|
| 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 | +LLSC (Leukemia & Lymphoma Society of Canada) is a full-stack application built for matching participants with volunteers. The application uses a monorepo structure with separate frontend and backend services. |
| 8 | + |
| 9 | +**Tech Stack:** |
| 10 | +- Backend: FastAPI (Python 3.12), SQLAlchemy, PostgreSQL, Alembic migrations |
| 11 | +- Frontend: Next.js, React, TypeScript, Chakra UI |
| 12 | +- Infrastructure: Docker, Docker Compose |
| 13 | +- Auth: Firebase Authentication |
| 14 | +- Email: AWS SES |
| 15 | + |
| 16 | +## Development Commands |
| 17 | + |
| 18 | +### Initial Setup |
| 19 | +```bash |
| 20 | +# Start Docker containers (required for database) |
| 21 | +docker-compose up -d |
| 22 | + |
| 23 | +# Backend setup |
| 24 | +cd backend |
| 25 | +pdm install |
| 26 | +pdm run dev # Runs on http://localhost:8000 |
| 27 | + |
| 28 | +# Frontend setup |
| 29 | +cd frontend |
| 30 | +npm install |
| 31 | +npm run dev # Runs on http://localhost:3000 |
| 32 | +``` |
| 33 | + |
| 34 | +### Backend Commands |
| 35 | +```bash |
| 36 | +cd backend |
| 37 | + |
| 38 | +# Development |
| 39 | +pdm run dev # Start FastAPI dev server (port 8000) |
| 40 | + |
| 41 | +# Database |
| 42 | +pdm run alembic revision --autogenerate -m "message" # Create migration |
| 43 | +pdm run alembic upgrade head # Apply migrations |
| 44 | +pdm run seed # Seed database with reference data |
| 45 | +pdm run db-reset # Reset DB: down, up, migrate, seed |
| 46 | + |
| 47 | +# Testing |
| 48 | +pdm run tests # Run pytest tests |
| 49 | + |
| 50 | +# Linting & Formatting |
| 51 | +pdm run ruff check . # Check linting |
| 52 | +pdm run ruff check --fix . # Fix linting issues |
| 53 | +pdm run ruff format . # Format code |
| 54 | +pdm run precommit # Run pre-commit hooks manually |
| 55 | +``` |
| 56 | + |
| 57 | +### Frontend Commands |
| 58 | +```bash |
| 59 | +cd frontend |
| 60 | + |
| 61 | +npm run dev # Start Next.js dev server |
| 62 | +npm run build # Build for production |
| 63 | +npm run lint # Run ESLint |
| 64 | +npm run lint:fix # Fix ESLint issues |
| 65 | +npm run prettier:check # Check formatting |
| 66 | +npm run prettier:fix # Fix formatting |
| 67 | +npm run format # Run both prettier and eslint fixes |
| 68 | +``` |
| 69 | + |
| 70 | +### Docker Commands |
| 71 | +```bash |
| 72 | +# Database access |
| 73 | +docker exec -it llsc_db psql -U postgres -d llsc |
| 74 | + |
| 75 | +# Container management |
| 76 | +docker-compose up --build # Rebuild and start |
| 77 | +docker-compose down # Stop containers |
| 78 | +docker-compose down --volumes # Stop and remove volumes |
| 79 | +docker ps # List running containers |
| 80 | +``` |
| 81 | + |
| 82 | +## Architecture |
| 83 | + |
| 84 | +### Backend Structure |
| 85 | + |
| 86 | +The backend follows a **layered service architecture**: |
| 87 | + |
| 88 | +- **Models** (`app/models/`): SQLAlchemy ORM models. All models must be imported in `app/models/__init__.py` for Alembic autogeneration to work. |
| 89 | +- **Schemas** (`app/schemas/`): Pydantic schemas for request/response validation. |
| 90 | +- **Routes** (`app/routes/`): FastAPI route handlers that accept requests and return responses. |
| 91 | +- **Services** (`app/services/`): Business logic layer that routes call into. |
| 92 | + - `implementations/`: Concrete service implementations |
| 93 | +- **Interfaces** (`app/interfaces/`): Abstract base classes defining service contracts. |
| 94 | +- **Middleware** (`app/middleware/`): Request/response middleware (e.g., `AuthMiddleware`). |
| 95 | +- **Utilities** (`app/utilities/`): Shared utilities, constants, Firebase, SES initialization. |
| 96 | +- **Seeds** (`app/seeds/`): Database seeding scripts for reference data. |
| 97 | + |
| 98 | +**Key Backend Files:** |
| 99 | +- `app/server.py`: FastAPI application initialization, middleware setup, route registration |
| 100 | +- `app/__init__.py`: Contains `run_migrations()` which auto-runs Alembic migrations on startup |
| 101 | +- `app/utilities/constants.py`: Contains `LOGGER_NAME()` function for creating standardized loggers |
| 102 | + |
| 103 | +**Authentication Flow:** |
| 104 | +- Firebase tokens are validated via `AuthMiddleware` |
| 105 | +- Public paths are defined in `server.py` (`PUBLIC_PATHS`) |
| 106 | +- Protected routes require valid Firebase auth tokens |
| 107 | + |
| 108 | +**Database Migrations:** |
| 109 | +When adding a new model, you MUST: |
| 110 | +1. Create the model file in `app/models/` |
| 111 | +2. Import it in `app/models/__init__.py` and add to `__all__` |
| 112 | +3. Run `pdm run alembic revision --autogenerate -m "description"` |
| 113 | +4. Run `pdm run alembic upgrade head` |
| 114 | + |
| 115 | +### Frontend Structure |
| 116 | + |
| 117 | +The frontend is a **Next.js application** using TypeScript and Chakra UI: |
| 118 | + |
| 119 | +- **Pages** (`src/pages/`): Next.js file-based routing |
| 120 | + - `participant/`: Participant-specific pages (intake, ranking) |
| 121 | + - `volunteer/`: Volunteer-specific pages (intake, secondary application) |
| 122 | + - `admin/`: Admin dashboard pages |
| 123 | +- **Components** (`src/components/`): Reusable React components |
| 124 | + - `auth/`: Authentication-related components |
| 125 | + - `intake/`: Form intake components |
| 126 | + - `ranking/`: Ranking interface components |
| 127 | + - `ui/`: Base UI components |
| 128 | +- **API Clients** (`src/APIClients/`): API communication layer with backend |
| 129 | +- **Contexts** (`src/contexts/`): React Context providers for global state |
| 130 | +- **Hooks** (`src/hooks/`): Custom React hooks |
| 131 | +- **Types** (`src/types/`): TypeScript type definitions |
| 132 | +- **Utils** (`src/utils/`): Utility functions |
| 133 | + |
| 134 | +**Key Frontend Files:** |
| 135 | +- `src/pages/_app.tsx`: Next.js app wrapper, providers setup |
| 136 | +- `src/pages/_document.tsx`: Custom document for Next.js |
| 137 | + |
| 138 | +## Version Control |
| 139 | + |
| 140 | +### Branching |
| 141 | +- Branch off `main` for all feature work |
| 142 | +- Branch naming: `<github-username>/<ticket-number>-description` (e.g., `mslwang/LLSC-42-readme-update`) |
| 143 | +- Use rebase instead of merge to integrate main: `git pull origin main --rebase` |
| 144 | + |
| 145 | +### Commits |
| 146 | +- Commits should be atomic and self-contained |
| 147 | +- Use imperative tense with capitalized first word (e.g., "Add user authentication") |
| 148 | +- Squash trivial commits (typos, formatting) using `git rebase -i` |
| 149 | + |
| 150 | +## Logging |
| 151 | + |
| 152 | +To add a logger to any file: |
| 153 | +```python |
| 154 | +from app.utilities.constants import LOGGER_NAME |
| 155 | +import logging |
| 156 | + |
| 157 | +log = logging.getLogger(LOGGER_NAME("my_service")) |
| 158 | +``` |
| 159 | + |
| 160 | +New logger names must be added to `alembic.ini` under the logger section. |
| 161 | + |
| 162 | +## Testing |
| 163 | + |
| 164 | +- Backend tests: `pdm run tests` (runs pytest in `backend/tests/`) |
| 165 | +- Test structure: `tests/unit/` and `tests/functional/` |
| 166 | +- CI runs linting, formatting checks, unit tests, and security scans on every PR |
| 167 | + |
| 168 | +## Firebase Configuration |
| 169 | + |
| 170 | +Backend requires: |
| 171 | +1. `serviceAccountKey.json` in `backend/` directory (obtain from Firebase Console) |
| 172 | +2. `FIREBASE_WEB_API_KEY` in `.env` file |
| 173 | + |
| 174 | +## Environment Variables |
| 175 | + |
| 176 | +Environment variables are stored in: |
| 177 | +- Backend: `.env` in project root (loaded by backend service) |
| 178 | +- Frontend: `frontend/.env` |
| 179 | + |
| 180 | +Secrets are documented in the LLSC Notion workspace. |
0 commit comments