# sahil-ladhania/preflight architecture

> Architecture diagram of the GitHub repository sahil-ladhania/preflight, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sahil-ladhania/preflight
- Repository: https://github.com/sahil-ladhania/preflight

## Overview

Preflight is a marketing-compliance workflow: teams capture intent, freeze applicable constraints, generate assets, and review a rule-by-rule evidence ledger. The graph includes the documented campaign stages and the sampled backend paths for campaign orchestration, judgement, rulebook changes, and workbench chat, alongside the rule engine and shared contracts. The README documents the product journey; source excerpts and the SOURCE INDEX support only the cited internal calls. Several UI/API and unsampled subsystem connections are therefore omitted.

Main entry points: [`apps/preflight-backend/src/features/findings/judge.service.ts`](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/findings/judge.service.ts) (Judgement evaluation), [`apps/preflight-backend/src/features/campaigns/campaigns.service.ts`](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/campaigns/campaigns.service.ts) (Campaign orchestration), [`apps/preflight-backend/src/features/campaigns/generate.service.ts`](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/campaigns/generate.service.ts) (Asset generation), [`apps/preflight-backend/src/features/workbench/workbench.service.ts`](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/workbench/workbench.service.ts) (Workbench chat)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Product experience"]
  node_workbench_ui["Workbench UI<br/>[Workbench.tsx]"]
  node_campaign_ui["Campaign UI<br/>[Campaign.tsx]"]
  node_overview_ui["Overview<br/>[Overview.tsx]"]
  node_rulebook_ui["Rulebook UI<br/>[Rulebook.tsx]"]
  node_web_app["Web app shell<br/>[App.tsx]"]
end

subgraph group_workflow["Campaign workflow"]
  node_api_app["API routing<br/>[app.ts]"]
  node_campaign_http["Campaign handlers"]
  node_campaign_service["Campaign orchestration"]
  node_brief_extract["Brief extraction<br/>[extract.service.ts]"]
  node_campaign_compile["Constraint compile<br/>[compile.service.ts]"]
  node_campaign_generate["Asset generation"]
end

subgraph group_governance["Review and governance"]
  node_findings["Findings and decisions"]
  node_judge["Judgement evaluation<br/>[judge.service.ts]"]
  node_rulebook_service["Rulebook management<br/>[rules.service.ts]"]
  node_change_log["Rule change record"]
end

subgraph group_runtime["Agent runtime"]
  node_chat_service["Workbench chat"]
  node_agent_runs["Agent run record"]
  node_gitagent["Agent invocation<br/>[gitagent.ts]"]
end

subgraph group_contracts["Rules and contracts"]
  node_rules_engine["Deterministic checks"]
  node_schemas["Shared API contracts<br/>[brief.ts]"]
end

node_team(("Marketing team"))
node_postgres[("PostgreSQL")]

node_team -->|"captures intent"| node_workbench_ui
node_team -->|"builds campaign"| node_campaign_ui
node_campaign_ui -.->|"requests stages"| node_campaign_http
node_workbench_ui -.->|"sends chat"| node_chat_service
node_rulebook_ui -.->|"manages rules"| node_rulebook_service
node_api_app -->|"mounts routes"| node_campaign_http
node_campaign_http -->|"invokes stages"| node_campaign_service
node_campaign_service -.->|"extracts brief"| node_brief_extract
node_campaign_service -.->|"freezes constraints"| node_campaign_compile
node_campaign_service -.->|"generates assets"| node_campaign_generate
node_campaign_generate -->|"checks copy"| node_rules_engine
node_campaign_generate -->|"evaluates findings"| node_judge
node_findings -->|"requests evaluation"| node_judge
node_judge -->|"records run"| node_agent_runs
node_judge -->|"invokes judge"| node_gitagent
node_chat_service -->|"records run"| node_agent_runs
node_chat_service -->|"invokes agent"| node_gitagent
node_rulebook_service -->|"records changes"| node_change_log
node_campaign_generate -.->|"persists assets"| node_postgres
node_agent_runs -->|"writes run rows"| node_postgres
node_judge -->|"reads and updates"| node_postgres
node_team -->|"reviews ledger"| node_overview_ui
node_team -->|"declares constraints"| node_rulebook_ui

