Skip to content

Commit ba60fe0

Browse files
authored
Merge pull request #3 from mongodb-developer/upgrade
Update project metadata, upgrade dependencies and add CI workflow
2 parents 154e945 + 99942db commit ba60fe0

17 files changed

Lines changed: 22865 additions & 31798 deletions

File tree

.claude/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"enabledPlugins": {
3+
"mongodb@claude-plugins-official": true
4+
}
5+
}

.devcontainer/devcontainer.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "FARM Stack To-Do App",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "app",
5+
"workspaceFolder": "/workspaces/FARM-Intro",
6+
"forwardPorts": [8000, 3000, 27017],
7+
"portsAttributes": {
8+
"8000": { "label": "FastAPI backend", "onAutoForward": "notify" },
9+
"3000": { "label": "React frontend", "onAutoForward": "openBrowser" },
10+
"27017": { "label": "MongoDB", "onAutoForward": "silent" }
11+
},
12+
"customizations": {
13+
"vscode": {
14+
"extensions": [
15+
"mongodb.mongodb-vscode",
16+
"ms-python.python",
17+
"ms-python.vscode-pylance",
18+
"dbaeumer.vscode-eslint",
19+
"esbenp.prettier-vscode"
20+
]
21+
}
22+
},
23+
"remoteEnv": {
24+
"DB_URL": "mongodb://localhost:27017/",
25+
"DB_NAME": "farm_intro"
26+
},
27+
"postCreateCommand": "pip install -r backend/requirements.txt && cd frontend && npm install",
28+
"postStartCommand": "echo 'Backend: DB_URL=mongodb://localhost:27017/ DB_NAME=farm_intro uvicorn main:app --reload (from backend/)'"
29+
}

.devcontainer/docker-compose.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
services:
2+
mongodb:
3+
image: mongodb/mongodb-atlas-local:8.0.3-20250506T093411Z
4+
ports:
5+
- "27017:27017"
6+
volumes:
7+
- mongodb-data:/data/db
8+
- mongodb-config:/data/configdb
9+
healthcheck:
10+
test: mongosh --eval "db.adminCommand({ ping: 1 })"
11+
interval: 10s
12+
timeout: 5s
13+
retries: 5
14+
15+
app:
16+
image: mcr.microsoft.com/devcontainers/python:1-3.13-bookworm
17+
network_mode: service:mongodb
18+
volumes:
19+
- ..:/workspaces/FARM-Intro:cached
20+
command: sleep infinity
21+
depends_on:
22+
mongodb:
23+
condition: service_healthy
24+
25+
volumes:
26+
mongodb-data:
27+
mongodb-config:

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
mongodb:
1414
image: mongo:latest
1515
options: >-
16-
--health-cmd mongosh
16+
--health-cmd "mongosh --eval 'db.adminCommand({ ping: 1 })'"
1717
--health-interval 10s
1818
--health-timeout 5s
1919
--health-retries 5
@@ -30,12 +30,12 @@ jobs:
3030
- name: Set up Python
3131
uses: actions/setup-python@v5
3232
with:
33-
python-version: "3.12"
33+
python-version: "3.13"
3434

3535
- name: Set up Node
3636
uses: actions/setup-node@v4
3737
with:
38-
node-version: "20"
38+
node-version: "22"
3939

4040
- name: Repo smoke checks
4141
shell: bash
@@ -114,7 +114,7 @@ jobs:
114114
fi
115115
116116
- name: Install integration test dependencies
117-
run: pip install pytest pymongo
117+
run: pip install pytest pymongo pydantic-settings
118118

119119
- name: Run integration tests
120120
env:

AGENTS.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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.

EDD.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# EDD — Entity Document Diagram
2+
3+
MongoDB data model for the FARM Stack To-Do App.
4+
5+
## Database
6+
7+
| Setting | Value |
8+
|---------------|--------------|
9+
| Database name | `farm_intro` (set via `DB_NAME` env var) |
10+
| Driver | pymongo 4.x `AsyncMongoClient` |
11+
| appName | `farm-intro-api` |
12+
13+
---
14+
15+
## Collections
16+
17+
### `tasks`
18+
19+
Stores to-do tasks created by users.
20+
21+
#### Fields
22+
23+
| Field | BSON type | Required | Notes |
24+
|-------------|-----------|----------|-------------------------------------------|
25+
| `_id` | String | Yes | UUID v4 string (not ObjectId) |
26+
| `name` | String | Yes | Display label for the task |
27+
| `completed` | Boolean | Yes | `false` on creation; `true` when done |
28+
29+
#### Example Document
30+
31+
```json
32+
{
33+
"_id": "00010203-0405-0607-0809-0a0b0c0d0e0f",
34+
"name": "Buy groceries",
35+
"completed": false
36+
}
37+
```
38+
39+
#### Indexes
40+
41+
| Index | Fields | Type | Notes |
42+
|------------|---------|---------|--------------------------|
43+
| `_id_` | `_id` | Default | Created automatically |
44+
45+
No additional indexes are defined. Add an index on `completed` if you add filtering by status.
46+
47+
---
48+
49+
## ER Diagram
50+
51+
```mermaid
52+
erDiagram
53+
TASKS {
54+
string _id PK "UUID v4"
55+
string name
56+
boolean completed
57+
}
58+
```
59+
60+
---
61+
62+
## Notes
63+
64+
- `_id` is a UUID string, not a MongoDB ObjectId. This is intentional so the frontend can use the ID directly without BSON serialisation.
65+
- The `completed` field defaults to `false` in the Pydantic model; callers can omit it on creation.
66+
- Deleting a task is a hard delete; there is no soft-delete or archive.
67+
- The integration tests (`tests/test_integration.py`) create and drop a separate `farm_intro_integration_test` database and do not affect production data.

0 commit comments

Comments
 (0)