Build application code from an Auto narrative model. Use when the user asks to build, generate, scaffold, or implement code from their model, or when working with vertical slices, resolvers, components, or tests derived from the model.
The narrative model (.auto-agent/model.json) is the single source of truth for your application. It expresses what the application does; you translate it to how.
Narratives group scenes into complete user journeys (e.g., "Flower Shop Order Fulfillment").
Scenes group moments into coherent interaction sequences (e.g., "Browse and Select Flowers"). A scene represents a unit of business value — all moments within it must work together.
Moments are the atomic units. Each moment is either a command (state change via mutation) or a query (data retrieval). Each moment becomes one vertical slice in the codebase.
Messages define data contracts: command (input), event (output), state (persisted), query (lookup params). Their fields arrays define the schema.
Each moment is a self-contained vertical slice with high cohesion internally and low coupling to other slices. Slices communicate through events and shared state, never by importing each other directly.
src/
narratives/<narrative-slug>/
scenes/<scene-slug>/
moments/<moment-slug>/
server/
handler.ts # GraphQL resolver + business logic
handler.test.ts # Given-When-Then tests from server.specs
client/
<MomentName>.tsx # React component (json-render + Apollo)
<MomentName>.stories.tsx
<MomentName>.test.tsx
scene.acceptance.test.ts # Cross-moment acceptance test for the scene
shared/
graphql/
schema.ts # Merged GraphQL type definitions
resolvers.ts # Merged resolver map
db/
repository.ts # Repository interface + implementation
event-log.ts # Append-only event log
components/ # Shared UI primitives if needed
Slug derivation: "Place Order" → place-order, "CreateBouquetDraft" → create-bouquet-draft.
Do NOT call auto_get_model — it returns the full model (often >100K chars) which overwhelms context. Instead use targeted extraction tools:
Call auto_get_model_overview to understand the full scope:
This tells you WHAT to build — the complete structure in one compact call.
Call auto_get_design to get the theme and app shell:
theme.colors (light/dark mode with oklch values)theme.font, theme.radius, theme.shadow, theme.animationappShell (layout name, chrome, navigation, brand placement)brief (visual direction description)Generate theme.css with CSS custom properties immediately. The model's theme is authoritative — use it for all styling decisions.
For each scene, call auto_get_scene_detail(sceneName) to get:
client.ui.spec (json-render wireframe)client.specs (BDD test specs)server.specs and server.dataBuild one scene at a time, keeping context focused.
scene.moments[].type — "command", "query", "experience", or "react"scene.moments[].client.ui.spec — json-render flat element map (root, elements, state)scene.moments[].client.specs — BDD describe/it test specsscene.moments[].server.specs — gherkin Given/When/Then scenariosscene.moments[].server.data.items — event targets and stream patternsrelatedMessages — data contracts (command/event/state/query messages with full field types)Command moments → GraphQL mutations. Each handler validates input, executes business logic via a repository, emits domain events, and returns a MutationResponse.
Query moments → GraphQL queries. Each handler reads from the database via a repository and returns projected state.
The database is the source of truth for state. Events are emitted alongside state changes for observability, testing, and inter-slice communication. An append-only event log stores all events but the database tables hold canonical state.
DDD patterns apply: repository pattern for data access, domain services for cross-cutting logic, CQRS for separating reads from writes.
See references/backend-patterns.md for complete resolver templates, type mapping rules, and repository patterns.
The model's client.ui.spec is directly compatible with json-render.dev — the spec format (root, elements, type, props, children, visible, repeat, $state, $item) matches json-render's schema.
Approach for each moment's UI:
@json-render/react + @json-render/shadcn (39 pre-built shadcn/ui components). This gets the UI structure working immediately with minimal tokens.useMutation for command moments, useQuery for query moments. The moment.request field contains the exact GraphQL operation to use.on: { click: { action: "submit" } } to json-render's ActionProvider pattern.@json-render/code-generation can export standalone React components with zero json-render runtime dependency.See references/frontend-patterns.md for json-render setup, Apollo wiring, and Storybook patterns.
All generated UI must follow the premium design patterns in references/design-patterns.md. Key rules:
Geist, Satoshi, or Outfit fonts — never Inter or Robotolinear or ease-in-outApply these patterns while preserving the structural intent of the model's client.ui.spec. The spec provides layout and data binding; the design patterns provide visual polish.
Three levels of testing ensure both individual slice correctness and cross-slice cohesion.
server.specs)Each moment's server.specs contains gherkin rules with Given/When/Then steps:
text field names a message, docString provides sample data)After all moments in a scene are built, test the full flow by executing moments in order against the real GraphQL endpoint. This verifies that data flows correctly across moments within a scene.
After generating code, run the full test suite and fix any failures before moving on.
See references/testing-patterns.md for concrete test templates and the gherkin-to-test translation rules.
After completing all moments in a scene, verify the running application works end-to-end:
If browser MCP tools are available (e.g., chrome-devtools):
mcp__chrome-devtools__navigate_page to http://localhost:5173mcp__chrome-devtools__take_screenshot to visually verify the page rendered correctlymcp__chrome-devtools__list_console_messagesmcp__chrome-devtools__click, mcp__chrome-devtools__fill, etc. to walk through the flowIf browser tools are NOT available, fall back to:
curl the frontend URL to verify it returns HTMLcurl -s http://localhost:4000/graphql \
-H 'Content-Type: application/json' \
-d '{"query":"{ <queryFromMoment> }"}'
GraphQL endpoint testing (always, regardless of browser availability):
request field against the running serverauto_get_modelclient.ui.spec using json-renderserver.specs gherkin scenariosauto_update_endpointsauto_get_changes (returns added/updated/removed entities, then clears)added moment/scene → generate new sliceupdated moment/scene → regenerate affected sliceremoved moment/scene → remove slice directoryWhile building, if you detect inconsistencies in the model (missing message references, type mismatches, incomplete specs):
auto_send_model — the server validates and may apply further correctionsWhen building for the first time and no project structure exists, you have full agency to scaffold the project. Here are typical defaults for guidance (the developer may direct you otherwise):
These are starting points, not requirements. Follow the developer's preferences if they differ.