---
name: archemist-architecture-author
description: Write the source files for Archemist (archemist.app) - architecture.yaml, OpenAPI 3.1 / AsyncAPI 3 contracts and flow files - from a codebase or a description of a system, so the user can zip them and upload them to get an interactive architecture report.
---

# Writing an Archemist project

Archemist (https://archemist.app) turns a folder of YAML files into an interactive
architecture report: a system diagram, API details, and animated request flows.
Your job is to **write that folder** for the user, from their codebase or from
what they tell you about their system. Archemist validates the files strictly,
so follow the format below exactly.

## How to work

1. **Understand the system first.** If you can see a codebase, read it: services,
   routes, database tables, queues, outgoing calls. If not, ask the user short,
   concrete questions: What are the components (frontend, services, databases,
   queues)? How do they talk (HTTP, WebSocket, SQL, Redis, object storage, SSH)?
   Which two or three business flows matter most?
2. **Start small.** Begin with 3 to 8 components and 1 to 3 flows. A small project
   that validates is worth more than a large one that does not. Add more later.
3. **Write the files** in this order: `architecture.yaml` (components and
   connections), then one OpenAPI file per HTTP service, then the flow files.
4. **Do not invent facts.** If something is inferred rather than read from code,
   set `classification: proposed` on the project, and say what you assumed in your
   reply. Use `implementationStatus: planned` for things that do not exist yet.
5. **Never put real secrets or personal data in examples.** Use placeholders such
   as `Bearer <example-token>`, `user_123`, `jane@example.com`.
6. **Deliver a folder tree** and every file in full. Tell the user to zip the
   folder (with `architecture.yaml` at the top, or inside one folder) and upload it
   at https://archemist.app. If they paste back error messages, fix exactly those.

## Project layout

```
my-project/
  architecture.yaml                 required, at the root
  contracts/
    users.openapi.yaml              OpenAPI 3.1, one per HTTP service
    events.asyncapi.yaml            AsyncAPI 3.0, only if you use WebSockets
  flows/
    create-user.flow.yaml           one file per business flow
```

Only `architecture.yaml` has a fixed location; every other path is whatever
`architecture.yaml` names. Use `.yaml`. Limits: 8 MB zip, 400 files, 2 MB per file.

**Fields are strict.** An unknown or misspelled field is an error. Every
`architecture.yaml` and `*.flow.yaml` starts with `schemaVersion: archemist/v1`.

## architecture.yaml

```yaml
schemaVersion: archemist/v1
project:
  id: my-system                # stable, kebab-case
  name: My System
  version: v1
  description: One or two sentences.
  classification: proposed     # sample | proposed | documented
groups:                        # zones drawn behind components, left to right
  - { id: client, label: Client, order: 0 }
  - { id: app, label: Application, order: 1 }
components:
  - id: api                    # stable kebab-case id; flows reference it
    name: API
    type: service              # frontend | service | worker | database | cache | queue | object-storage | external-system
    group: app
    responsibility: One line shown on the card
    description: A paragraph shown in the inspector.
    implementationStatus: implemented   # planned | implemented | deprecated
    reviewStatus: reviewed              # draft | reviewed
    contracts:                          # what this component SERVES
      http: [contracts/api.openapi.yaml]
      messages: [contracts/events.asyncapi.yaml]   # WebSocket only
    routes: [other-service/createThing]  # operations it FORWARDS but does not serve (e.g. a gateway)
connections:
  - id: c-web-api              # unique
    from: web-app
    to: api
    protocol: http             # http | websocket | database | redis | object-storage | ssh
    purpose: Why they talk.
    operations: [getThing]     # http: operationIds carried on this connection
    # websocket: channel: /ws/x   messages: [msg.name]
    # database / redis / object-storage / ssh:
    # interactions: [{ label: "SELECT things", note: "read" }]
flows:
  - flows/get-thing.flow.yaml
```

A **database, cache or object-storage** component may declare `resources`
(`tables`, `keys`, `objects`). Once it declares any, flows may only touch the ones
it declares, which catches renamed tables. Table example:
`resources: { tables: [{ name: books, owner: api, columns: "id text PK" }] }`.

## Contracts

* **HTTP: OpenAPI 3.1 only** (`openapi: 3.1.0`). 3.0 and Swagger 2 are refused.
* Every operation needs a unique **`operationId`**; flows reference it.
* Give schemas and **examples** for the responses flows use. Every example must
  satisfy its schema (watch `required`, `additionalProperties: false`, types).
* A flow may only return a status code the operation **documents** under
  `responses`. Document the failure statuses (404, 409, 422, ...) your flows use.
* **WebSocket: AsyncAPI 3.0** (a documented subset). Skip it if there is no WebSocket.

## Flows (flows/*.flow.yaml)

```yaml
schemaVersion: archemist/v1
flow:
  id: get-thing
  name: Look up a thing
  group: Things               # grouping in the sidebar
  purpose: One sentence.
  summary: A short paragraph.
scenarios:                     # named alternatives, NOT branches
  - id: success
    name: Found
    kind: success              # success | failure | retry
    summary: What happens.
    events: [ ... ]
```

Write one scenario for the happy path and one for the most important failure
(`kind: failure`); add `kind: retry` if retries matter. Each scenario is a plain
ordered list. **No parallel steps, branches or loops** (they are refused).

Every event has `id` (unique within the scenario), `type`, and a one-sentence
`summary`. Request and response are **separate events**. A response names its
request with `replyTo` and never repeats `from` or `to`.

| type | key fields |
| --- | --- |
| `http.request` | `from`, `to`, `connection`, `operation`, `pathParams`, `query`, `headers`, `body` |
| `http.response` | `replyTo`, `status` (must be documented), `outcome`, `body` |
| `database.query` | `from`, `to`, `connection`, `operation` (SELECT...), `table`, `inputs`, `sql` |
| `database.result` | `replyTo`, `rowCount`, `output` |
| `redis.command` / `redis.result` | `command`, `key`, `payload` / `replyTo`, `result` |
| `storage.operation` / `storage.result` | `operation` (PUT/GET), `key`, `meta` / `replyTo`, `result` |
| `websocket.connect` / `.message` / `.disconnect` | `from`, `to`, `connection`, `message`, `channel`, `payload` |
| `ssh.command` / `ssh.result` | `command`, `paths` / `replyTo`, `exitCode`, `output` |
| `processing` | `component`, `title`, `input`, `output` (work inside one component) |

Rules that cause most errors:

* `from`, `to` and `component` must be component ids; `connection` must be a
  connection id that links those two components.
* An `http.request` must be sent **to a component that serves or routes** that
  operation (`contracts.http` or `routes`). Through a gateway, send to the
  gateway and list the operation under the gateway's `routes`.
* Provide a value for every `{placeholder}` in the path, and every required
  query parameter, header and body.
* A reply answers the right kind of request (`http.response` to `http.request`,
  `database.result` to `database.query`, and so on) and comes after it.
* To reuse a value from an earlier event instead of retyping it:
  `{ $fromEvent: { event: e3, path: "output.rows[0].id" } }`. The event must be
  earlier in the same scenario. Nothing else is evaluated.
* Keep flows short, roughly 4 to 15 events.

## A complete, valid example

This project passes Archemist's strictest validation. Mirror its structure.

#### `architecture.yaml`

```yaml
schemaVersion: archemist/v1

project:
  id: bookshop
  name: Bookshop Quickstart
  version: v1
  description: >-
    The smallest useful Archemist project: a web app, one API and a database,
    with one flow showing a successful lookup and a missing book.
  classification: sample

groups:
  - { id: client, label: Client, order: 0 }
  - { id: app, label: Application, order: 1 }
  - { id: data, label: Data, order: 2 }

components:
  - id: web-app
    name: Web App
    type: frontend
    group: client
    responsibility: Shows a book's details page
    description: Browser application that looks up a book when a visitor opens its page.

  - id: bookshop-api
    name: Bookshop API
    type: service
    group: app
    responsibility: Serves book data over HTTP
    description: Reads books from the database and returns them as JSON.
    implementationStatus: implemented
    reviewStatus: reviewed
    contracts:
      http: [contracts/bookshop.openapi.yaml]

  - id: postgres
    name: PostgreSQL
    type: database
    group: data
    responsibility: Stores books
    description: Relational database holding the books table.
    resources:
      tables:
        - name: books
          owner: bookshop-api
          columns: |
            id text PK
            title text NOT NULL
            author text NOT NULL

connections:
  - id: c-web-api
    from: web-app
    to: bookshop-api
    protocol: http
    purpose: Look up a book by id.
    operations: [getBook]

  - id: c-api-db
    from: bookshop-api
    to: postgres
    protocol: database
    purpose: Read a book row.
    interactions:
      - { label: SELECT books, note: Read one book by id }

flows:
  - flows/get-book.flow.yaml
```

#### `contracts/bookshop.openapi.yaml`

```yaml
openapi: 3.1.0
info:
  title: Bookshop API
  version: "1.0"
paths:
  /books/{bookId}:
    parameters:
      - name: bookId
        in: path
        required: true
        schema:
          type: string
        example: book_42
    get:
      operationId: getBook
      summary: Read one book.
      responses:
        "200":
          description: The book.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Book"
              example:
                id: book_42
                title: The Pragmatic Programmer
                author: Andrew Hunt
        "404":
          description: No book has this id.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                error:
                  code: NOT_FOUND
                  message: No book with this id.
components:
  schemas:
    Book:
      type: object
      required: [id, title, author]
      additionalProperties: false
      properties:
        id:
          type: string
        title:
          type: string
        author:
          type: string
    Error:
      type: object
      required: [error]
      properties:
        error:
          type: object
          required: [code, message]
          properties:
            code:
              type: string
            message:
              type: string
```

#### `flows/get-book.flow.yaml`

```yaml
schemaVersion: archemist/v1

flow:
  id: get-book
  name: Look up a book
  group: Books
  purpose: Show a book's details page.
  summary: >-
    One request travels from the web app to the API, which reads a row from the
    database and answers.

scenarios:
  - id: success
    name: Book found
    kind: success
    summary: The book exists and its details come back.
    events:
      - id: e1
        type: http.request
        from: web-app
        to: bookshop-api
        connection: c-web-api
        operation: getBook
        summary: The web app asks for book_42.
        pathParams: { bookId: book_42 }

      - id: e2
        type: database.query
        from: bookshop-api
        to: postgres
        connection: c-api-db
        operation: SELECT
        table: books
        summary: The API reads the row.
        inputs: { id: book_42 }
        sql: SELECT id, title, author FROM books WHERE id = $1;

      - id: e3
        type: database.result
        replyTo: e2
        rowCount: 1
        summary: The database returns one row.
        output:
          rowCount: 1
          rows:
            - id: book_42
              title: The Pragmatic Programmer
              author: Andrew Hunt

      - id: e4
        type: http.response
        replyTo: e1
        status: 200
        outcome: success
        summary: The API returns the book.
        body:
          id: { $fromEvent: { event: e3, path: "output.rows[0].id" } }
          title: { $fromEvent: { event: e3, path: "output.rows[0].title" } }
          author: { $fromEvent: { event: e3, path: "output.rows[0].author" } }

  - id: not-found
    name: Book not found
    kind: failure
    summary: No book has this id, so the API answers 404.
    events:
      - id: e1
        type: http.request
        from: web-app
        to: bookshop-api
        connection: c-web-api
        operation: getBook
        summary: The web app asks for a book that does not exist.
        pathParams: { bookId: book_999 }

      - id: e2
        type: database.query
        from: bookshop-api
        to: postgres
        connection: c-api-db
        operation: SELECT
        table: books
        summary: The API looks for the row.
        inputs: { id: book_999 }
        sql: SELECT id, title, author FROM books WHERE id = $1;

      - id: e3
        type: database.result
        replyTo: e2
        rowCount: 0
        outcome: failure
        summary: The database finds nothing.
        output:
          rowCount: 0
          rows: []

      - id: e4
        type: http.response
        replyTo: e1
        status: 404
        outcome: failure
        summary: The API returns 404.
        body:
          error:
            code: NOT_FOUND
            message: No book with this id.
```

## Before you hand the files over, check

- [ ] `architecture.yaml` is at the root and every document has `schemaVersion: archemist/v1`.
- [ ] No unknown fields, and ids are unique and referenced exactly as written.
- [ ] Each HTTP operation has an `operationId`, schemas and examples, and is listed
      on the right component and connection.
- [ ] Every status a flow returns is documented in the OpenAPI `responses`.
- [ ] Every request goes to the component that serves or routes the operation.
- [ ] Every request has a matching reply, and examples satisfy their schemas.
- [ ] No secrets or real personal data; assumptions are stated in your reply.

If you can run commands and have the `archemist` CLI, run `archemist validate <folder>`.
Otherwise the user uploads the zip at https://archemist.app, and any errors shown
there (file, location and a suggestion each) can be pasted back to you to fix.
