# d-engahmed/ancient architecture

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

- Interactive diagram: https://gitdiagram.com/d-engahmed/ancient
- Repository: https://github.com/d-engahmed/ancient

## Overview

ANCIENT is a self-hosted, terminal-native AI coding agent. Its principal documented workflow is a user submitting a coding task in the CLI, the server accepting execution requests, and execution results being presented in the terminal; the unified execution engine provides the main internal layer. The README also advertises agent teams, model fallback, checkpoints, MCP, and pipeline execution. Evidence is mixed: several runtime files are sampled, but most server routes and persistence paths are not, so those links are shown only where the README documents them.

Main entry points: [`packages/execution/src/engine.ts`](https://github.com/d-engahmed/ancient/blob/main/packages/execution/src/engine.ts) (Unified engine), [`packages/server/src/index.ts`](https://github.com/d-engahmed/ancient/blob/main/packages/server/src/index.ts) (HTTP API), [`packages/agent/src/runtime/engine.ts`](https://github.com/d-engahmed/ancient/blob/main/packages/agent/src/runtime/engine.ts) (Team orchestrator), [`packages/cli/src/lib/api-client.ts`](https://github.com/d-engahmed/ancient/blob/main/packages/cli/src/lib/api-client.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Terminal experience"]
  node_cli_session["Session console<br/>[session.tsx]"]
  node_cli_input["Task input<br/>[input-bar.tsx]"]
  node_cli_hook["Execution hook<br/>[use-execution.ts]"]
  node_cli_api["API client<br/>[api-client.ts]"]
  node_cli_stream["Event stream"]
end

subgraph group_execution["Execution engine"]
  node_engine["Unified engine<br/>[engine.ts]"]
  node_context["Context runtime<br/>[context.ts]"]
  node_profiler["Task profiler<br/>[profiler.ts]"]
  node_selector["Strategy selector<br/>[selector.ts]"]
  node_strategy_runtime["Strategy runtime<br/>[runtime.ts]"]
end

subgraph group_agents["Agent orchestration"]
  node_agent_orchestrator["Team orchestrator<br/>[engine.ts]"]
  node_arena["Arena coordinator<br/>[coordinator.ts]"]
  node_agent_executor["Agent executor<br/>[executor.ts]"]
  node_backend_router["Backend router<br/>[router.ts]"]
  node_team_builder["Team builder<br/>[builder.ts]"]
end

subgraph group_capabilities["Tools and integrations"]
  node_cap_registry["Capability registry<br/>[registry.ts]"]
  node_mcp_client["MCP client<br/>[client.ts]"]
  node_file_tools["File tools<br/>[tools.ts]"]
  node_shell_tools["Shell tools<br/>[tools.ts]"]
end

subgraph group_platform["Server and state"]
  node_server_api["HTTP API<br/>[index.ts]"]
  node_pipeline_route["Pipeline jobs<br/>[pipeline.ts]"]
  node_database[("Application database<br/>[client.ts]")]
  node_checkpoint_store["Checkpoint storage<br/>[checkpoints.ts]"]
  node_provider_router["Provider routing<br/>[router.ts]"]
end

node_user(("Developer"))

node_user -->|"submits task"| node_cli_input
node_cli_input -->|"enters session"| node_cli_session
node_cli_session -->|"uses execution"| node_cli_hook
node_cli_hook -->|"requests execution"| node_cli_api
node_cli_api -->|"parses events"| node_cli_stream
node_cli_api -->|"calls API"| node_server_api
node_server_api -.->|"persists application state"| node_database
node_engine -->|"profiles task"| node_profiler
node_engine -->|"selects strategy"| node_selector
node_engine -->|"builds context"| node_context
node_engine -->|"runs strategy"| node_strategy_runtime
node_server_api -.->|"starts execution"| node_engine
node_agent_orchestrator -->|"delegates execution"| node_arena
node_agent_orchestrator -->|"constructs executor"| node_agent_executor
node_agent_orchestrator -->|"constructs router"| node_backend_router
node_arena -->|"executes agents"| node_agent_executor
node_arena -.->|"uses team config"| node_team_builder
node_agent_executor -->|"requests model"| node_backend_router
node_mcp_client -->|"provides remote tools"| node_cap_registry
node_file_tools -.->|"registers tools"| node_cap_registry
node_shell_tools -.->|"registers tools"| node_cap_registry
node_pipeline_route -.->|"serves pipeline jobs"| node_server_api
node_engine -.->|"routes providers"| node_provider_router
node_engine -.->|"supports rewind"| node_checkpoint_store

click node_cli_session "https://github.com/d-engahmed/ancient/blob/main/packages/cli/src/screens/session.tsx"
click node_cli_input "https://github.com/d-engahmed/ancient/blob/main/packages/cli/src/components/input-bar.tsx"
click node_cli_hook "https://github.com/d-engahmed/ancient/blob/main/packages/cli/src/hooks/use-execution.ts"
click node_cli_api "https://github.com/d-engahmed/ancient/blob/main/packages/cli/src/lib/api-client.ts"
click node_cli_stream "https://github.com/d-engahmed/ancient/blob/main/packages/cli/src/lib/execution-stream.ts"
click node_engine "https://github.com/d-engahmed/ancient/blob/main/packages/execution/src/engine.ts"
click node_context "https://github.com/d-engahmed/ancient/blob/main/packages/execution/src/context.ts"
click node_profiler "https://github.com/d-engahmed/ancient/blob/main/packages/execution/src/profiler.ts"
click node_selector "https://github.com/d-engahmed/ancient/blob/main/packages/strategies/src/selector.ts"
click node_strategy_runtime "https://github.com/d-engahmed/ancient/blob/main/packages/execution/src/runtime.ts"
click node_agent_orchestrator "https://github.com/d-engahmed/ancient/blob/main/packages/agent/src/runtime/engine.ts"
click node_arena "https://github.com/d-engahmed/ancient/blob/main/packages/agent/src/arena/coordinator.ts"
click node_agent_executor "https://github.com/d-engahmed/ancient/blob/main/packages/agent/src/runtime/executor.ts"
click node_backend_router "https://github.com/d-engahmed/ancient/blob/main/packages/agent/src/backends/router.ts"
click node_team_builder "https://github.com/d-engahmed/ancient/blob/main/packages/agent/src/team/builder.ts"
click node_cap_registry "https://github.com/d-engahmed/ancient/blob/main/packages/capabilities/src/core/registry.ts"
click node_mcp_client "https://github.com/d-engahmed/ancient/blob/main/packages/capabilities/src/mcp/client.ts"
click node_file_tools "https://github.com/d-engahmed/ancient/blob/main/packages/capabilities/src/files/tools.ts"
click node_shell_tools "https://github.com/d-engahmed/ancient/blob/main/packages/capabilities/src/shell/tools.ts"
click node_server_api "https://github.com/d-engahmed/ancient/blob/main/packages/server/src/index.ts"
click node_pipeline_route "https://github.com/d-engahmed/ancient/blob/main/packages/server/src/routes/pipeline.ts"
click node_database "https://github.com/d-engahmed/ancient/blob/main/packages/database/src/client.ts"
click node_checkpoint_store "https://github.com/d-engahmed/ancient/blob/main/packages/infrastructure/src/storage/checkpoints.ts"
click node_provider_router "https://github.com/d-engahmed/ancient/blob/main/packages/infrastructure/src/providers/router.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_session,node_cli_input,node_cli_hook,node_cli_api,node_cli_stream toneBlue
class node_engine,node_context,node_profiler,node_selector,node_strategy_runtime toneAmber
class node_agent_orchestrator,node_arena,node_agent_executor,node_backend_router,node_team_builder toneMint
class node_cap_registry,node_mcp_client,node_file_tools,node_shell_tools toneRose
class node_server_api,node_pipeline_route,node_database,node_checkpoint_store,node_provider_router,node_user toneIndigo
```

## Components

### Terminal experience

- [Session console](https://github.com/d-engahmed/ancient/blob/main/packages/cli/src/screens/session.tsx): `packages/cli/src/screens/session.tsx`
- [Task input](https://github.com/d-engahmed/ancient/blob/main/packages/cli/src/components/input-bar.tsx): `packages/cli/src/components/input-bar.tsx`
- [Execution hook](https://github.com/d-engahmed/ancient/blob/main/packages/cli/src/hooks/use-execution.ts): `packages/cli/src/hooks/use-execution.ts`
- [API client](https://github.com/d-engahmed/ancient/blob/main/packages/cli/src/lib/api-client.ts): `packages/cli/src/lib/api-client.ts`
- [Event stream](https://github.com/d-engahmed/ancient/blob/main/packages/cli/src/lib/execution-stream.ts): `packages/cli/src/lib/execution-stream.ts`

### Execution engine

- [Unified engine](https://github.com/d-engahmed/ancient/blob/main/packages/execution/src/engine.ts): `packages/execution/src/engine.ts`
- [Context runtime](https://github.com/d-engahmed/ancient/blob/main/packages/execution/src/context.ts): `packages/execution/src/context.ts`
- [Task profiler](https://github.com/d-engahmed/ancient/blob/main/packages/execution/src/profiler.ts): `packages/execution/src/profiler.ts`
- [Strategy selector](https://github.com/d-engahmed/ancient/blob/main/packages/strategies/src/selector.ts): `packages/strategies/src/selector.ts`
- [Strategy runtime](https://github.com/d-engahmed/ancient/blob/main/packages/execution/src/runtime.ts): `packages/execution/src/runtime.ts`

### Agent orchestration

- [Team orchestrator](https://github.com/d-engahmed/ancient/blob/main/packages/agent/src/runtime/engine.ts): `packages/agent/src/runtime/engine.ts`
- [Arena coordinator](https://github.com/d-engahmed/ancient/blob/main/packages/agent/src/arena/coordinator.ts): `packages/agent/src/arena/coordinator.ts`
- [Agent executor](https://github.com/d-engahmed/ancient/blob/main/packages/agent/src/runtime/executor.ts): `packages/agent/src/runtime/executor.ts`
- [Backend router](https://github.com/d-engahmed/ancient/blob/main/packages/agent/src/backends/router.ts): `packages/agent/src/backends/router.ts`
- [Team builder](https://github.com/d-engahmed/ancient/blob/main/packages/agent/src/team/builder.ts): `packages/agent/src/team/builder.ts`

### Tools and integrations

- [Capability registry](https://github.com/d-engahmed/ancient/blob/main/packages/capabilities/src/core/registry.ts): `packages/capabilities/src/core/registry.ts`
- [MCP client](https://github.com/d-engahmed/ancient/blob/main/packages/capabilities/src/mcp/client.ts): `packages/capabilities/src/mcp/client.ts`
- [File tools](https://github.com/d-engahmed/ancient/blob/main/packages/capabilities/src/files/tools.ts): `packages/capabilities/src/files/tools.ts`
- [Shell tools](https://github.com/d-engahmed/ancient/blob/main/packages/capabilities/src/shell/tools.ts): `packages/capabilities/src/shell/tools.ts`

### Server and state

- [HTTP API](https://github.com/d-engahmed/ancient/blob/main/packages/server/src/index.ts): `packages/server/src/index.ts`
- [Pipeline jobs](https://github.com/d-engahmed/ancient/blob/main/packages/server/src/routes/pipeline.ts): `packages/server/src/routes/pipeline.ts`
- [Application database](https://github.com/d-engahmed/ancient/blob/main/packages/database/src/client.ts): `packages/database/src/client.ts`
- [Checkpoint storage](https://github.com/d-engahmed/ancient/blob/main/packages/infrastructure/src/storage/checkpoints.ts): `packages/infrastructure/src/storage/checkpoints.ts`
- [Provider routing](https://github.com/d-engahmed/ancient/blob/main/packages/infrastructure/src/providers/router.ts): `packages/infrastructure/src/providers/router.ts`

### Other components

- **Developer**

## Connections

- Developer → Task input: submits task
- Task input → Session console: enters session (evidence: `packages/cli/src/screens/session.tsx`)
- Session console → Execution hook: uses execution (evidence: `packages/cli/src/screens/session.tsx`)
- Execution hook → API client: requests execution
- API client → Event stream: parses events (evidence: `packages/cli/src/lib/api-client.ts`)
- API client → HTTP API: calls API
- HTTP API → Application database: persists application state
- Unified engine → Task profiler: profiles task (evidence: `packages/execution/src/engine.ts`)
- Unified engine → Strategy selector: selects strategy (evidence: `packages/execution/src/engine.ts`)
- Unified engine → Context runtime: builds context (evidence: `packages/execution/src/engine.ts`)
- Unified engine → Strategy runtime: runs strategy (evidence: `packages/execution/src/engine.ts`)
- HTTP API → Unified engine: starts execution
- Team orchestrator → Arena coordinator: delegates execution (evidence: `packages/agent/src/runtime/engine.ts`)
- Team orchestrator → Agent executor: constructs executor (evidence: `packages/agent/src/runtime/engine.ts`)
- Team orchestrator → Backend router: constructs router (evidence: `packages/agent/src/runtime/engine.ts`)
- Arena coordinator → Agent executor: executes agents (evidence: `packages/agent/src/arena/coordinator.ts`)
- Arena coordinator → Team builder: uses team config
- Agent executor → Backend router: requests model (evidence: `packages/agent/src/runtime/executor.ts`)
- MCP client → Capability registry: provides remote tools (evidence: `packages/capabilities/src/mcp/client.ts`)
- File tools → Capability registry: registers tools
- Shell tools → Capability registry: registers tools
- Pipeline jobs → HTTP API: serves pipeline jobs
- Unified engine → Provider routing: routes providers
- Unified engine → Checkpoint storage: supports rewind
