Skip to content

backend: design and build the Public REST API v1 with OpenAPI spec #38

@ShantKhatri

Description

@ShantKhatri

Summary

Product doc section 5.12 specifies a Public REST API for programmatically creating, updating, and sharing DevCards. Design and implement the versioned public API under /api/v1/ with full OpenAPI 3.1 documentation generated at runtime.

Context

The current backend at apps/backend/src/routes/ serves internal app routes. This task builds a separate, stable, versioned public API surface with API key authentication (distinct from session auth) and machine-readable docs.

Tasks

  • design the API key authentication strategy:
    • add ApiKey model to Prisma schema: id, userId, keyHash (bcrypt), label, lastUsed, createdAt, revokedAt.
    • add POST /api/v1/keys (session auth) to create a key — returns the raw key once, never again.
    • add DELETE /api/v1/keys/:id to revoke.
  • create a Fastify plugin apps/backend/src/plugins/apiKey.ts that validates Authorization: Bearer <key> on /api/v1/ routes.
  • implement v1 endpoints:
    • GET /api/v1/profiles/me — returns authenticated user's full profile.
    • PUT /api/v1/profiles/me/links — add a platform link.
    • DELETE /api/v1/profiles/me/links/:id — remove a link.
    • GET /api/v1/profiles/:username — public profile read.
  • register @fastify/swagger and @fastify/swagger-ui to auto-generate OpenAPI spec from route schemas.
  • serve the spec at GET /api/v1/openapi.json and UI at /api/v1/docs.
  • write integration tests for API key creation, rotation, revocation, and endpoint access.
  • add API key management UI stub in web settings page.

Acceptance Criteria

  • /api/v1/docs renders a working Swagger UI.
  • API keys authenticate correctly and rate-limited separately from session users.
  • all v1 endpoints conform to the OpenAPI spec.
  • revoking a key immediately returns 401 on next use.

Difficulty

senior — requires auth system design, OpenAPI tooling, Prisma schema evolution, and versioning strategy.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions