# talibilat/zentra architecture

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

- Interactive diagram: https://gitdiagram.com/talibilat/zentra
- Repository: https://github.com/talibilat/zentra

## Overview

#### Purpose and entry points
Zentra is a local-first TypeScript orchestration kernel for bounded software-development tasks against configured Git projects. It owns lifecycle, durable evidence, recovery, isolated worktrees, validation, review, and serialized integration; projects retain source, commands, and policy. CLI entry point: `src/cli/main.ts`; public library surface: `src/index.ts`. Primary commands include deterministic `task run`, installed `milestone run`, configuration validation, status, recovery, and capsule conformance.

#### Durable domain model and state
Append-only SQLite events are the system of record; projections rebuild task/milestone state and support read-only recovery classification. Contracts define typed identities, task/milestone state, artifacts, authority, costs, and uncertain effects. Core paths: `src/journal/sqlite-journal.ts`, `src/journal/projecting-journal.ts`, `src/contracts/event.ts`, `src/tasks/task-projection.ts`, `src/milestones/milestone-projection.ts`. Agent Tail is a non-authoritative JSONL projection for live/saved observability: `src/observability/agent-tail-file-sink.ts`.

#### Milestone admission, policy, and replanning
Milestone registration binds plan, security/model policy, ownership, budgets, capabilities, and stop conditions before execution. Admission is fail-closed and records readiness or durable attention; plan replacement/revision is constrained by identity, evidence, and execution state. Core paths: `src/milestones/milestone-registry.ts`, `src/milestones/plan-readiness.ts`, `src/milestones/path-ownership.ts`, `src/policy/model-sheet.ts`, `src/policy/security-sheet.ts`.

#### Orchestration workflow
The installed workflow is fixed planner → researcher → host OpenCode writer → independent reviewer → validation → disposable candidate integration. Schedulers coordinate one bounded local workflow, resource governors constrain writer execution, and recovery refuses automatic retries after uncertain effects. Core paths: `src/orchestration/multi-agent-milestone.ts`, `src/orchestration/multi-writer-scheduler.ts`, `src/orchestration/writer-worktree-capsule.ts`, `src/orchestration/recovery.ts`, `src/reviews/review-gate.ts`. The deterministic tracer-bullet path remains a separate conformance workflow: `src/orchestration/tracer-bullet.ts`.

#### Workspace, validation, and integration boundaries
Each writer receives an isolated Git worktree with owned-file restrictions. Validations execute configured direct argument arrays under bounded timeouts; successful work is reviewed and integrated through serialized branch preparation/queue/lease control. Important paths: `src/workspaces/worktree-manager.ts`, `src/workspaces/git-client.ts`, `src/capabilities/validation-runner.ts`, `src/integration/integration-queue.ts`, `src/orchestration/integration-branch-preparation.ts`. Git mutations are guarded by canonical repository identity and durable intent/effect evidence.

#### Agents, capsules, and model transport
Read-only planner/researcher/reviewer roles run attested OpenCode in short-lived Docker capsules over sanitized repository views; model turns cross to a trusted host broker. The writer instead runs the operator-attested OpenCode executable on the host with minimal environment and explicit worktree authority. Core paths: `src/agents/opencode-read-only-program.ts`, `src/capsule/docker-capsule.ts`, `src/capsule/opencode-read-only-capsule.ts`, `src/providers/azure-openai-model-broker.ts`, `src/agents/opencode-worker-event-adapter.ts`. Azure OpenAI is the supported provider, with strict endpoint/DNS/TLS/SSE/budget controls; Docker and Git are material runtime dependencies.

#### External-effect and release boundaries
GitHub operations are brokered, grant-bound, serialized, and always treated as uncertain until separate reconciliation; credentials stay in host environment boundaries. Local release preparation is optional, runs trusted project commands in an exact-commit worktree, and stops before remote release actions. Core paths: `src/capsule/github-broker.ts`, `src/integration/integration-lease.ts`, `src/release/local-release-coordinator.ts`, `src/release/local-release-runner.ts`. The MVP supports one user and one local machine, specifically macOS arm64 with Node 24–26; it is not a distributed, multi-tenant, or hostile-repository sandbox.

