Monorepo Layout
Brainstormer V2 uses a Turbo + npm workspaces monorepo with three top-level workspace directories:Backend Service Structure
All backend services follow the same standardized layout:Each service has its own
CLAUDE.md file with endpoints, configuration, and patterns specific to that module.Request Flow
All authenticated frontend API calls follow this path: The gateway verifies the JWT signature and forwards auth context as headers to downstream services.Key Conventions
Authentication Pattern
Every service follows the same JWT pattern:- NEVER read
request.headers["organization-id"]orrequest.headers["user-id"]directly - ALWAYS use JWT auth middleware via
fastify.addHook("preHandler", ...) - ALWAYS access user info via
request.user.organizationIdandrequest.user.id - Downstream services trust gateway-forwarded headers; the gateway verifies signatures with
verifyJwt(token, JWT_SECRET)
Database Access
- Raw SQL with parameterized queries (no ORM)
- Repository pattern for data access
- Connection pooling via
pgPool - Credentials: db
brainstormer, userbrainstormer, password set byPOSTGRES_PASSWORDonlocalhost:5432
Platform Config
API keys and settings can be stored in theplatform_config DB table:
1
DB Storage
Auth service manages
GET/POST /auth/admin/config for encrypted key-value pairs.2
Gateway Proxy
Gateway proxies config requests to auth service.
3
Service Loading
Services fetch config on startup. DB values take precedence over env vars.
4
Encryption
Sensitive values encrypted with AES-256-GCM via
packages/shared/src/crypto.ts.Documentation Organization
Root-Level Files
Module-Level CLAUDE.md
Each service has its ownCLAUDE.md:
Docs Subfolders
File Naming
- UPPERCASE for major docs (e.g.,
KNOWLEDGE_BASE_SYSTEM.md) - lowercase-with-hyphens for scripts
- Never commit test artifacts to root
Development Commands
Infrastructure (Docker)
Migrations
Migrations live ininfrastructure/postgres/migrations/. New files use a UTC timestamp prefix — $(date -u +%Y%m%d%H%M%S)_short_snake_name.sql — enforced by the migration-guard CI job; legacy files keep their sequential NNN_ numbers and sort first. Run them with:

