|
| 1 | +--- |
| 2 | +paths: |
| 3 | + - "backend/kayman/**/*.py" |
| 4 | +--- |
| 5 | + |
| 6 | +# Backend development process |
| 7 | + |
| 8 | +Build a **new** backend feature in this order. This applies when adding a feature |
| 9 | +or endpoint from scratch; skip it for isolated bugfixes, renames, and small edits. |
| 10 | + |
| 11 | +The `----commit----` markers are hard checkpoints: stop, summarize what changed, |
| 12 | +and ask the user to commit before continuing. Don't cross a checkpoint on your own. |
| 13 | + |
| 14 | +## 1. Design the flow (no code) |
| 15 | + |
| 16 | +- Sketch the high-level flow end to end. |
| 17 | +- List things to consider, propose options with tradeoffs, and call out caveats. |
| 18 | +- Identify complex steps that may need business-logic functions (`logics/`) |
| 19 | + beyond plain CRUD, and propose how to structure them and compose them with the |
| 20 | + CRUD functions. |
| 21 | +- **Why:** the cheapest place to catch a wrong approach is before any schema or |
| 22 | + signature is written. |
| 23 | + |
| 24 | +## 2. Design schema and signatures (draft only) |
| 25 | + |
| 26 | +- Draft the schema shape and the CRUD/logic function signatures. |
| 27 | +- Keep this in the plan/draft. **Do not write it into the codebase yet.** |
| 28 | + |
| 29 | +## 3. Draft schema and migration |
| 30 | + |
| 31 | +- Write the schema classes and, if the DB shape changed, generate the Alembic |
| 32 | + migration (`uv run alembic revision --autogenerate -m "..."`). Review it. |
| 33 | +- This covers creating a model (or its fields) for the **first time**: a fresh |
| 34 | + table and a single additive migration. Altering a field that has already |
| 35 | + shipped (adding NOT NULL, removing, renaming, retyping) follows the staged |
| 36 | + migration dances in [`schemas.md`](schemas.md#changing-schema-fields) |
| 37 | + instead, not this process. |
| 38 | + |
| 39 | +`----commit----` |
| 40 | + |
| 41 | +## 4. Mock data |
| 42 | + |
| 43 | +- If the new model needs seed rows, add them following |
| 44 | + [`mock-data.md`](mock-data.md): the `backend/mock_data/<entity>.json` file and |
| 45 | + the `load_records` + `session.add` block in `seed.py` (in FK-dependency order). |
| 46 | +- Confirm a reseed succeeds end to end. |
| 47 | + |
| 48 | +`----commit----` |
| 49 | + |
| 50 | +## 5. Blank CRUD function |
| 51 | + |
| 52 | +- Add the CRUD function signature with an empty/stub body (e.g. `raise |
| 53 | + NotImplementedError` or `...`). No logic yet. |
| 54 | + |
| 55 | +## 6. Write tests (subagent) |
| 56 | + |
| 57 | +- Use a subagent to write the tests against the blank function's signature. |
| 58 | +- **Why:** tests written before the implementation, by a separate context, |
| 59 | + describe intended behavior instead of rationalizing whatever the code happens |
| 60 | + to do. |
| 61 | + |
| 62 | +## 7. Write the CRUD function |
| 63 | + |
| 64 | +- Implement the real body to satisfy the tests. |
| 65 | + |
| 66 | +## 8. Iterate until tests pass |
| 67 | + |
| 68 | +- Run the tests, fix, repeat until green. |
| 69 | + |
| 70 | +`----commit----` |
| 71 | + |
| 72 | +## 9. Business-logic functions (if needed) |
| 73 | + |
| 74 | +- If step 1 flagged complex steps needing `logics/` functions, repeat steps 5-8 |
| 75 | + for them: blank function, subagent tests, real implementation, iterate until |
| 76 | + green. Compose them from the CRUD functions built above, then commit. |
| 77 | +- If none are needed, skip to step 10 (no separate commit here). |
| 78 | + |
| 79 | +`----commit---- (only if this step did work)` |
| 80 | + |
| 81 | +## 10. Wire into the router |
| 82 | + |
| 83 | +- Connect the top-level function (CRUD or `logics/`) to its router endpoint. |
| 84 | + |
| 85 | +`----commit----` |
0 commit comments