|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is a full-stack FastAPI template with React frontend, built with modern tools and best practices. The project uses: |
| 8 | +- **Backend**: FastAPI, SQLModel (Pydantic + SQLAlchemy), PostgreSQL |
| 9 | +- **Frontend**: React, TypeScript, Vite, TanStack Router/Query, Chakra UI |
| 10 | +- **DevOps**: Docker Compose, Traefik, GitHub Actions |
| 11 | + |
| 12 | +## Quick Start Commands |
| 13 | + |
| 14 | +### Development Environment |
| 15 | +```bash |
| 16 | +# Start the full stack with Docker Compose |
| 17 | +docker compose watch |
| 18 | + |
| 19 | +# URLs after starting: |
| 20 | +# Frontend: http://localhost:5173 |
| 21 | +# Backend API: http://localhost:8000 |
| 22 | +# API Docs: http://localhost:8000/docs |
| 23 | +# Adminer (DB): http://localhost:8080 |
| 24 | +# Traefik UI: http://localhost:8090 |
| 25 | +``` |
| 26 | + |
| 27 | +### Backend Development |
| 28 | +```bash |
| 29 | +# Install dependencies and activate environment |
| 30 | +cd backend |
| 31 | +uv sync |
| 32 | +source .venv/bin/activate |
| 33 | + |
| 34 | +# Run backend locally (stop Docker service first) |
| 35 | +docker compose stop backend |
| 36 | +fastapi dev app/main.py |
| 37 | + |
| 38 | +# Run backend tests |
| 39 | +./scripts/test.sh # or |
| 40 | +uv run pytest |
| 41 | + |
| 42 | +# Run specific test |
| 43 | +uv run pytest tests/test_specific.py::test_function |
| 44 | + |
| 45 | +# Database migrations |
| 46 | +docker compose exec backend alembic revision --autogenerate -m "message" |
| 47 | +docker compose exec backend alembic upgrade head |
| 48 | +``` |
| 49 | + |
| 50 | +### Frontend Development |
| 51 | +```bash |
| 52 | +# Install dependencies and start dev server |
| 53 | +cd frontend |
| 54 | +npm install |
| 55 | +npm run dev |
| 56 | + |
| 57 | +# Generate API client after backend changes |
| 58 | +./scripts/generate-client.sh |
| 59 | + |
| 60 | +# Run frontend linting |
| 61 | +npm run lint |
| 62 | + |
| 63 | +# Run E2E tests |
| 64 | +npx playwright test |
| 65 | +npx playwright test --ui # Interactive mode |
| 66 | +``` |
| 67 | + |
| 68 | +## Architecture Overview |
| 69 | + |
| 70 | +### Backend Structure |
| 71 | +``` |
| 72 | +backend/ |
| 73 | +├── app/ |
| 74 | +│ ├── api/ # API routes organized by domain |
| 75 | +│ ├── core/ # Configuration, security, database setup |
| 76 | +│ ├── models.py # SQLModel database models |
| 77 | +│ ├── crud.py # Reusable CRUD operations |
| 78 | +│ └── tests/ # Pytest test files |
| 79 | +└── scripts/ # Development and deployment scripts |
| 80 | +``` |
| 81 | + |
| 82 | +### Frontend Structure |
| 83 | +``` |
| 84 | +frontend/ |
| 85 | +├── src/ |
| 86 | +│ ├── client/ # Auto-generated OpenAPI client |
| 87 | +│ ├── components/ # Reusable UI components |
| 88 | +│ ├── routes/ # TanStack Router pages |
| 89 | +│ └── hooks/ # Custom React hooks |
| 90 | +└── tests/ # Playwright E2E tests |
| 91 | +``` |
| 92 | + |
| 93 | +## Code Quality & Testing |
| 94 | + |
| 95 | +### Backend |
| 96 | +- **Linting**: Ruff (configured in pyproject.toml) |
| 97 | +- **Type checking**: MyPy (strict mode) |
| 98 | +- **Testing**: Pytest with coverage reports in `htmlcov/` |
| 99 | +- **Pre-commit**: Runs ruff format, linting, and basic checks |
| 100 | + |
| 101 | +### Frontend |
| 102 | +- **Linting**: Biome (configured in biome.json) |
| 103 | +- **Type checking**: TypeScript strict mode |
| 104 | +- **Testing**: Playwright for E2E tests |
| 105 | +- **Pre-commit**: Runs linting and formatting |
| 106 | + |
| 107 | +## Common Development Tasks |
| 108 | + |
| 109 | +### Adding a new API endpoint |
| 110 | +1. Add model in `backend/app/models.py` |
| 111 | +2. Create migration: `alembic revision --autogenerate -m "Add new model"` |
| 112 | +3. Add CRUD operations in `backend/app/crud.py` |
| 113 | +4. Add route in appropriate file under `backend/app/api/routes/` |
| 114 | +5. Update frontend client: `./scripts/generate-client.sh` |
| 115 | +6. Add frontend components/routes as needed |
| 116 | + |
| 117 | +### Database changes |
| 118 | +```bash |
| 119 | +# Create migration after model changes |
| 120 | +docker compose exec backend alembic revision --autogenerate -m "description" |
| 121 | + |
| 122 | +# Apply migration |
| 123 | +docker compose exec backend alembic upgrade head |
| 124 | + |
| 125 | +# Check current revision |
| 126 | +docker compose exec backend alembic current |
| 127 | +``` |
| 128 | + |
| 129 | +### Environment Variables |
| 130 | +Key variables in `.env`: |
| 131 | +- `SECRET_KEY` - JWT secret (generate with `python -c "import secrets; print(secrets.token_urlsafe(32))"`) |
| 132 | +- `POSTGRES_PASSWORD` - Database password |
| 133 | +- `FIRST_SUPERUSER_PASSWORD` - Initial admin password |
| 134 | +- `DOMAIN` - For local testing with subdomains (e.g., `localhost.tiangolo.com`) |
| 135 | + |
| 136 | +## Testing Commands |
| 137 | + |
| 138 | +```bash |
| 139 | +# Backend tests |
| 140 | +./scripts/test.sh # All tests |
| 141 | +uv run pytest tests/api/ # API tests only |
| 142 | +uv run pytest -x # Stop on first failure |
| 143 | +uv run pytest --cov=app # With coverage |
| 144 | + |
| 145 | +# Frontend tests |
| 146 | +npm run test:e2e # Run Playwright tests |
| 147 | +npm run test:e2e -- --ui # Interactive mode |
| 148 | +npm run test:e2e -- --debug # Debug mode |
| 149 | +``` |
| 150 | + |
| 151 | +## Deployment |
| 152 | +See `deployment.md` for production deployment instructions using Docker Compose with Traefik for HTTPS. |
0 commit comments