openapi: 3.0.3
info:
  title: ElectroGen AI Public API
  version: 0.1.0
  description: >-
    Read-only public API for ElectroGen AI (https://electrogen.org), an AI-powered
    electronics project generator. These endpoints expose community-shared project
    blueprints, the component marketplace catalog, electronics news, and runtime
    capabilities. No authentication is required. Mutating/AI-generation endpoints
    exist under /api but are intentionally not described here because they require
    sign-in.
  contact:
    url: https://electrogen.org
servers:
  - url: https://electrogen.org
paths:
  /api/health:
    get:
      operationId: getHealth
      summary: Liveness check
      responses:
        '200':
          description: Service is up.
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: ok
  /api/capabilities:
    get:
      operationId: getCapabilities
      summary: Runtime capability snapshot
      description: >-
        Reports which backend features are enabled: database, Google auth, AI
        provider availability/health, the caller's plan quota (null for anonymous
        callers), and the plan tier catalog.
      responses:
        '200':
          description: Capability snapshot.
          content:
            application/json:
              schema:
                type: object
                properties:
                  generatedAt:
                    type: string
                    format: date-time
                  db:
                    type: object
                    properties:
                      enabled:
                        type: boolean
                  auth:
                    type: object
                    properties:
                      provider:
                        type: string
                        example: google
                      serverAuthEnabled:
                        type: boolean
                  ai:
                    type: object
                    properties:
                      providers:
                        type: object
                        additionalProperties:
                          type: boolean
                      anyEnabled:
                        type: boolean
                  planQuota:
                    type: object
                    nullable: true
                  planCatalog:
                    type: object
                    properties:
                      tiers:
                        type: array
                        items:
                          type: object
                      actions:
                        type: array
                        items:
                          type: string
  /api/site-config:
    get:
      operationId: getSiteConfig
      summary: Public site SEO/analytics configuration
      responses:
        '200':
          description: Public site configuration values (may be null when unset).
          content:
            application/json:
              schema:
                type: object
  /api/community-projects:
    get:
      operationId: listCommunityProjects
      summary: List publicly shared community projects
      description: >-
        Returns card-shaped project objects (title, description, platform,
        difficulty, estimated time/cost, tags) with owner identifiers stripped.
        `groups` clusters projects into version families.
      responses:
        '200':
          description: Community projects payload.
          content:
            application/json:
              schema:
                type: object
                properties:
                  projects:
                    type: array
                    items:
                      $ref: '#/components/schemas/CommunityProject'
                  groups:
                    type: array
                    items:
                      type: object
                      properties:
                        rootProjectId:
                          type: string
                        projects:
                          type: array
                          items:
                            $ref: '#/components/schemas/CommunityProject'
  /api/community-projects/{id}:
    get:
      operationId: getCommunityProject
      summary: Get a full public community project blueprint by id
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: The public project (owner fields stripped).
          content:
            application/json:
              schema:
                type: object
                properties:
                  project:
                    $ref: '#/components/schemas/CommunityProject'
        '404':
          description: Project not found or not community-shared.
  /api/community-projects/{id}/preview:
    get:
      operationId: getCommunityProjectPreview
      summary: Prototype preview image for a community project
      description: Redirects (302) to the image URL or returns image bytes directly.
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Image bytes.
          content:
            image/*:
              schema:
                type: string
                format: binary
        '302':
          description: Redirect to the preview image URL.
        '404':
          description: No preview available.
  /api/component-products:
    get:
      operationId: listComponentProducts
      summary: Component marketplace catalog
      description: >-
        Validated components/modules with brand, category, tags, price range,
        availability, rating, and affiliate/vendor links.
      responses:
        '200':
          description: Marketplace items.
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/ComponentProduct'
                  generatedAt:
                    type: string
                    format: date-time
                  cacheTtlSeconds:
                    type: integer
  /api/component-news:
    get:
      operationId: listComponentNews
      summary: Aggregated electronics/component news items
      responses:
        '200':
          description: News items (empty list while the pipeline warms up).
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/NewsItem'
                  generatedAt:
                    type: string
                    format: date-time
  /api/news:
    get:
      operationId: listNewsPosts
      summary: List published news/blog posts
      description: >-
        Published ElectroGen articles — DIY electronics guides, product updates,
        and release notes. List items omit the article body; fetch
        /api/news/{slug} for the full post. Unlike most public routes this one
        is mounted under /api only (a bare /news mount would shadow the /news
        pages).
      parameters:
        - name: limit
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 200
            default: 50
        - name: offset
          in: query
          schema:
            type: integer
            minimum: 0
            default: 0
      responses:
        '200':
          description: Published posts, newest first.
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/NewsPost'
                  generatedAt:
                    type: string
                    format: date-time
                  cacheTtlSeconds:
                    type: integer
  /api/news/{slug}:
    get:
      operationId: getNewsPost
      summary: Get a published news post by slug
      parameters:
        - name: slug
          in: path
          required: true
          schema:
            type: string
            pattern: '^[a-z0-9][a-z0-9-]{0,119}$'
      responses:
        '200':
          description: The post, including the full markdown body.
          content:
            application/json:
              schema:
                type: object
                properties:
                  post:
                    $ref: '#/components/schemas/NewsPost'
        '404':
          description: Post not found.
  /api/public/{handle}/{slug}:
    get:
      operationId: getPublicProjectByHandleSlug
      summary: Shared-project permalink data
      description: >-
        Returns the read-only blueprint for a publicly shared project addressed by
        creator handle + project slug (the same identifiers used in
        https://electrogen.org/{handle}/{slug} page URLs).
      parameters:
        - name: handle
          in: path
          required: true
          schema:
            type: string
        - name: slug
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Public project payload.
          content:
            application/json:
              schema:
                type: object
                properties:
                  project:
                    $ref: '#/components/schemas/CommunityProject'
                  versions:
                    type: array
                    items:
                      $ref: '#/components/schemas/CommunityProject'
                  owner:
                    type: object
                    properties:
                      handle:
                        type: string
                  canonical:
                    type: object
                    properties:
                      handle:
                        type: string
                      slug:
                        type: string
        '404':
          description: Not found or not publicly shared.
  /api/mcp:
    post:
      operationId: mcpJsonRpc
      summary: Model Context Protocol endpoint (JSON-RPC 2.0)
      description: >-
        Streamable-HTTP MCP endpoint (server->client responses only, no SSE).
        Methods: initialize, ping, tools/list, tools/call. Tools:
        list_public_projects, get_component_products, list_news_posts,
        get_capabilities, describe_platform. Rate-limited per client IP.
        Notifications (messages without an id) return 202 with no body; GET
        returns 405 because no SSE stream is offered.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [jsonrpc, method]
              properties:
                jsonrpc:
                  type: string
                  enum: ['2.0']
                id:
                  oneOf:
                    - type: string
                    - type: integer
                    - type: 'null'
                method:
                  type: string
                  enum: [initialize, ping, tools/list, tools/call]
                params:
                  type: object
      responses:
        '200':
          description: JSON-RPC 2.0 response envelope.
          content:
            application/json:
              schema:
                type: object
        '202':
          description: Notification accepted (no response body).
        '429':
          description: Rate limit exceeded; see Retry-After header.
components:
  schemas:
    CommunityProject:
      type: object
      description: >-
        Public card-shaped project blueprint. Owner identifiers are always
        stripped. Additional blueprint fields (hardware, connections, code,
        instructions, cadFiles, etc.) may be present on single-project fetches.
      properties:
        id:
          type: string
        title:
          type: string
        description:
          type: string
        platform:
          type: string
          enum: [Arduino, 'Raspberry Pi', ESP32, Generic]
        platformVariant:
          type: string
        projectMode:
          type: string
          enum: [electromechanical, mechanical_only]
        difficulty:
          type: string
          enum: [Beginner, Intermediate, Advanced, Expert]
        estimatedTime:
          type: string
        totalCost:
          type: string
        tags:
          type: array
          items:
            type: string
        version:
          type: number
        communityShared:
          type: boolean
        createdAt:
          type: number
          description: Unix epoch milliseconds
    ComponentProduct:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        brand:
          type: string
        category:
          type: string
        tags:
          type: array
          items:
            type: string
        priceRange:
          type: object
          properties:
            min:
              type: number
            max:
              type: number
            currency:
              type: string
        availabilityStatus:
          type: string
        shipEta:
          type: string
          nullable: true
        rating:
          type: number
          nullable: true
        reviewCount:
          type: integer
          nullable: true
        bestFor:
          type: array
          items:
            type: string
        affiliateLinks:
          type: array
          items:
            type: object
            properties:
              vendor:
                type: string
              region:
                type: string
              url:
                type: string
        lastCheckedAt:
          type: string
          format: date-time
    NewsPost:
      type: object
      description: >-
        Published news/blog article. `bodyMd` (the full markdown body) is only
        present on single-post fetches.
      properties:
        slug:
          type: string
        title:
          type: string
        excerpt:
          type: string
        bodyMd:
          type: string
        topic:
          type: string
          nullable: true
        publishedAt:
          type: string
          format: date-time
          nullable: true
        createdAt:
          type: string
          format: date-time
          nullable: true
        readingMinutes:
          type: integer
    NewsItem:
      type: object
      properties:
        id:
          type: string
        title:
          type: string
        summary:
          type: string
        sourceUrl:
          type: string
        publishedAt:
          type: string
        tags:
          type: array
          items:
            type: string
        vendors:
          type: array
          items:
            type: string
