# codexhaven/codex-developer architecture

> Architecture diagram of the GitHub repository codexhaven/codex-developer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/codexhaven/codex-developer
- Repository: https://github.com/codexhaven/codex-developer

## Overview

1. **What this repository is**
   - This is not an application product; it is a **project-building orchestration tool** (“Codex Developer v12.6”) installed as a Hermes skill.
   - Its job is to take a natural-language request, research the target domain, generate or modify a project, validate it, optionally deploy it, and push it to GitHub.

2. **Primary runtime and interfaces**
   - The repo is mostly **Bash orchestration scripts** with a few **Python utilities**.
   - The main entry point is `listen.sh`, which runs in a Linux/macOS/Termux shell environment and depends on Git, Python 3.10+, and external tools like `hermes`, plus optional GitHub and Vercel credentials.

3. **Request intake and mode routing**
   - `listen.sh` is the front door: it classifies the user request into modes such as `NEW`, `GENERATE`, `EXISTING`, `REVIEW`, `CONTINUATION`, `CHECK`, `DEPLOY`, and `DIRECT`.
   - That mode decision determines whether the repo performs a full build, a targeted patch, a review-only scan, a continuation from queue state, or a deploy path.

4. **Build engine and phase-gated execution**
   - `runcycle.sh` is the central build engine.
   - It runs a **phase-gated loop** with retry limits, orchestrates build steps in order, and coordinates post-generation validation and push/deploy actions.
   - The README describes this as the core “factory” loop, with a maximum cycle count and phase progression enforced by the orchestrator.

5. **Research and architecture planning**
   - The `sandbox/recon.sh` and `sandbox/architect.sh` scripts form the **research/planning boundary**.
   - `recon.sh` performs domain-aware analysis and generates a project brain / contract plan; `architect.sh` enforces phase gates and validates that the generated plan matches expected build contracts.

6. **Hardening and code-shape enforcement**
   - `sandbox/strengthen.sh` is the hardening pass that re-checks generated files, import relationships, and structure.
   - Supporting utilities like `modules/enforce_path.py`, `modules/scan_deps.py`, `modules/map_project.py`, and `modules/import-check.sh` help ensure generated code stays within allowed paths and has consistent dependency wiring.

7. **Validation, contracts, and smoke checks**
   - Validation is a separate subsystem, not just a final test.
   - Scripts such as `modules/contract-import-check.sh`, `modules/symbol-check.sh`, `modules/failure-check.sh`, `modules/smoke-tester.sh`, and `modules/self-test.sh` verify that generated code matches expected function/import contracts and is actually runnable.
   - This is a key architectural boundary: generation is followed by structural checks before any deploy/push.

8. **Self-healing loop**
   - `modules/healer.sh` coordinates failure recovery through `healer_trace.sh`, `healer_analyze.sh`, `healer_fix.sh`, and `healer_reset.sh`.
   - The pipeline captures failure context, diagnoses likely root cause, applies a targeted repair, and resets state if needed.
   - This subsystem is triggered when builds repeatedly fail, so recovery is part of the normal architecture rather than an exception path.

9. **Stack-specific adapters for generated projects**
   - The repository includes stack plugins for different target project types: `modules/vibestack`, `modules/flaskstack`, and `modules/vanillastack`, each with an `apply.sh`.
   - These act as specialization layers so the factory can generate different kinds of projects without changing the core orchestration flow.
   - The README also mentions auto-detection and method adaptation, which means stack choice is a first-class routing concern.

10. **External services and delivery**
   - GitHub integration is handled by scripts like `modules/github-push.sh`, and deployment support is provided by `modules/vercel-deploy.sh`.
   - The repo expects credentials via environment variables such as `GITHUB_TOKEN`, `GITHUB_USER`, `VERCEL_TOKEN`, and `OPENROUTER_KEY`.
   - These services materially affect the architecture because the factory can automatically push and optionally deploy generated work.

11. **State, queues, and recovery boundaries**
   - Build state is persisted in `.codex/` files such as the build queue and completion markers, with lock handling via `/tmp` files.
   - This means the system is stateful across invocations: `listen.sh` can resume work via `CONTINUATION`, and recovery often starts by clearing queue/lock state.
   - The repo also includes `self-update.sh` and related maintenance scripts, showing that the factory can manage its own lifecycle.

