---
estimated_steps: 22
estimated_files: 2
skills_used: []
---

# T01: Add GET /api/v1/stats endpoint returning technique and creator counts

Create a new stats router with a single endpoint that returns technique_count and creator_count. Register it in main.py.

## Steps

1. Create `backend/routers/stats.py` with a `GET /stats` endpoint:
   - Import `APIRouter`, `Depends`, `AsyncSession` from FastAPI/SQLAlchemy
   - Import `get_session` from `database`
   - Import `TechniquePage` and `Creator` from `models`
   - Use `select(func.count()).select_from(TechniquePage)` and same for `Creator`
   - Return a dict `{"technique_count": N, "creator_count": N}`
   - Use `tags=["stats"]` on the router
2. Edit `backend/main.py` to add `from routers import stats` and `app.include_router(stats.router, prefix="/api/v1")` following the existing pattern (after the last `include_router` call around line 88).
3. Rebuild and restart the API container on ub01:
   ```
   ssh ub01 'cd /vmPool/r/repos/xpltdco/chrysopedia && git pull && docker compose build chrysopedia-api && docker compose up -d chrysopedia-api'
   ```
4. Verify: `curl http://ub01:8096/api/v1/stats` returns JSON with both counts > 0.

## Must-Haves

- [ ] Endpoint returns `{"technique_count": int, "creator_count": int}`
- [ ] Both counts are > 0 against the live database
- [ ] Router registered with `/api/v1` prefix

## Verification

- `curl -s http://ub01:8096/api/v1/stats | python3 -c "import sys,json; d=json.load(sys.stdin); assert d['technique_count']>0 and d['creator_count']>0, f'Bad counts: {d}'"` exits 0
- `curl -s -o /dev/null -w '%{http_code}' http://ub01:8096/api/v1/stats` returns 200

## Inputs

- ``backend/models.py` — TechniquePage and Creator model definitions`
- ``backend/database.py` — get_session dependency`
- ``backend/main.py` — router registration pattern (lines 78-88)`

## Expected Output

- ``backend/routers/stats.py` — new stats router with GET /stats endpoint`
- ``backend/main.py` — edited to register stats router`

## Verification

curl -s http://ub01:8096/api/v1/stats | python3 -c "import sys,json; d=json.load(sys.stdin); assert d['technique_count']>0 and d['creator_count']>0"
