|
| 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 | +Penn Marketplace is a full-stack platform for Penn students to buy/sell items and browse/post sublets. It uses a **hybrid Docker development approach**: services (Postgres, Redis, Django, Next.js) run in Docker, but dependencies are also installed locally for IDE support. |
| 8 | + |
| 9 | +- **Frontend**: Next.js 15 (App Router) + React 19 + TypeScript + Tailwind CSS 4 |
| 10 | +- **Backend**: Django 5.0 + Django REST Framework |
| 11 | +- **Database**: PostgreSQL 15.8, **Cache**: Redis |
| 12 | +- **Auth**: Penn Platform OIDC via `django-labs-accounts` (backend) and `jose` JWT handling (frontend) |
| 13 | + |
| 14 | +## Commands |
| 15 | + |
| 16 | +### Development (Docker) |
| 17 | + |
| 18 | +```bash |
| 19 | +make setup # One-time: install local deps + pre-commit hooks |
| 20 | +make up # Start all containers (frontend :3000, backend :8000) |
| 21 | +make up-d # Start in background |
| 22 | +make down # Stop containers |
| 23 | +make logs # View all container logs |
| 24 | +``` |
| 25 | + |
| 26 | +### Frontend (from `frontend/`, package manager: pnpm) |
| 27 | + |
| 28 | +```bash |
| 29 | +pnpm dev # Dev server with Turbopack |
| 30 | +pnpm check # Run all checks: lint + typecheck + format:check |
| 31 | +pnpm fix # Auto-fix: lint:fix + format |
| 32 | +pnpm lint # ESLint only |
| 33 | +pnpm typecheck # TypeScript only (tsc --noEmit) |
| 34 | +pnpm format # Prettier only |
| 35 | +``` |
| 36 | + |
| 37 | +### Backend (from `backend/`, package manager: uv) |
| 38 | + |
| 39 | +```bash |
| 40 | +uv run pytest # Run tests |
| 41 | +uv run ruff check . # Lint |
| 42 | +uv run ruff format . # Format |
| 43 | +make migrate # Apply migrations (via Docker) |
| 44 | +make makemigrations # Create migrations (via Docker) |
| 45 | +make test # Run pytest via Docker |
| 46 | +make generate-data # Generate fake listings |
| 47 | +``` |
| 48 | + |
| 49 | +### CI Checks (must pass before merge) |
| 50 | + |
| 51 | +Backend: `uv run ruff check .` + `uv run ruff format .` |
| 52 | +Frontend: `pnpm lint` + `pnpm typecheck` |
| 53 | + |
| 54 | +Run `./scripts/check.sh` locally to match CI. Pre-commit hooks auto-fix on commit. |
| 55 | + |
| 56 | +## Architecture |
| 57 | + |
| 58 | +### Frontend (`frontend/`) |
| 59 | + |
| 60 | +- **App Router**: Pages in `app/`, with `items/`, `sublets/`, `create/` routes |
| 61 | +- **Server Actions** (`lib/actions.ts`): All API calls go through `serverFetch<T>()` which handles auth headers from cookies. This is the main data-fetching layer. |
| 62 | +- **TanStack Query**: Client-side caching/refetching via `providers/TanstackQueryProvider.tsx` |
| 63 | +- **Form handling**: React Hook Form + Zod schemas (`lib/validations.ts`) |
| 64 | +- **Middleware** (`middleware.ts`): OIDC token refresh and auth redirects |
| 65 | +- **UI primitives**: shadcn/ui components in `components/ui/` (built on Radix UI) |
| 66 | +- **Types**: All API response types in `lib/types.ts` |
| 67 | +- **Constants**: Environment variables and app constants in `lib/constants.ts` |
| 68 | + |
| 69 | +### Backend (`backend/`) |
| 70 | + |
| 71 | +- **Single Django app** (`market/`): models, views, serializers, permissions, urls |
| 72 | +- **Config**: Split settings in `config/settings/` (base, development, production) |
| 73 | +- **Models**: `User` (extends AbstractUser), `Listing` (base), `Item` and `Sublet` (inherit from Listing), `ListingImage`, `Offer`, `Category`, `Tag` |
| 74 | +- **Views**: DRF ViewSets (`Listings`, `Offers`, `Favorites`) and function-based views for user/phone endpoints |
| 75 | +- **URL prefix**: All market endpoints under `/market/` (listings, offers, favorites, tags, phone verification, user) |
| 76 | +- **Tests**: `tests/market/test_market.py` using pytest + DRF's APIClient |
| 77 | + |
| 78 | +### API Pattern |
| 79 | + |
| 80 | +REST JSON API with offset/limit pagination. Endpoints return `{ count, next, previous, results }`. Auth via `Authorization: Bearer <token>` header (set automatically by server actions). |
| 81 | + |
| 82 | +## Key Conventions |
| 83 | + |
| 84 | +### Frontend |
| 85 | +- Strict TypeScript (`"strict": true`) — avoid `any` |
| 86 | +- Prettier: 100 char width, 2 spaces, semicolons, Tailwind class sorting plugin |
| 87 | +- Server Components by default; use `"use client"` only when needed |
| 88 | +- Component composition: Page → Filters → Grid → Card |
| 89 | + |
| 90 | +### Backend |
| 91 | +- Ruff for linting + formatting (88 char width, double quotes, isort with 2 blank lines after imports) |
| 92 | +- Excluded from ruff: `migrations/`, `.venv/` |
| 93 | +- Migrations are auto-applied on Docker startup |
| 94 | + |
| 95 | +### Installing New Packages |
| 96 | + |
| 97 | +**Frontend**: `cd frontend && pnpm add <pkg>`, then `docker compose exec frontend pnpm install` |
| 98 | +**Backend**: `cd backend && uv add <pkg>`, then `docker compose exec backend uv sync` |
| 99 | + |
| 100 | +No Docker rebuild needed — lock files are volume-mounted. |
0 commit comments