Main entry points: [`src/orchestration/multi-agent-milestone.ts`](https://github.com/talibilat/zentra/blob/main/src/orchestration/multi-agent-milestone.ts) (Installed milestone workflow), [`src/milestones/milestone-registry.ts`](https://github.com/talibilat/zentra/blob/main/src/milestones/milestone-registry.ts) (Milestone admission), [`src/journal/projecting-journal.ts`](https://github.com/talibilat/zentra/blob/main/src/journal/projecting-journal.ts) (Projecting journal), [`src/journal/sqlite-journal.ts`](https://github.com/talibilat/zentra/blob/main/src/journal/sqlite-journal.ts) (SQLite event journal)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry Surfaces"]
  node_cli["CLI commands<br/>TypeScript CLI<br/>[main.ts]"]
  node_library["Public library<br/>TypeScript API<br/>[index.ts]"]
end

subgraph group_state["Durable State &amp; Policy"]
  node_journal[("SQLite event journal<br/>event store<br/>[sqlite-journal.ts]")]
  node_projecting_journal["Projecting journal<br/>projection service"]
  node_task_projection["Task projection<br/>task read model<br/>[task-projection.ts]"]
  node_milestone_projection["Milestone projection<br/>milestone read model"]
  node_agent_tail["Agent Tail<br/>JSONL observability"]
  node_milestone_registry["Milestone admission<br/>registry"]
  node_plan_readiness{{"Plan readiness<br/>admission gate<br/>[plan-readiness.ts]"}}
  node_ownership["Path ownership<br/>policy enforcement<br/>[path-ownership.ts]"]
  node_policy["Security &amp; model policy<br/>policy sheets<br/>[security-sheet.ts]"]
end

subgraph group_workflow["Orchestration"]
  node_milestone_workflow["Installed milestone workflow<br/>orchestrator"]
  node_writer_scheduler["Writer scheduler<br/>resource governor"]
  node_recovery{{"Recovery controller<br/>recovery policy<br/>[recovery.ts]"}}
  node_tracer_bullet["Tracer-bullet workflow<br/>conformance workflow<br/>[tracer-bullet.ts]"]
  node_writer_capsule["Host writer capsule<br/>worktree writer"]
  node_review_gate{{"Review gate<br/>independent review<br/>[review-gate.ts]"}}
end

subgraph group_execution["Execution Boundaries"]
  node_read_only_agents["Read-only OpenCode roles<br/>planner/researcher/reviewer"]
  node_docker_capsules["Docker read-only capsules<br/>isolated runtime"]
  node_model_broker["Azure OpenAI broker<br/>trusted model transport"]
  node_worktrees["Git worktree manager<br/>workspace isolation"]
  node_validation["Validation runner<br/>command executor"]
end

subgraph group_delivery["Integration &amp; Release"]
  node_integration["Integration queue &amp; lease<br/>serialized integration"]
  node_github_broker["GitHub broker<br/>external-effect broker<br/>[github-broker.ts]"]
  node_release["Local release coordinator<br/>optional release flow"]
end

node_cli -->|"registers and admits"| node_milestone_registry
node_library -->|"exposes"| node_milestone_workflow
node_milestone_registry -->|"checks"| node_plan_readiness
node_milestone_registry -->|"binds"| node_ownership
node_milestone_registry -->|"applies"| node_policy
node_milestone_registry -->|"records admission"| node_journal
node_journal -->|"projects events"| node_projecting_journal
node_projecting_journal -->|"builds"| node_task_projection
node_projecting_journal -->|"builds"| node_milestone_projection
node_projecting_journal -.->|"publishes"| node_agent_tail
node_cli -->|"runs milestone"| node_milestone_workflow
node_cli -->|"runs deterministic task"| node_tracer_bullet
node_milestone_workflow -->|"coordinates"| node_writer_scheduler
node_milestone_workflow -->|"plans, researches, reviews"| node_read_only_agents
node_read_only_agents -->|"runs in"| node_docker_capsules
node_docker_capsules -->|"model turns"| node_model_broker
node_writer_scheduler -->|"authorizes writer"| node_writer_capsule
node_writer_capsule -->|"writes isolated workspace"| node_worktrees
node_worktrees -->|"validates candidate"| node_validation
node_validation -->|"successful candidate"| node_review_gate
node_review_gate -->|"approved candidate"| node_integration
node_integration -->|"brokers GitHub effects"| node_github_broker
node_integration -->|"exact commit"| node_release
node_recovery -->|"classifies state"| node_milestone_projection
node_recovery -->|"inspects effects"| node_journal
node_milestone_workflow -.->|"uncertain effects"| node_recovery
node_milestone_workflow -->|"records lifecycle"| node_journal

click node_cli "https://github.com/talibilat/zentra/blob/main/src/cli/main.ts"
click node_library "https://github.com/talibilat/zentra/blob/main/src/index.ts"
click node_journal "https://github.com/talibilat/zentra/blob/main/src/journal/sqlite-journal.ts"
click node_projecting_journal "https://github.com/talibilat/zentra/blob/main/src/journal/projecting-journal.ts"
click node_task_projection "https://github.com/talibilat/zentra/blob/main/src/tasks/task-projection.ts"
click node_milestone_projection "https://github.com/talibilat/zentra/blob/main/src/milestones/milestone-projection.ts"
click node_agent_tail "https://github.com/talibilat/zentra/blob/main/src/observability/agent-tail-file-sink.ts"
click node_milestone_registry "https://github.com/talibilat/zentra/blob/main/src/milestones/milestone-registry.ts"
click node_plan_readiness "https://github.com/talibilat/zentra/blob/main/src/milestones/plan-readiness.ts"
click node_ownership "https://github.com/talibilat/zentra/blob/main/src/milestones/path-ownership.ts"
click node_policy "https://github.com/talibilat/zentra/blob/main/src/policy/security-sheet.ts"
click node_milestone_workflow "https://github.com/talibilat/zentra/blob/main/src/orchestration/multi-agent-milestone.ts"
click node_writer_scheduler "https://github.com/talibilat/zentra/blob/main/src/orchestration/multi-writer-scheduler.ts"
click node_recovery "https://github.com/talibilat/zentra/blob/main/src/orchestration/recovery.ts"
click node_tracer_bullet "https://github.com/talibilat/zentra/blob/main/src/orchestration/tracer-bullet.ts"
click node_read_only_agents "https://github.com/talibilat/zentra/blob/main/src/agents/opencode-read-only-program.ts"
click node_docker_capsules "https://github.com/talibilat/zentra/blob/main/src/capsule/opencode-read-only-capsule.ts"
click node_model_broker "https://github.com/talibilat/zentra/blob/main/src/providers/azure-openai-model-broker.ts"
click node_writer_capsule "https://github.com/talibilat/zentra/blob/main/src/orchestration/writer-worktree-capsule.ts"
click node_worktrees "https://github.com/talibilat/zentra/blob/main/src/workspaces/worktree-manager.ts"
click node_validation "https://github.com/talibilat/zentra/blob/main/src/capabilities/validation-runner.ts"
click node_review_gate "https://github.com/talibilat/zentra/blob/main/src/reviews/review-gate.ts"
click node_integration "https://github.com/talibilat/zentra/blob/main/src/integration/integration-queue.ts"
click node_github_broker "https://github.com/talibilat/zentra/blob/main/src/capsule/github-broker.ts"
click node_release "https://github.com/talibilat/zentra/blob/main/src/release/local-release-coordinator.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_cli,node_library toneBlue
class node_journal,node_projecting_journal,node_task_projection,node_milestone_projection,node_agent_tail,node_milestone_registry,node_plan_readiness,node_ownership,node_policy toneAmber
class node_milestone_workflow,node_writer_scheduler,node_recovery,node_tracer_bullet,node_writer_capsule,node_review_gate toneMint
class node_read_only_agents,node_docker_capsules,node_model_broker,node_worktrees,node_validation toneRose
class node_integration,node_github_broker,node_release toneIndigo
```

## Components

### Entry Surfaces

- [CLI commands](https://github.com/talibilat/zentra/blob/main/src/cli/main.ts): TypeScript CLI · Run, recovery, status, configuration, and conformance commands. · `src/cli/main.ts`
- [Public library](https://github.com/talibilat/zentra/blob/main/src/index.ts): TypeScript API · `src/index.ts`

### Durable State & Policy

- [SQLite event journal](https://github.com/talibilat/zentra/blob/main/src/journal/sqlite-journal.ts): event store · Append-only system of record for durable facts and effects. · `src/journal/sqlite-journal.ts`
- [Projecting journal](https://github.com/talibilat/zentra/blob/main/src/journal/projecting-journal.ts): projection service · `src/journal/projecting-journal.ts`
- [Task projection](https://github.com/talibilat/zentra/blob/main/src/tasks/task-projection.ts): task read model · `src/tasks/task-projection.ts`
- [Milestone projection](https://github.com/talibilat/zentra/blob/main/src/milestones/milestone-projection.ts): milestone read model · `src/milestones/milestone-projection.ts`
- [Agent Tail](https://github.com/talibilat/zentra/blob/main/src/observability/agent-tail-file-sink.ts): JSONL observability · Non-authoritative live and saved agent-event projection. · `src/observability/agent-tail-file-sink.ts`
- [Milestone admission](https://github.com/talibilat/zentra/blob/main/src/milestones/milestone-registry.ts): registry · Binds plans, budgets, capabilities, ownership, and stop conditions. · `src/milestones/milestone-registry.ts`
- [Plan readiness](https://github.com/talibilat/zentra/blob/main/src/milestones/plan-readiness.ts): admission gate · Fail-closed readiness and durable-attention decisions. · `src/milestones/plan-readiness.ts`
- [Path ownership](https://github.com/talibilat/zentra/blob/main/src/milestones/path-ownership.ts): policy enforcement · `src/milestones/path-ownership.ts`
- [Security & model policy](https://github.com/talibilat/zentra/blob/main/src/policy/security-sheet.ts): policy sheets · `src/policy/security-sheet.ts`

### Orchestration

- [Installed milestone workflow](https://github.com/talibilat/zentra/blob/main/src/orchestration/multi-agent-milestone.ts): orchestrator · Fixed planner → researcher → writer → reviewer → validation → candidate integration flow. · `src/orchestration/multi-agent-milestone.ts`
- [Writer scheduler](https://github.com/talibilat/zentra/blob/main/src/orchestration/multi-writer-scheduler.ts): resource governor · Coordinates one bounded local writer workflow. · `src/orchestration/multi-writer-scheduler.ts`
- [Recovery controller](https://github.com/talibilat/zentra/blob/main/src/orchestration/recovery.ts): recovery policy · Refuses automatic retry after uncertain effects. · `src/orchestration/recovery.ts`
- [Tracer-bullet workflow](https://github.com/talibilat/zentra/blob/main/src/orchestration/tracer-bullet.ts): conformance workflow · Separate deterministic task-run path. · `src/orchestration/tracer-bullet.ts`
- [Host writer capsule](https://github.com/talibilat/zentra/blob/main/src/orchestration/writer-worktree-capsule.ts): worktree writer · Operator-attested OpenCode with minimal environment and explicit authority. · `src/orchestration/writer-worktree-capsule.ts`
- [Review gate](https://github.com/talibilat/zentra/blob/main/src/reviews/review-gate.ts): independent review · `src/reviews/review-gate.ts`

### Execution Boundaries

- [Read-only OpenCode roles](https://github.com/talibilat/zentra/blob/main/src/agents/opencode-read-only-program.ts): planner/researcher/reviewer · Attested roles operating over sanitized repository views. · `src/agents/opencode-read-only-program.ts`
- [Docker read-only capsules](https://github.com/talibilat/zentra/blob/main/src/capsule/opencode-read-only-capsule.ts): isolated runtime · `src/capsule/opencode-read-only-capsule.ts`
- [Azure OpenAI broker](https://github.com/talibilat/zentra/blob/main/src/providers/azure-openai-model-broker.ts): trusted model transport · Enforces endpoint, DNS, TLS, SSE, and budget controls. · `src/providers/azure-openai-model-broker.ts`
- [Git worktree manager](https://github.com/talibilat/zentra/blob/main/src/workspaces/worktree-manager.ts): workspace isolation · Creates isolated worktrees and enforces owned-file restrictions. · `src/workspaces/worktree-manager.ts`
- [Validation runner](https://github.com/talibilat/zentra/blob/main/src/capabilities/validation-runner.ts): command executor · Runs configured direct argument arrays with bounded timeouts. · `src/capabilities/validation-runner.ts`

### Integration & Release

- [Integration queue & lease](https://github.com/talibilat/zentra/blob/main/src/integration/integration-queue.ts): serialized integration · Prepares candidate branches and controls serialized integration authority. · `src/integration/integration-queue.ts`
- [GitHub broker](https://github.com/talibilat/zentra/blob/main/src/capsule/github-broker.ts): external-effect broker · Grant-bound operations remain uncertain until reconciled. · `src/capsule/github-broker.ts`
- [Local release coordinator](https://github.com/talibilat/zentra/blob/main/src/release/local-release-coordinator.ts): optional release flow · Runs trusted commands in an exact-commit worktree; stops before remote release. · `src/release/local-release-coordinator.ts`

## Connections

- CLI commands → Milestone admission: registers and admits
- Public library → Installed milestone workflow: exposes
- Milestone admission → Plan readiness: checks
- Milestone admission → Path ownership: binds
- Milestone admission → Security & model policy: applies
- Milestone admission → SQLite event journal: records admission
- SQLite event journal → Projecting journal: projects events
- Projecting journal → Task projection: builds
- Projecting journal → Milestone projection: builds
- Projecting journal → Agent Tail: publishes
- CLI commands → Installed milestone workflow: runs milestone
- CLI commands → Tracer-bullet workflow: runs deterministic task
- Installed milestone workflow → Writer scheduler: coordinates
- Installed milestone workflow → Read-only OpenCode roles: plans, researches, reviews
- Read-only OpenCode roles → Docker read-only capsules: runs in
- Docker read-only capsules → Azure OpenAI broker: model turns
- Writer scheduler → Host writer capsule: authorizes writer
- Host writer capsule → Git worktree manager: writes isolated workspace
- Git worktree manager → Validation runner: validates candidate
- Validation runner → Review gate: successful candidate
- Review gate → Integration queue & lease: approved candidate
- Integration queue & lease → GitHub broker: brokers GitHub effects
- Integration queue & lease → Local release coordinator: exact commit
- Recovery controller → Milestone projection: classifies state
- Recovery controller → SQLite event journal: inspects effects
- Installed milestone workflow → Recovery controller: uncertain effects
- Installed milestone workflow → SQLite event journal: records lifecycle
