Problem
generateRoutes() currently emits stub handlers:
lines.push(` // TODO: implement ${routeName} handler`);
lines.push(` return c.json({ status: 'ok' });`);
Specs pass but handlers are hollow. No DB queries, no response shaping, no error handling. This blocks FoodFiles domain contracts (Stackbilt-dev/foodfilesapi_v2#23) from producing usable code.
Decided Approach: Handlebars-style string templates
Per prior architecture decision:
- Template files under
src/generators/templates/ with placeholders ({{contractName}}, {{inputSchema}}, {{refImports}}, etc.)
- Zod walker builds a context object, feeds it to templates
- Generated handler bodies include:
req.body validation against Zod schema (already done)
- DB queries via
surfaces.db helpers (db.prepare().bind().run() for D1)
- Standard success/error response shaping (try/catch with
errorResponse() envelope)
- State transition guards from
contract.states
- Authority middleware from
contract.authority (already done)
- Prettier pass on output
Why Templates (Not AST)
- Speed: instant iteration on contract definitions
- Auditability: deterministic, diffable output
- Low risk: no complex AST transforms — aligns with speed + rigor
AST-based generation (ts-morph) is v0.3, gated on template coverage ≥ 90%.
Scope
Must have (v0.2)
Also fix
Validation Target
Write RecipeContract (state machine: draft→published→archived, refs to Organization + User, invariant: published requires ingredients). Run all generators. Diff SQL against FoodFiles 001_fresh_multitenant_schema.sql.
Roadmap
| Version |
Approach |
Status |
| v0.1 |
Stub handlers |
Done |
| v0.2 |
Template-driven real handlers |
This issue |
| v0.3 |
AST-based generation (ts-morph) |
Planned |
| v0.4 |
CI integration + no-TODO lint rule |
Planned |
Problem
generateRoutes()currently emits stub handlers:Specs pass but handlers are hollow. No DB queries, no response shaping, no error handling. This blocks FoodFiles domain contracts (Stackbilt-dev/foodfilesapi_v2#23) from producing usable code.
Decided Approach: Handlebars-style string templates
Per prior architecture decision:
src/generators/templates/with placeholders ({{contractName}},{{inputSchema}},{{refImports}}, etc.)req.bodyvalidation against Zod schema (already done)surfaces.dbhelpers (db.prepare().bind().run()for D1)errorResponse()envelope)contract.statescontract.authority(already done)Why Templates (Not AST)
AST-based generation (ts-morph) is v0.3, gated on template coverage ≥ 90%.
Scope
Must have (v0.2)
publish,archive)surfaces.db.table+ schema columnsref()→ JOIN clause generationAlso fix
generateSQL()— validate against FoodFiles migration 001 (recipe/org tables)generateSDK()— fix syntax bug (unmatched paren line 72)generateTests()— emit integration tests that hit handlers, not just schema validationValidation Target
Write
RecipeContract(state machine: draft→published→archived, refs to Organization + User, invariant: published requires ingredients). Run all generators. Diff SQL against FoodFiles001_fresh_multitenant_schema.sql.Roadmap