CLAUDE.md — Full-Stack Monorepo
Project Basics
This is a full-stack TypeScript monorepo. Structure:
packages/shared/— Shared types, utilities, and validation schemasapps/api/— Backend API (Express/Fastify + Prisma)apps/web/— Frontend (React/Next.js)
Package manager: pnpm (with workspaces). All packages use TypeScript strict mode.
Shared Types
packages/shared/is the single source of truth for types used by both frontend and backend- API request/response types, validation schemas, and enums live here
- Never duplicate types between apps — import from shared
- When changing shared types, verify both apps still compile
API Contracts
- API changes require both backend and frontend updates in the same PR
- If the API response shape changes, update the shared type first, then both consumers
- Use versioned endpoints (
/api/v1/) for breaking changes - Document all endpoints with request/response types in shared package
Build Order
Build in this order — shared libs first, then consumers:
packages/shared— shared types and utilitiesapps/api— backend (depends on shared)apps/web— frontend (depends on shared)
pnpm --filter shared build && pnpm --filter api build && pnpm --filter web build
# Or: pnpm build (if workspace scripts are configured)
Database
- Migrations live in
apps/api/only — never run migrations from the frontend - Seed data lives alongside migrations
- Schema changes require a migration — never modify the database directly
- Use transactions for multi-table operations
- Test against a real database, not mocks
Environment Variables
- Each app has its own
.envfile (apps/api/.env,apps/web/.env) - Document all required variables in each app’s
.env.example - Shared/common variables (e.g., API URL) should be consistent across apps
- Never commit
.envfiles —.env.exampleonly - Frontend variables must be prefixed appropriately (
NEXT_PUBLIC_,VITE_, etc.)
Testing Strategy
- Unit tests per package:
packages/shared,apps/api,apps/webeach have their own test suite - Integration tests for the API: test endpoints with a real database
- E2E tests for critical user flows: login, core CRUD operations, checkout/payment
- Run all tests:
pnpm test(workspace-level) - Run specific:
pnpm --filter api test
Cross-App Changes
- Type changes: update
packages/sharedfirst, then update consumers - API endpoint changes: update backend, update shared types, update frontend — in that order
- Always run the full monorepo build after cross-app changes to catch type errors
- PR descriptions must list which apps are affected
Deployment
- If API response shape changes: deploy backend first, then frontend
- If frontend consumes a new endpoint: deploy backend first, then frontend
- If changes are independent: deploy in any order
- Use feature flags for gradual rollout of breaking changes
- Verify the deployed version matches the build (check health endpoint)
Verification
Before claiming work is done:
- Run
pnpm buildfrom the root — all packages build successfully - Run
pnpm testfrom the root — all test suites pass - Run
pnpm tsc --noEmitper app — zero type errors across the workspace - If cross-app changes: verify the API contract is consistent
- For UI changes: ask the user to visually confirm