12. **Knowledge assets and analysis helpers**
   - Files like `global-knowledge.jsonl`, `patterns.json`, `failure-patterns.json`, `project-templates.json`, and domain notes such as `domain_knowledge_healthcare_ehr.txt` provide prompt and pattern intelligence.
   - Python analyzers like `lesson-analyzer.py` and `opportunity-analyzer.py` process prior runs and failure lessons to improve future builds.
   - These are not app data stores; they are the factory’s “experience layer.”

13. **Testing and verification**
   - The repository includes a small test suite under `tests/`, including mocks and `tests/test_calc.py`, which likely exercises a simple utility path and verifies the tooling itself.
   - This supports the repo’s own reliability claims: the factory validates its core scripts before being trusted to generate or modify other projects.

14. **How the pieces fit together**
   - The high-level flow is: **request intake → mode selection → research/plan → phase-gated build → hardening/validation → self-heal if needed → push/deploy**.
   - The architectural boundary to emphasize is that this repo is a **meta-build system**: its outputs are external projects, while its own source tree is a coordinated orchestration and validation platform.

Main entry points: [`runcycle.sh`](https://github.com/codexhaven/codex-developer/blob/main/runcycle.sh) (Run Cycle), [`modules/healer.sh`](https://github.com/codexhaven/codex-developer/blob/main/modules/healer.sh) (Healer), [`sandbox/strengthen.sh`](https://github.com/codexhaven/codex-developer/blob/main/sandbox/strengthen.sh) (Strengthen), [`listen.sh`](https://github.com/codexhaven/codex-developer/blob/main/listen.sh) (Listen)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_orchestration["Orchestration"]
  node_listen_sh["Listen<br/>shell entry<br/>[listen.sh]"]
  node_runcycle_sh["Run Cycle<br/>build engine<br/>[runcycle.sh]"]
  node_kernel_sh["Kernel<br/>runtime core<br/>[kernel.sh]"]
end

subgraph group_group_planning["Planning"]
  node_recon_sh["Recon<br/>research pass<br/>[recon.sh]"]
  node_architect_sh["Architect<br/>phase gate<br/>[architect.sh]"]
  node_mirror_sh["Mirror<br/>planning helper<br/>[mirror.sh]"]
end

subgraph group_group_validation["Validation"]
  node_strengthen_sh["Strengthen<br/>hardening pass<br/>[strengthen.sh]"]
  node_contract_check["Contract Check<br/>validator"]
  node_symbol_check["Symbol Check<br/>validator<br/>[symbol-check.sh]"]
  node_smoke_tester["Smoke Test<br/>runnable check<br/>[smoke-tester.sh]"]
  node_self_test["Self Test<br/>tooling test<br/>[self-test.sh]"]
  node_healer_sh["Healer<br/>recovery coordinator<br/>[healer.sh]"]
  node_healer_trace["Trace<br/>failure capture<br/>[healer_trace.sh]"]
  node_healer_analyze["Analyze<br/>root cause<br/>[healer_analyze.sh]"]
  node_healer_fix["Fix<br/>targeted repair<br/>[healer_fix.sh]"]
  node_healer_reset["Reset<br/>[healer_reset.sh]"]
end

subgraph group_group_adapters["Adapters"]
  node_vibestack["Vibe Stack<br/>stack adapter<br/>[apply.sh]"]
  node_flaskstack["Flask Stack<br/>stack adapter<br/>[apply.sh]"]
  node_vanillastack["Vanilla Stack<br/>stack adapter<br/>[apply.sh]"]
end

subgraph group_group_delivery["Delivery & State"]
  node_github_push["GitHub Push<br/>delivery integration<br/>[github-push.sh]"]
  node_vercel_deploy["Vercel Deploy<br/>deployment integration<br/>[vercel-deploy.sh]"]
  node_review_queue["Review Queue<br/>state bridge<br/>[review-to-queue.sh]"]
  node_codex_state[("Codex State<br/>persistent state<br/>[.codex]")]
  node_knowledge_assets["Knowledge<br/>experience layer"]
  node_lesson_analyzer["Lessons<br/>analysis utility<br/>[lesson-analyzer.py]"]
  node_opportunity_analyzer["Opportunities<br/>analysis utility"]
end

node_listen_sh -->|"route mode"| node_runcycle_sh
node_listen_sh -->|"continuation"| node_review_queue
node_runcycle_sh -->|"plan"| node_recon_sh
node_runcycle_sh -->|"gate"| node_architect_sh
node_runcycle_sh -->|"harden"| node_strengthen_sh
node_runcycle_sh -->|"recover"| node_healer_sh
node_recon_sh -->|"consult"| node_knowledge_assets
node_architect_sh -->|"validate against"| node_knowledge_assets
node_strengthen_sh -->|"verify"| node_contract_check
node_strengthen_sh -->|"verify"| node_symbol_check
node_strengthen_sh -->|"exercise"| node_smoke_tester
node_self_test -.->|"trust"| node_listen_sh
node_healer_sh -->|"capture"| node_healer_trace
node_healer_sh -->|"diagnose"| node_healer_analyze
node_healer_sh -->|"repair"| node_healer_fix
node_healer_sh -->|"reset"| node_healer_reset
node_runcycle_sh -->|"specialize"| node_vibestack
node_runcycle_sh -->|"specialize"| node_flaskstack
node_runcycle_sh -->|"specialize"| node_vanillastack
node_runcycle_sh -->|"push"| node_github_push
node_runcycle_sh -->|"deploy"| node_vercel_deploy
node_review_queue -->|"persist"| node_codex_state
node_listen_sh -->|"resume"| node_codex_state
node_lesson_analyzer -->|"update"| node_knowledge_assets
node_opportunity_analyzer -->|"update"| node_knowledge_assets

click node_listen_sh "https://github.com/codexhaven/codex-developer/blob/main/listen.sh"
click node_runcycle_sh "https://github.com/codexhaven/codex-developer/blob/main/runcycle.sh"
click node_kernel_sh "https://github.com/codexhaven/codex-developer/blob/main/kernel.sh"
click node_recon_sh "https://github.com/codexhaven/codex-developer/blob/main/sandbox/recon.sh"
click node_architect_sh "https://github.com/codexhaven/codex-developer/blob/main/sandbox/architect.sh"
click node_mirror_sh "https://github.com/codexhaven/codex-developer/blob/main/sandbox/mirror.sh"
click node_strengthen_sh "https://github.com/codexhaven/codex-developer/blob/main/sandbox/strengthen.sh"
click node_contract_check "https://github.com/codexhaven/codex-developer/blob/main/modules/contract-import-check.sh"
click node_symbol_check "https://github.com/codexhaven/codex-developer/blob/main/modules/symbol-check.sh"
click node_smoke_tester "https://github.com/codexhaven/codex-developer/blob/main/modules/smoke-tester.sh"
click node_self_test "https://github.com/codexhaven/codex-developer/blob/main/modules/self-test.sh"
click node_healer_sh "https://github.com/codexhaven/codex-developer/blob/main/modules/healer.sh"
click node_healer_trace "https://github.com/codexhaven/codex-developer/blob/main/modules/healer_trace.sh"
click node_healer_analyze "https://github.com/codexhaven/codex-developer/blob/main/modules/healer_analyze.sh"
click node_healer_fix "https://github.com/codexhaven/codex-developer/blob/main/modules/healer_fix.sh"
click node_healer_reset "https://github.com/codexhaven/codex-developer/blob/main/modules/healer_reset.sh"
click node_vibestack "https://github.com/codexhaven/codex-developer/blob/main/modules/vibestack/apply.sh"
click node_flaskstack "https://github.com/codexhaven/codex-developer/blob/main/modules/flaskstack/apply.sh"
click node_vanillastack "https://github.com/codexhaven/codex-developer/blob/main/modules/vanillastack/apply.sh"
click node_github_push "https://github.com/codexhaven/codex-developer/blob/main/modules/github-push.sh"
click node_vercel_deploy "https://github.com/codexhaven/codex-developer/blob/main/modules/vercel-deploy.sh"
click node_review_queue "https://github.com/codexhaven/codex-developer/blob/main/modules/review-to-queue.sh"
click node_codex_state "https://github.com/codexhaven/codex-developer/blob/main/.codex"
click node_knowledge_assets "https://github.com/codexhaven/codex-developer/blob/main/global-knowledge.jsonl"
click node_lesson_analyzer "https://github.com/codexhaven/codex-developer/blob/main/lesson-analyzer.py"
click node_opportunity_analyzer "https://github.com/codexhaven/codex-developer/blob/main/opportunity-analyzer.py"

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_listen_sh,node_runcycle_sh,node_kernel_sh toneBlue
class node_recon_sh,node_architect_sh,node_mirror_sh toneAmber
class node_strengthen_sh,node_contract_check,node_symbol_check,node_smoke_tester,node_self_test,node_healer_sh,node_healer_trace,node_healer_analyze,node_healer_fix,node_healer_reset toneMint
class node_vibestack,node_flaskstack,node_vanillastack toneRose
class node_github_push,node_vercel_deploy,node_review_queue,node_codex_state,node_knowledge_assets,node_lesson_analyzer,node_opportunity_analyzer toneIndigo
```

## Components

### Orchestration

Front door and build-cycle control for the factory runtime.

- [Listen](https://github.com/codexhaven/codex-developer/blob/main/listen.sh): shell entry · Main request intake and mode router. · `listen.sh`
- [Run Cycle](https://github.com/codexhaven/codex-developer/blob/main/runcycle.sh): build engine · Phase-gated orchestration loop for generation, validation, and delivery. · `runcycle.sh`
- [Kernel](https://github.com/codexhaven/codex-developer/blob/main/kernel.sh): runtime core · Shared execution/kernel helpers used by the orchestration scripts. · `kernel.sh`

### Planning

Research, architecture, and project-shaping stages before generation.

- [Recon](https://github.com/codexhaven/codex-developer/blob/main/sandbox/recon.sh): research pass · Domain analysis and project-brain generation. · `sandbox/recon.sh`
- [Architect](https://github.com/codexhaven/codex-developer/blob/main/sandbox/architect.sh): phase gate · Validates plans against build contracts and stage rules. · `sandbox/architect.sh`
- [Mirror](https://github.com/codexhaven/codex-developer/blob/main/sandbox/mirror.sh): planning helper · Auxiliary sandbox helper for reflecting or shaping generated context. · `sandbox/mirror.sh`

### Validation

Hardening, contract checks, smoke tests, and self-healing.

- [Strengthen](https://github.com/codexhaven/codex-developer/blob/main/sandbox/strengthen.sh): hardening pass · Re-checks generated files, imports, and structure. · `sandbox/strengthen.sh`
- [Contract Check](https://github.com/codexhaven/codex-developer/blob/main/modules/contract-import-check.sh): validator · Checks generated code against expected import/function contracts. · `modules/contract-import-check.sh`
- [Symbol Check](https://github.com/codexhaven/codex-developer/blob/main/modules/symbol-check.sh): validator · Verifies exported symbols and structural expectations. · `modules/symbol-check.sh`
- [Smoke Test](https://github.com/codexhaven/codex-developer/blob/main/modules/smoke-tester.sh): runnable check · Runs basic execution checks against the generated project. · `modules/smoke-tester.sh`
- [Self Test](https://github.com/codexhaven/codex-developer/blob/main/modules/self-test.sh): tooling test · Validates the factory's own scripts and support paths. · `modules/self-test.sh`
- [Healer](https://github.com/codexhaven/codex-developer/blob/main/modules/healer.sh): recovery coordinator · Coordinates failure tracing, diagnosis, repair, and reset. · `modules/healer.sh`
- [Trace](https://github.com/codexhaven/codex-developer/blob/main/modules/healer_trace.sh): failure capture · Captures failure context for recovery analysis. · `modules/healer_trace.sh`
- [Analyze](https://github.com/codexhaven/codex-developer/blob/main/modules/healer_analyze.sh): root cause · Infers likely causes from failure traces and run history. · `modules/healer_analyze.sh`
- [Fix](https://github.com/codexhaven/codex-developer/blob/main/modules/healer_fix.sh): targeted repair · Applies focused repairs to failing generated work. · `modules/healer_fix.sh`
- [Reset](https://github.com/codexhaven/codex-developer/blob/main/modules/healer_reset.sh): state reset · Clears or rewinds state after repeated failure. · `modules/healer_reset.sh`

### Adapters

Stack-specific specialization layers for generated projects.

- [Vibe Stack](https://github.com/codexhaven/codex-developer/blob/main/modules/vibestack/apply.sh): stack adapter · Specialized adapter for one target project style. · `modules/vibestack/apply.sh`
- [Flask Stack](https://github.com/codexhaven/codex-developer/blob/main/modules/flaskstack/apply.sh): stack adapter · Specialized adapter for Flask-style target projects. · `modules/flaskstack/apply.sh`
- [Vanilla Stack](https://github.com/codexhaven/codex-developer/blob/main/modules/vanillastack/apply.sh): stack adapter · Specialized adapter for minimal or framework-light projects. · `modules/vanillastack/apply.sh`

### Delivery & State

External push/deploy integrations, persistent state, and knowledge assets.

- [GitHub Push](https://github.com/codexhaven/codex-developer/blob/main/modules/github-push.sh): delivery integration · Pushes generated work to GitHub. · `modules/github-push.sh`
- [Vercel Deploy](https://github.com/codexhaven/codex-developer/blob/main/modules/vercel-deploy.sh): deployment integration · Deploys eligible generated projects to Vercel. · `modules/vercel-deploy.sh`
- [Review Queue](https://github.com/codexhaven/codex-developer/blob/main/modules/review-to-queue.sh): state bridge · Moves review output into queued continuation state. · `modules/review-to-queue.sh`
- [Codex State](https://github.com/codexhaven/codex-developer/blob/main/.codex): persistent state · Queue, completion markers, and resume state under .codex/. · `.codex`
- [Knowledge](https://github.com/codexhaven/codex-developer/blob/main/global-knowledge.jsonl): experience layer · Patterns, lessons, templates, and domain notes used to guide future runs. · `global-knowledge.jsonl`
- [Lessons](https://github.com/codexhaven/codex-developer/blob/main/lesson-analyzer.py): analysis utility · Extracts lessons from prior runs and failures. · `lesson-analyzer.py`
- [Opportunities](https://github.com/codexhaven/codex-developer/blob/main/opportunity-analyzer.py): analysis utility · Finds improvement opportunities from run history. · `opportunity-analyzer.py`

## Connections

- Listen → Run Cycle: route mode · Request intake selects the build path and hands control to the cycle engine.
- Listen → Review Queue: continuation · Continuation and review modes can enqueue work for later execution.
- Run Cycle → Recon: plan · The build cycle begins with research and project shaping when needed.
- Run Cycle → Architect: gate · Plans are checked against phase and contract rules before generation proceeds.
- Run Cycle → Strengthen: harden · Generated output is re-scanned for path and shape issues.
- Run Cycle → Healer: recover · Repeated failures trigger recovery instead of immediate termination.
- Recon → Knowledge: consult · Research uses repository knowledge, patterns, and domain notes.
- Architect → Knowledge: validate against · Architecture decisions are compared with templates and known contracts.
- Strengthen → Contract Check: verify · Hardening runs contract-level checks on generated files.
- Strengthen → Symbol Check: verify · Hardening also checks symbol and structure expectations.
- Strengthen → Smoke Test: exercise · Runnable smoke tests confirm the project can execute.
- Self Test → Listen: trust · Factory self-tests validate the core orchestration scripts.
- Healer → Trace: capture · Recovery starts by collecting failure context.
- Healer → Analyze: diagnose · Captured traces are analyzed for likely root cause.
- Healer → Fix: repair · Targeted fixes are applied after diagnosis.
- Healer → Reset: reset · State is cleared or rewound when recovery needs a fresh start.
- Run Cycle → Vibe Stack: specialize · Stack detection can route generation through a Vibestack adapter.
- Run Cycle → Flask Stack: specialize · Stack detection can route generation through a Flask adapter.
- Run Cycle → Vanilla Stack: specialize · Stack detection can route generation through a Vanilla adapter.
- Run Cycle → GitHub Push: push · Successful builds can be published to GitHub.
- Run Cycle → Vercel Deploy: deploy · Deployable targets can be sent to Vercel.
- Review Queue → Codex State: persist · Queue state and resume markers are stored in .codex/.
- Listen → Codex State: resume · The front door can resume work from persisted state.
- Lessons → Knowledge: update · Lessons extracted from runs feed the experience layer.
- Opportunities → Knowledge: update · Opportunity analysis informs future build decisions.
