|
| 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 | +Forms Platform is a forms-as-a-service platform for government organizations, enabling non-technical staff to create user-friendly "guided interview" web experiences. The platform serves two primary personas: |
| 8 | +- **Form Builders**: Create and publish forms via a no-code browser interface |
| 9 | +- **Form Fillers**: Complete forms created by form builders |
| 10 | + |
| 11 | +## Core Concepts |
| 12 | + |
| 13 | +- **Blueprint**: Defines the structure of an interactive session between government and user |
| 14 | +- **Conversation**: A single instance of a blueprint (one interactive session) |
| 15 | +- **Pattern/Template**: Building blocks of a blueprint, implementing UX best-practices |
| 16 | +- **Prompt**: Produced by a pattern, defines what is presented to the user at a single point in a conversation |
| 17 | +- **Component**: UI building block of prompts |
| 18 | + |
| 19 | +## Common Commands |
| 20 | + |
| 21 | +### Setup |
| 22 | +```bash |
| 23 | +pnpm install # Install dependencies |
| 24 | +pnpm dlx playwright@1.51.1 install --with-deps # One-time: Install browsers for Vitest |
| 25 | +``` |
| 26 | + |
| 27 | +### Development |
| 28 | +```bash |
| 29 | +pnpm build # Build all packages (required before dev) |
| 30 | +pnpm dev # Start dev servers (Astro at :4321, Storybook at :61610) |
| 31 | +``` |
| 32 | + |
| 33 | +### Testing |
| 34 | +```bash |
| 35 | +pnpm test # Run all tests (requires Docker/Podman for PostgreSQL) |
| 36 | +pnpm vitest # Run tests in watch mode |
| 37 | +pnpm test:ci # Run tests in CI mode |
| 38 | +pnpm test:e2e:dev # Run E2E tests in dev mode |
| 39 | +pnpm test:e2e:ci # Run E2E tests in CI mode |
| 40 | +``` |
| 41 | + |
| 42 | +### Testing Individual Packages |
| 43 | +```bash |
| 44 | +pnpm --filter @flexion/forms-design test:watch # Watch mode for specific package |
| 45 | +``` |
| 46 | + |
| 47 | +### Code Quality |
| 48 | +```bash |
| 49 | +pnpm lint # Lint all packages |
| 50 | +pnpm format # Format code with Prettier |
| 51 | +pnpm typecheck # Type-check all packages |
| 52 | +``` |
| 53 | + |
| 54 | +### Cleanup |
| 55 | +```bash |
| 56 | +pnpm clean:dist # Remove all build artifacts recursively |
| 57 | +pnpm clean:modules # Remove all node_modules recursively |
| 58 | +``` |
| 59 | + |
| 60 | +### CLI Tool |
| 61 | +```bash |
| 62 | +./manage.sh --help # Access command-line operations |
| 63 | +``` |
| 64 | + |
| 65 | +## Architecture |
| 66 | + |
| 67 | +### Monorepo Structure |
| 68 | + |
| 69 | +This is a pnpm workspace managed with Turborepo for efficient builds. The codebase is organized into packages and apps: |
| 70 | + |
| 71 | +**Packages** (in `/packages/`): |
| 72 | +- `forms`: Core business logic, services, patterns, repository, and document handling |
| 73 | + - `/src/services`: Public interface of Forms Platform |
| 74 | + - `/src/patterns`: Form building blocks ("patterns") |
| 75 | + - `/src/repository`: Database routines |
| 76 | + - `/src/documents`: Document ingest and creation |
| 77 | + - `/src/context`: Runtime contexts (testing, browser, server-side) |
| 78 | +- `design`: User-facing React components, USWDS theme, Storybook stories |
| 79 | +- `server`: Node.js web server built on Astro with Express adapter |
| 80 | +- `auth`: Authentication and authorization (uses deprecated Lucia Auth with Arctic for Login.gov) |
| 81 | +- `database`: PostgreSQL (production) and SQLite (testing) support with Knex migrations and Kysely queries |
| 82 | +- `common`: Shared utilities |
| 83 | + |
| 84 | +**Apps** (in `/apps/`): |
| 85 | +- `spotlight`: Main Astro website (http://localhost:4321/) |
| 86 | +- `sandbox`: Testing/demo application |
| 87 | +- `server-doj`: Department of Justice specific server instance |
| 88 | +- `cli`: Command-line interface (accessed via `./manage.sh`) |
| 89 | + |
| 90 | +**Infrastructure** (in `/infra/`): |
| 91 | +- `aws-cdk`: AWS CDK infrastructure code |
| 92 | +- `cdktf`: Terraform CDK infrastructure code |
| 93 | +- `core`: Shared infrastructure utilities |
| 94 | + |
| 95 | +### Dependency Flow |
| 96 | +``` |
| 97 | +server → auth, common, database, design, forms |
| 98 | +forms → common, database |
| 99 | +design → common, forms |
| 100 | +auth → common, database |
| 101 | +database → common |
| 102 | +common → (no dependencies) |
| 103 | +``` |
| 104 | + |
| 105 | +### Key Technologies |
| 106 | + |
| 107 | +- **Build System**: pnpm workspaces + Turborepo for efficient caching and builds |
| 108 | +- **Frontend**: Astro (static site framework), React components, USWDS design system |
| 109 | +- **Backend**: Node.js with Express |
| 110 | +- **Database**: PostgreSQL (production), SQLite (testing) |
| 111 | + - Query builders: Kysely (type-safe queries) and Knex.js (migrations) |
| 112 | + - Testing: Testcontainers for Postgres unit tests, in-memory SQLite for integration tests |
| 113 | +- **Auth**: Lucia Auth (deprecated) with Arctic for Login.gov OIDC/PKCE |
| 114 | +- **Testing**: Vitest (unit/integration), Playwright (E2E), @vitest/browser (Storybook) |
| 115 | +- **Language**: TypeScript throughout |
| 116 | + |
| 117 | +### Pattern System |
| 118 | + |
| 119 | +Patterns are the platform's primary building blocks. Each pattern has: |
| 120 | +- `type`: String identifier for the pattern type |
| 121 | +- `id`: Unique identifier for the pattern instance |
| 122 | +- `data`: Configuration data specific to the pattern type |
| 123 | + |
| 124 | +Patterns can be constructed manually or via `PatternBuilder` helper classes. They are stored on the form `Blueprint`'s pattern attribute. |
| 125 | + |
| 126 | +## Testing Strategy |
| 127 | + |
| 128 | +- **Unit tests**: Service-level with in-memory SQLite via `createInMemoryDatabaseContext()` |
| 129 | +- **Integration tests**: Database gateway logic tested against PostgreSQL Testcontainers |
| 130 | +- **E2E tests**: Playwright tests for full user flows |
| 131 | +- **Component tests**: Storybook + @vitest/browser |
| 132 | + |
| 133 | +Use `describeDatabase` helper for testing database routines against both SQLite and PostgreSQL. |
| 134 | + |
| 135 | +## Important Notes |
| 136 | + |
| 137 | +- Node version is specified in `.nvmrc` - use `nvm install` to ensure correct version |
| 138 | +- Requires Docker or Podman for running tests (PostgreSQL container) |
| 139 | +- Playwright version must match exactly (1.51.1) across local and CI environments |
| 140 | +- Build is required before running `pnpm dev` |
| 141 | +- Pre-commit hook runs `pnpm format` automatically |
0 commit comments