This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Lightning is an open source workflow platform for governments and non-profits to move health and survey data between systems. It's built on Elixir/Phoenix with PostgreSQL, featuring React components and real-time collaborative editing via Yjs CRDTs.
./bin/bootstrap # Initial setup (run once, or when switching branches)
iex -S mix phx.server # Run development server
mix verify # Run all code quality checks before committingMIX_ENV=test mix ecto.create # First time test DB setup only
mix test # Run all tests (don't use -v flag)
mix test path/to/test.exs # Run single file
mix test path/to/test.exs:42 # Run test at specific line
mix test --only focus # Run tests tagged with @tag :focuscd assets
npm test # Run unit tests once
npm run test:watch # Run tests in watch mode
npm run test:e2e # Run E2E tests
npm run test:e2e:ui # E2E with interactive UI
npm run lint # Lint TypeScript
npx tsc --noEmit --project ./tsconfig.browser.json # Type checkmix format # Format Elixir code (before committing)
mix credo --strict --all # Static analysis
mix dialyzer # Type checking
mix sobelow # Security analysismix ecto.migrate # Run migrations
mix ecto.reset # Drop and recreate database
mix ecto.gen.migration short_descriptive_name # Generate migrationImportant Notes:
- Phoenix auto-builds assets; use
mix esbuild defaultor Tidewave MCP to check for build errors - For JS/TS issues, prefer
mcp__ide__getDiagnosticsovertsc - Never commit the
.contextdirectory (symlink to shared folder)
lib/lightning/- Core business logic, contexts, schemaslib/lightning_web/- LiveViews, controllers, API, channelsassets/js/- React components, TypeScripttest/- Mirrors source structure
- Workflows - DAGs with jobs, triggers, edges (
lib/lightning/workflows.ex) - Jobs - JavaScript execution units with NPM adaptors
- Accounts - User management, authentication
- Projects - Main organizational unit
- Credentials - External service authentication (encrypted)
- Runs / WorkOrders - Workflow execution management
- Collections - Key-value data store
Workflows are directed acyclic graphs (DAGs):
- Triggers: Webhook, Cron, or Kafka initiation
- Jobs: JavaScript code executed with NPM adaptors
- Edges: Flow control with conditions (
:always,:on_job_success,:on_job_failure,:js_expression)
Key features:
- Snapshot system with
lock_versionoptimistic locking - Real-time collaborative editing via Yjs CRDTs
- Presence system for edit priority
Real-time multi-user workflow editing using:
- Yjs - CRDT for conflict-free collaborative editing
- y-phoenix-channel - Yjs sync over Phoenix Channels
- Y_ex - Elixir Yjs bindings (see
.claude/guidelines/yex-guidelines.md)
Y.Doc transactions have non-obvious deadlock hazards on the BEAM. See
.claude/guidelines/yex-guidelines.md §Transaction Deadlock Rulesbefore writing any server-side Y.Doc code.
Store Architecture (see .claude/guidelines/store-structure.md):
- SessionStore - Y.Doc, connection state, sync status
- WorkflowStore - Jobs, triggers, edges, positions (Y.Doc backed)
- AwarenessStore - User presence, cursors, selections
- SessionContextStore - User, project, permissions (Phoenix Channel)
- AdaptorStore / CredentialStore - Reference data
All stores use useSyncExternalStore + Immer and integrate with Redux DevTools
in development.
- PostgreSQL with Ecto ORM
- Dev:
postgres://postgres:postgres@localhost:5432/lightning_dev - Test:
lightning_test(auto-created by mix test) - Schemas alongside contexts in
lib/lightning/
- Use
{}brace syntax in HEEx templates warnings_as_errors: true- code must compile without warnings
- Props from LiveView are underscore_cased (not camelCase)
- Use
cn()utility from#/utils/cnfor conditional CSS classes - Use heroicons via Tailwind:
className="hero-check-micro h-4 w-4" - See
.claude/guidelines/toast-notifications.mdfor notification patterns
- Backend: ExUnit with ExMachina factories
- Frontend: Vitest (see
.claude/guidelines/testing-essentials.md) - E2E: Playwright (see
.claude/guidelines/e2e-testing.md) - Group related assertions; avoid micro-tests (one assertion per test)
- Target test file sizes: < 400 lines (see
.claude/guidelines/testing-essentials.md §Test file length)
External Node.js workers (@openfn/ws-worker) execute JavaScript jobs:
- WebSocket communication with JWT authentication
- Two-layer security: Worker Token + Run Token
- Generate keys:
mix lightning.gen_worker_keys - Required ENVs:
WORKER_RUNS_PRIVATE_KEY,WORKER_SECRET,WORKER_LIGHTNING_PUBLIC_KEY
- Phoenix 1.7 + LiveView, Ecto 3.13+, Oban (background jobs)
- Bodyguard (authorization), Cloak (encryption), Y_ex (Yjs bindings)
- React 18, @xyflow/react (DAG visualization), Monaco Editor
- Yjs + y-phoenix-channel (collaboration), Zustand + Immer (state)
- Tailwind CSS, Vitest, Playwright
mix lightning.gen_worker_keys # Generate worker authentication keys
mix lightning.gen_encryption_key # Generate credential encryption key
mix lightning.install_runtime # Install JavaScript runtime dependencies
mix lightning.install_schemas # Install JSON schemas for validation
mix lightning.install_adaptor_icons # Install adaptor iconsRun ./bin/bootstrap to sync dependencies and migrations.
Install Rust: brew install rust
Canonical roster. Command files (create-plan.md, implement-plan.md,
research-codebase.md) cross-ref this section rather than repeating it.
- codebase-locator - Find WHERE files and components live.
- codebase-analyzer - Document HOW specific code works (no critique).
- codebase-pattern-finder - Surface examples of existing patterns.
- context-locator - Discover
.context/documents about a topic. - context-analyzer - Extract key insights from a specific context doc.
- web-search-researcher - External documentation and references (on request).
- phoenix-elixir-expert - Elixir/Phoenix backend, Ecto, LiveView, Channels, OTP, ExUnit.
- react-collab-editor -
assets/js/collaborative-editor/, Y.Doc sync, Immer/useSyncExternalStore, TanStack Form, @xyflow/react. - react-test-specialist - React unit tests with Vitest; test quality and de-duplication.
- security-reviewer - Security review of pending changes.
- idea-machine - Brainstorming and framing shorthand.
Detailed guidelines in .claude/guidelines/:
store-structure.md- Collaborative editor store architecturetesting-essentials.md- Unit testing patterns and anti-patternse2e-testing.md- Playwright E2E testingyex-guidelines.md- Critical Yex (Yjs/Elixir) usage rulestoast-notifications.md- Notification patternsui-patterns.md- Button variants, disabled states, Tailwind conventions