Here's your plan: # GET /healthz Endpoint Implementation Plan ## Context The FastAPI app (`src/my_deepagent/api/app.py`) uses: - **Database**: Singleton `Database` instance stored in `app.state.db` during lifespan startup - **Dependency injection**: `deps.get_db(request)` retrieves the shared DB instance - **Router pattern**: API routes are organized as separate modules in `src/my_deepagent/api/routes/` and included via `app.include_router()` - **Async/await**: All database operations are async (SQLAlchemy AsyncSession) - **Response format**: JSON responses via Pydantic models or dicts ## Phases 1. Create response model in `api/models.py` with `status` (str) and `db` (bool) fields. 2. Create new route module `api/routes/health.py` with `GET /healthz` endpoint. 3. Endpoint executes `SELECT 1` via `db.session()` to test connectivity; catches exceptions. 4. Include health router in `app.py` with prefix `/api/health` (or `/healthz` directly). 5. Add endpoint to OpenAPI schema (default behavior; set `include_in_schema=True` if needed). 6. Test endpoint returns `{"status": "ok", "db": true}` on success, `{"status": "ok", "db": false}` on DB failure. ## Verification - **Unit test**: Mock `Database`, verify response structure and `db` field logic. - **Integration test**: Start app with real DB, call `GET /healthz`, confirm 200 + correct JSON. - **Failure case**: Simulate DB unavailability (e.g., wrong connection string), verify `db: false` returned. - **Schema check**: Confirm endpoint appears in OpenAPI docs at `/docs`.