Week 4 repository guide
Purpose and architecture
This directory contains a small FastAPI + SQLite developer command center.
backend/app/main.py: application entry point, startup, static mount, router registration.backend/app/routers/notes.py: note list/create/search/read/update/delete endpoints.backend/app/routers/action_items.py: action-item list/create/complete endpoints.backend/app/schemas.py: Pydantic request validation and response contracts.backend/app/models.py: SQLAlchemy persistence models.backend/app/db.py: engine, sessions, and one-time seed loading fromdata/seed.sql.backend/app/services/extract.py: pure note action/tag extraction.backend/tests/: isolated API and service tests.frontend/: dependency-free HTML/CSS/JavaScript client served at/.docs/TASKS.md: product backlog;docs/API.md: public HTTP contract.
Request flow: browser → FastAPI router → Pydantic schema → SQLAlchemy session → SQLite. The dependency commits successful requests and rolls back exceptions.
Common commands
Run from week4/:
bash
make run
make test
make lint
make format
pre-commit install
pre-commit run --all-files
pytest -q backend/tests/test_notes.pyThe app is at http://127.0.0.1:8000; interactive API docs are at /docs; OpenAPI is at /openapi.json.
Custom workflows:
/tests [optional pytest selector]/docs-sync [optional base URL]/refactor-module <old path> <new path> [symbol rename]
Style and contracts
- Python: Black formatting, Ruff-clean imports, type annotations on application functions, four spaces, descriptive names.
- API: define request/response schemas, validate at the boundary, use
404for missing resources and a cleardetail; preserve FastAPI's422for malformed request bodies. - Routes: place fixed paths such as
/searchbefore/{id}. Use plural resource names and return204with an empty body for successful deletion. - Database: use the injected
Session; flush before serializing newly changed rows. Never create global sessions in routers. - JavaScript: use
fetchJSON,textContentrather than HTML interpolation,encodeURIComponentfor query values, and show rejected requests to the user. - Tests: assert observable status, payload, persistence, validation, case-insensitive search, and missing-resource behavior. Tests must remain isolated.
- Documentation: any endpoint/schema change requires
docs/API.mdsynchronization.
Agent instructions
- Read the affected router, schema, tests, and API documentation before editing.
- For endpoint changes, write/update the narrow contract test, implement the smallest complete change, update the frontend if user-visible, then sync API docs.
- Run the narrow test first, then
/tests; runpre-commit run --all-filesbefore delivery. - Do not edit
data/seed.sqlfor test setup, commit generated databases, weaken validation to satisfy a test, or use destructive Git/database commands. - Preserve unrelated user changes. Do not add a second convention where an existing helper or pattern suffices.
- Report exact commands and results; never claim checks that were not run.