|
| 1 | +# AGENTS.md — FARM Stack To-Do App |
| 2 | + |
| 3 | +Agent guide for AI coding assistants working in this repository. |
| 4 | + |
| 5 | +## Build and Test Commands |
| 6 | + |
| 7 | +```bash |
| 8 | +# Backend — install and start |
| 9 | +cd backend |
| 10 | +pip install -r requirements.txt |
| 11 | +DB_URL="mongodb://localhost:27017/" DB_NAME="farm_intro" uvicorn main:app --reload |
| 12 | + |
| 13 | +# Frontend — install and start |
| 14 | +cd frontend |
| 15 | +npm install |
| 16 | +npm start |
| 17 | + |
| 18 | +# Tests (no MongoDB needed) |
| 19 | +python tests/test_runtime.py |
| 20 | + |
| 21 | +# Integration tests (MongoDB required) |
| 22 | +MONGODB_URI="mongodb://localhost:27017/" pytest tests/test_integration.py -v |
| 23 | + |
| 24 | +# Regenerate backend lockfile |
| 25 | +cd backend && pip-compile --upgrade requirements.in |
| 26 | +``` |
| 27 | + |
| 28 | +## Project Structure |
| 29 | + |
| 30 | +``` |
| 31 | +FARM-Intro/ |
| 32 | +├── backend/ |
| 33 | +│ ├── main.py # FastAPI app, lifespan (DB connect/close), appName |
| 34 | +│ ├── config/__init__.py # pydantic-settings: DB_URL, DB_NAME, HOST, PORT |
| 35 | +│ ├── apps/todo/ |
| 36 | +│ │ ├── models.py # TaskModel and UpdateTaskModel (pydantic v2) |
| 37 | +│ │ └── routers.py # CRUD handlers for /task/ prefix |
| 38 | +│ ├── requirements.in # Direct dependencies (source of truth) |
| 39 | +│ └── requirements.txt # Pinned lockfile — regenerate with pip-compile |
| 40 | +├── frontend/ |
| 41 | +│ ├── src/App.js # React 18 task list; polls /task/ every 1 s |
| 42 | +│ └── package.json # React 18, antd 5, react-scripts 5 |
| 43 | +├── tests/ |
| 44 | +│ ├── test_runtime.py # Offline unit test; stubs FastAPI and pymongo |
| 45 | +│ └── test_integration.py # Live CRUD tests against MongoDB |
| 46 | +├── .github/workflows/ci.yml # CI: Python 3.13, Node 22, mongo:latest service |
| 47 | +├── .devcontainer/ # Codespaces/Dev Container with Atlas Local |
| 48 | +├── EDD.md # MongoDB data model specification |
| 49 | +└── README.md |
| 50 | +``` |
| 51 | + |
| 52 | +## Environment Variables |
| 53 | + |
| 54 | +| Variable | Required | Default | Description | |
| 55 | +|-------------|----------|----------|-----------------------------------| |
| 56 | +| `DB_URL` | Yes | — | MongoDB connection string | |
| 57 | +| `DB_NAME` | Yes | — | Database name | |
| 58 | +| `HOST` | No | `0.0.0.0`| uvicorn bind address | |
| 59 | +| `PORT` | No | `8000` | uvicorn port | |
| 60 | +| `DEBUG_MODE`| No | `false` | Enable uvicorn auto-reload | |
| 61 | + |
| 62 | +## Key Conventions |
| 63 | + |
| 64 | +- **Pydantic v2**: use `model_config = ConfigDict(...)` and `json_schema_extra`; never `class Config` |
| 65 | +- **Lifespan**: DB init/teardown lives in the `@asynccontextmanager lifespan(app)` function in `main.py`; never use `@app.on_event` |
| 66 | +- **appName**: the pymongo client is always created with `appName="farm-intro-api"` |
| 67 | +- **No seed script**: tasks are created by users; the integration tests create and clean up their own data |
| 68 | +- **Collection name**: `tasks` in the database specified by `DB_NAME` |
| 69 | +- **Task `_id`**: UUID string (not ObjectId) — see EDD.md |
| 70 | + |
| 71 | +## When To Use EDD.md |
| 72 | + |
| 73 | +Use [EDD.md](./EDD.md) as the source of truth for the MongoDB data model in this repository. |
| 74 | + |
| 75 | +Consult [EDD.md](./EDD.md) before making changes that touch: |
| 76 | + |
| 77 | +- MongoDB collections, document structure, or field names |
| 78 | +- FastAPI routes that read or write database records |
| 79 | +- Validation, form fields, API payloads, or UI that depend on persisted data |
| 80 | +- Schema documentation, Mermaid diagrams, or entity modelling discussions |
| 81 | + |
| 82 | +## MongoDB Skills |
| 83 | + |
| 84 | +Use the official MongoDB agent skills from https://github.com/mongodb/agent-skills |
| 85 | +whenever the task is MongoDB-specific and a matching skill exists. |
0 commit comments