click node_workbench_ui "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-web/src/features/workbench/Workbench.tsx"
click node_campaign_ui "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-web/src/features/campaign/Campaign.tsx"
click node_overview_ui "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-web/src/features/overview/Overview.tsx"
click node_rulebook_ui "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-web/src/features/rulebook/Rulebook.tsx"
click node_web_app "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-web/src/App.tsx"
click node_api_app "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/app.ts"
click node_campaign_http "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/campaigns/campaigns.controller.ts"
click node_campaign_service "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/campaigns/campaigns.service.ts"
click node_brief_extract "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/campaigns/extract.service.ts"
click node_campaign_compile "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/campaigns/compile.service.ts"
click node_campaign_generate "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/campaigns/generate.service.ts"
click node_rules_engine "https://github.com/sahil-ladhania/preflight/blob/main/packages/rules/src/run-deterministic.ts"
click node_findings "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/findings/findings.service.ts"
click node_judge "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/findings/judge.service.ts"
click node_rulebook_service "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/rules/rules.service.ts"
click node_change_log "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/rulebook-changes/rulebook-changes.service.ts"
click node_chat_service "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/workbench/workbench.service.ts"
click node_agent_runs "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/agent-runs/agent-runs.service.ts"
click node_gitagent "https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/lib/gitagent.ts"
click node_schemas "https://github.com/sahil-ladhania/preflight/blob/main/packages/schemas/src/brief.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_workbench_ui,node_campaign_ui,node_overview_ui,node_rulebook_ui,node_web_app toneBlue
class node_api_app,node_campaign_http,node_campaign_service,node_brief_extract,node_campaign_compile,node_campaign_generate,node_postgres toneAmber
class node_findings,node_judge,node_rulebook_service,node_change_log toneMint
class node_chat_service,node_agent_runs,node_gitagent toneRose
class node_rules_engine,node_schemas,node_team toneIndigo
```

## Components

### Product experience

- [Workbench UI](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-web/src/features/workbench/Workbench.tsx): `apps/preflight-web/src/features/workbench/Workbench.tsx`
- [Campaign UI](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-web/src/features/campaign/Campaign.tsx): `apps/preflight-web/src/features/campaign/Campaign.tsx`
- [Overview](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-web/src/features/overview/Overview.tsx): `apps/preflight-web/src/features/overview/Overview.tsx`
- [Rulebook UI](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-web/src/features/rulebook/Rulebook.tsx): `apps/preflight-web/src/features/rulebook/Rulebook.tsx`
- [Web app shell](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-web/src/App.tsx): `apps/preflight-web/src/App.tsx`

### Campaign workflow

- [API routing](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/app.ts): `apps/preflight-backend/src/app.ts`
- [Campaign handlers](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/campaigns/campaigns.controller.ts): `apps/preflight-backend/src/features/campaigns/campaigns.controller.ts`
- [Campaign orchestration](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/campaigns/campaigns.service.ts): `apps/preflight-backend/src/features/campaigns/campaigns.service.ts`
- [Brief extraction](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/campaigns/extract.service.ts): `apps/preflight-backend/src/features/campaigns/extract.service.ts`
- [Constraint compile](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/campaigns/compile.service.ts): `apps/preflight-backend/src/features/campaigns/compile.service.ts`
- [Asset generation](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/campaigns/generate.service.ts): `apps/preflight-backend/src/features/campaigns/generate.service.ts`

### Review and governance

- [Findings and decisions](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/findings/findings.service.ts): `apps/preflight-backend/src/features/findings/findings.service.ts`
- [Judgement evaluation](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/findings/judge.service.ts): `apps/preflight-backend/src/features/findings/judge.service.ts`
- [Rulebook management](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/rules/rules.service.ts): `apps/preflight-backend/src/features/rules/rules.service.ts`
- [Rule change record](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/rulebook-changes/rulebook-changes.service.ts): `apps/preflight-backend/src/features/rulebook-changes/rulebook-changes.service.ts`

### Agent runtime

- [Workbench chat](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/workbench/workbench.service.ts): `apps/preflight-backend/src/features/workbench/workbench.service.ts`
- [Agent run record](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/features/agent-runs/agent-runs.service.ts): `apps/preflight-backend/src/features/agent-runs/agent-runs.service.ts`
- [Agent invocation](https://github.com/sahil-ladhania/preflight/blob/main/apps/preflight-backend/src/lib/gitagent.ts): `apps/preflight-backend/src/lib/gitagent.ts`

### Rules and contracts

- [Deterministic checks](https://github.com/sahil-ladhania/preflight/blob/main/packages/rules/src/run-deterministic.ts): `packages/rules/src/run-deterministic.ts`
- [Shared API contracts](https://github.com/sahil-ladhania/preflight/blob/main/packages/schemas/src/brief.ts): `packages/schemas/src/brief.ts`

### Other components

- **Marketing team**
- **PostgreSQL**

## Connections

- Marketing team → Workbench UI: captures intent
- Marketing team → Campaign UI: builds campaign
- Campaign UI → Campaign handlers: requests stages
- Workbench UI → Workbench chat: sends chat
- Rulebook UI → Rulebook management: manages rules
- API routing → Campaign handlers: mounts routes (evidence: `apps/preflight-backend/src/app.ts`)
- Campaign handlers → Campaign orchestration: invokes stages (evidence: `apps/preflight-backend/src/features/campaigns/campaigns.controller.ts`)
- Campaign orchestration → Brief extraction: extracts brief
- Campaign orchestration → Constraint compile: freezes constraints
- Campaign orchestration → Asset generation: generates assets
- Asset generation → Deterministic checks: checks copy (evidence: `apps/preflight-backend/src/features/campaigns/generate.service.ts`)
- Asset generation → Judgement evaluation: evaluates findings (evidence: `apps/preflight-backend/src/features/campaigns/generate.service.ts`)
- Findings and decisions → Judgement evaluation: requests evaluation (evidence: `apps/preflight-backend/src/features/findings/findings.service.ts`)
- Judgement evaluation → Agent run record: records run (evidence: `apps/preflight-backend/src/features/findings/judge.service.ts`)
- Judgement evaluation → Agent invocation: invokes judge (evidence: `apps/preflight-backend/src/features/findings/judge.service.ts`)
- Workbench chat → Agent run record: records run (evidence: `apps/preflight-backend/src/features/workbench/workbench.service.ts`)
- Workbench chat → Agent invocation: invokes agent (evidence: `apps/preflight-backend/src/features/workbench/workbench.service.ts`)
- Rulebook management → Rule change record: records changes (evidence: `apps/preflight-backend/src/features/rules/rules.service.ts`)
- Asset generation → PostgreSQL: persists assets
- Agent run record → PostgreSQL: writes run rows (evidence: `apps/preflight-backend/src/features/agent-runs/agent-runs.service.ts`)
- Judgement evaluation → PostgreSQL: reads and updates (evidence: `apps/preflight-backend/src/features/findings/judge.service.ts`)
- Marketing team → Overview: reviews ledger
- Marketing team → Rulebook UI: declares constraints
