|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Full Stack FastAPI Template — a monorepo with a Python/FastAPI backend and a React/TypeScript frontend. Services run together via Docker Compose. |
| 8 | + |
| 9 | +## Commands |
| 10 | + |
| 11 | +### Full stack (Docker Compose) |
| 12 | + |
| 13 | +```bash |
| 14 | +docker compose watch # start the full stack with live reload |
| 15 | +docker compose logs backend # tail logs for a specific service |
| 16 | +``` |
| 17 | + |
| 18 | +### Backend (from `backend/`) |
| 19 | + |
| 20 | +```bash |
| 21 | +uv sync # install dependencies |
| 22 | +source .venv/bin/activate # activate virtual environment |
| 23 | +fastapi dev app/main.py # run dev server locally (without Docker) |
| 24 | + |
| 25 | +# Testing |
| 26 | +bash ./scripts/test.sh # run tests with coverage |
| 27 | +# Against running Docker stack: |
| 28 | +docker compose exec backend bash scripts/tests-start.sh |
| 29 | +docker compose exec backend bash scripts/tests-start.sh -x # stop on first failure |
| 30 | + |
| 31 | +# Linting / formatting |
| 32 | +uv run prek run --all-files # run all pre-commit hooks manually |
| 33 | + |
| 34 | +# Database migrations (inside backend container) |
| 35 | +alembic revision --autogenerate -m "description" |
| 36 | +alembic upgrade head |
| 37 | +``` |
| 38 | + |
| 39 | +### Frontend (from `frontend/`) |
| 40 | + |
| 41 | +```bash |
| 42 | +bun install |
| 43 | +bun run dev # dev server at http://localhost:5173 |
| 44 | +bun run build # type-check + production build |
| 45 | +bun run lint # biome check + auto-fix |
| 46 | +bun run generate-client # regenerate OpenAPI client from openapi.json |
| 47 | +bunx playwright test # E2E tests (requires backend stack running) |
| 48 | +bunx playwright test --ui # E2E tests with UI |
| 49 | +``` |
| 50 | + |
| 51 | +### Regenerate frontend API client |
| 52 | + |
| 53 | +Run from project root after backend schema changes: |
| 54 | + |
| 55 | +```bash |
| 56 | +bash ./scripts/generate-client.sh |
| 57 | +``` |
| 58 | + |
| 59 | +This exports the OpenAPI schema from the running backend, writes it to `frontend/openapi.json`, regenerates `frontend/src/client/`, and lints. |
| 60 | + |
| 61 | +## Architecture |
| 62 | + |
| 63 | +### Backend (`backend/`) |
| 64 | + |
| 65 | +- **FastAPI** app entrypoint: `backend/app/main.py` |
| 66 | +- **API routes**: `backend/app/api/routes/` — `login.py`, `users.py`, `items.py`, `utils.py`, `private.py` (local-only) |
| 67 | +- **Models**: `backend/app/models.py` — all SQLModel models live here. Each model follows the pattern: `*Base` (shared) → `*Create`/`*Update` (input) → `*(table=True)` (DB) → `*Public` (API response) |
| 68 | +- **CRUD**: `backend/app/crud.py` — database operations |
| 69 | +- **Config**: `backend/app/core/config.py` — `Settings` loaded from `../.env` via pydantic-settings |
| 70 | +- **DB setup**: `backend/app/core/db.py` |
| 71 | +- **Auth**: `backend/app/core/security.py` + `backend/app/api/deps.py` — JWT via PyJWT, passwords via pwdlib (argon2/bcrypt) |
| 72 | +- **Migrations**: Alembic in `backend/app/alembic/`; run inside the container |
| 73 | + |
| 74 | +### Frontend (`frontend/src/`) |
| 75 | + |
| 76 | +- **Router**: TanStack Router with file-based routes in `src/routes/`; `routeTree.gen.ts` is auto-generated |
| 77 | +- **Data fetching**: TanStack Query wrapping the generated OpenAPI client in `src/client/` |
| 78 | +- **UI components**: shadcn/ui (Radix UI primitives + Tailwind CSS v4) in `src/components/` |
| 79 | +- **Forms**: react-hook-form + Zod validation |
| 80 | +- **Theme**: next-themes for dark mode |
| 81 | + |
| 82 | +### Key data flows |
| 83 | + |
| 84 | +1. Backend models defined in `models.py` → Alembic generates migrations → FastAPI exposes OpenAPI schema |
| 85 | +2. `scripts/generate-client.sh` exports the schema → `@hey-api/openapi-ts` generates typed client in `frontend/src/client/` |
| 86 | +3. Frontend components import from `src/client/` and call API via TanStack Query hooks |
| 87 | + |
| 88 | +### Environment |
| 89 | + |
| 90 | +All configuration lives in the root `.env` file, which is read by both Docker Compose and the backend (`config.py` looks for `../.env`). The frontend reads `VITE_API_URL` from `frontend/.env`. |
| 91 | + |
| 92 | +### Pre-commit hooks |
| 93 | + |
| 94 | +Configured via `.pre-commit-config.yaml` using `prek`. Runs ruff (lint + format) on Python and Biome on TypeScript. Install with `uv run prek install -f` from `backend/`. |
0 commit comments