Skip to main content

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.
When adding new backend routes, you must also add the corresponding proxy route in services/gateway/src/routes/proxy.ts.

Key Conventions

Authentication Pattern

Every service follows the same JWT pattern:
  • NEVER read request.headers["organization-id"] or request.headers["user-id"] directly
  • ALWAYS use JWT auth middleware via fastify.addHook("preHandler", ...)
  • ALWAYS access user info via request.user.organizationId and request.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 pg Pool
  • Credentials: db brainstormer, user brainstormer, password set by POSTGRES_PASSWORD on localhost:5432

Platform Config

API keys and settings can be stored in the platform_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 own CLAUDE.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 in infrastructure/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: