2.5 KiB
2.5 KiB
AGENTS.md
This project is a FastAPI backend for generating structured math problems. The intended design should scale to grades 1 through 6 and multiple problem types per grade.
Run And Test
- Start the API with
uv run uvicorn main:app --reload. - Open API docs at
http://127.0.0.1:8000/docs. - Run tests with
uv run python -m unittest. - Compile changed Python files with
uv run python -m py_compile <files>.
Endpoint example
POST /math/grade_1/join_pictures_with_quantity- The caller sends image metadata and optional generation settings.
- The endpoint returns a JSON-ready math problem where students count images and match groups to numbers.
Responsibilities
main.pyis only the uvicorn entry point. Keep it thin.app/main.pydefinescreate_app()and includes the top-level API router.app/routers/math.pyowns the/mathrouter and includes grade routers.app/routers/grade_1.pyregisters all grade 1 HTTP endpoints.app/problems/grade_1/contains reusable generation logic for grade 1 problems.app/schemas/grade_1/contains Pydantic request/response models for grade 1 problems.tests/contains endpoint tests usingfastapi.testclient.TestClient.
Design Rules
- Keep HTTP code in
app/routers/. - Keep generation logic in
app/problems/. - Keep all Pydantic models in
app/schemas/. - Do not put generation logic in routers.
- Do not put FastAPI router code in problem generator modules.
- Prefer one router file per grade, not one router file per problem.
- Prefer one schema file per problem type.
- Prefer one generator file per problem type.
Adding A New Problem Type
For a new grade 1 problem named example_problem:
- Add schemas in
app/schemas/grade_1/example_problem.py. - Add generator logic in
app/problems/grade_1/example_problem.py. - Register the endpoint in
app/routers/grade_1.py. - Add endpoint tests in
tests/. - Run
uv run python -m unittest.
For a new grade, follow the same pattern:
- Add
app/schemas/grade_2/andapp/problems/grade_2/. - Add
app/routers/grade_2.py. - Include the new grade router from
app/routers/math.py. - Add tests.
Naming Conventions
- Endpoint paths use the existing style:
/math/1_grade/<problem_name>. - Python package names should use valid identifiers like
grade_1, not1_grade. - Problem files should use snake case, for example
join_pictures_with_quantity.py. - Request schema names should end in
Request. - Response schema names should describe the generated problem, for example
JoinPicturesWithQuantityProblem.