# truefoundry/trueforge architecture

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

- Interactive diagram: https://gitdiagram.com/truefoundry/trueforge
- Repository: https://github.com/truefoundry/trueforge
- Video tour (about a minute): https://gitdiagram.com/truefoundry/trueforge/video

## Overview

#### Purpose and Entry Points
TrueForge is an open-source agent harness: it executes LLM agent turns with sessions, streaming, tools, approvals, skills, sandboxing, and context management. The deployable Node.js server starts through `packages/trueforge/src/main.ts`; CLI/local startup is `packages/trueforge/src/cli.ts`. The HTTP application is assembled in `packages/trueforge/src/app.ts`; scheduled work has a separate controller entry point at `packages/trueforge/src/controller-main.ts`.

#### Server API and Contract Boundary
The server exposes REST/SSE endpoints for agents, sessions/turns, configuration resources, schedules, metrics, and authentication. Route definitions separate transport from API implementations:
- `packages/trueforge/src/routes/sessionRoutes.ts`
- `packages/trueforge/src/routes/turnRoutes.ts`
- `packages/trueforge/src/apis/sessions.ts`

Request/response schemas in `packages/trueforge/src/schemas/` are the server’s validation boundary. OpenAPI is emitted from the server and drives generated client SDKs via `.github/fern/openapi/openapi.json`.

#### Agent Execution Core
`@truefoundry/trueforge-core` contains runtime-agnostic execution logic. An incoming turn resolves its agent/session resources, creates an agent thread, invokes the model, processes streamed events/tool calls, and persists thread/turn state. Main orchestration seams:
- `packages/trueforge-core/src/core/runtime/AgentThreadOrchestrator.ts`
- `packages/trueforge-core/src/core/runtime/AgentThread.ts`
- `packages/trueforge-core/src/agent-session/Sessions.ts`

The LLM interface decouples orchestration from providers; the supplied adapter uses the Vercel AI stack/OpenAI-shaped messages: `packages/trueforge-core/src/core/llm/ILLM.ts` and `packages/trueforge-core/src/core/llm/VercelAILLM.ts`.

#### Tools, Capabilities, and Human Interaction
Agent specifications enable built-in capabilities such as context compaction, deferred/large tool responses, web search, OpenUI, dynamic subagents, and ask-user prompts. Capabilities modify context or tool-response handling around the core loop:
- `packages/trueforge-core/src/core/capabilities/AgentCapability.ts`
- `packages/trueforge-core/src/core/capabilities/builtins/ContextCompaction.ts`
- `packages/trueforge-core/src/core/capabilities/builtins/DynamicSubAgents.ts`

MCP is the primary external-tool boundary. Local and remote server adapters normalize available tools, select/load them, execute calls, and surface authorization/approval events: `packages/trueforge-core/src/core/mcp/RemoteMCP.ts`, `packages/trueforge-core/src/core/mcp/ToolSet.ts`, `packages/trueforge-core/src/core/mcp/executeToolCalls.ts`.

#### Persistence, Identity, and Runtime Coordination
The server abstracts agents, sessions, providers, skills, OAuth tokens, schedules, and metrics behind stores, with SQLite for local mode and Postgres for hosted mode. Core examples are `packages/trueforge/src/db/sqlite/session-store/SqliteSessionStore.ts` and `packages/trueforge/src/db/postgres/session-store/PostgresSessionStore.ts`. Migrations live alongside each implementation.

Authentication/authorization is configurable, including standalone and OIDC modes: `packages/trueforge/src/auth/createAuthenticator.ts` and `packages/trueforge/src/auth/authorizer.ts`. Hosted multi-replica coordination uses Redis for event subscriptions and runtime state: `packages/trueforge/src/runtime/event-subscription/redis.ts`, `packages/trueforge/src/runtime/redis.ts`.

#### Sandboxes and Scheduled Execution
Sandboxing is a provisioned-on-demand tool execution boundary. Core supports Daytona and TrueFoundry sandbox providers plus NATS-based Code Mode transport: `packages/trueforge-core/src/core/sandbox/Sandbox.ts`, `packages/trueforge-core/src/core/sandbox/provider/DaytonaProvider.ts`, `packages/trueforge-core/src/core/sandbox/codeMode/nats/CodeModeNatsTransport.ts`. The server also implements a local sandbox provider under `packages/trueforge/src/sandbox/local/provider/LocalSandboxProvider.ts`.

Schedules are persisted then dispatched by the controller, which creates unattended session work: `packages/trueforge/src/controller/Controller.ts` and `packages/trueforge/src/controller/scheduleDispatch.ts`.

#### Clients, UI, and Deployment
Generated TypeScript and Python SDKs consume the HTTP contract: `packages/trueforge-sdk/src/Client.ts` and `python/trueforge_sdk/src/trueforge_sdk/client.py`. The bundled React frontend boots at `packages/frontend/src/main.ts`; the embeddable UI package composes chat/server adapters through `packages/trueforge-ui/src/containers/TrueForgeUI.tsx` and `packages/trueforge-ui/src/plugins/trueforge-agent-server-adapter/client.ts`.

Runtime targets are Node.js 22.14+, Docker Compose, Railway, and Kubernetes Helm. Production topology is server/controller plus Postgres and Redis; Helm manifests define both application and controller deployments: `charts/trueforge/templates/deployment.yaml` and `charts/trueforge/templates/controller-deployment.yaml`.

Main entry points: [`packages/trueforge/src/app.ts`](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/app.ts) (HTTP application), [`packages/trueforge-core/src/core/runtime/AgentThread.ts`](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/core/runtime/AgentThread.ts) (Agent thread), [`packages/trueforge-core/src/core/runtime/AgentThreadOrchestrator.ts`](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/core/runtime/AgentThreadOrchestrator.ts) (Agent thread orchestrator), [`packages/trueforge/src/routes/sessionRoutes.ts`](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/routes/sessionRoutes.ts) (REST and SSE routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Node.js Server"]
  node_server_entry["Server entry<br/>Node.js entry<br/>[main.ts]"]
  node_cli["CLI / local startup<br/>CLI entry<br/>[cli.ts]"]
  node_http_app["HTTP application<br/>API server<br/>[app.ts]"]
  node_routes["REST and SSE routes<br/>transport routes<br/>[sessionRoutes.ts]"]
  node_sessions_api["Session API<br/>API implementation<br/>[sessions.ts]"]
  node_schemas["Request/response schemas<br/>validation contract"]
  node_auth["Authentication &amp; authorization<br/>identity boundary"]
end

subgraph group_core["Execution Core"]
  node_orchestrator["Agent thread orchestrator<br/>turn orchestration"]
  node_agent_thread["Agent thread<br/>execution loop<br/>[AgentThread.ts]"]
  node_sessions["Session runtime<br/>session lifecycle<br/>[Sessions.ts]"]
  node_llm["LLM interface &amp; Vercel adapter<br/>model provider adapter<br/>[ILLM.ts]"]
  node_capabilities["Agent capabilities<br/>context and tool behavior<br/>[AgentCapability.ts]"]
  node_mcp{{"MCP tool boundary<br/>external tools<br/>[ToolSet.ts]"}}
  node_sandbox{{"Sandbox providers<br/>isolated execution<br/>[Sandbox.ts]"}}
end

subgraph group_runtime["Hosted Runtime"]
  node_stores[("Resource stores<br/>persistence abstraction")]
  node_postgres[("Postgres<br/>hosted database")]
  node_redis[("Redis coordination<br/>event and runtime state<br/>[redis.ts]")]
  node_controller["Schedule controller<br/>scheduled-work dispatcher<br/>[Controller.ts]"]
  node_helm["Helm deployments<br/>production topology<br/>[deployment.yaml]"]
end

subgraph group_clients["Clients &amp; UI"]
  node_sdk["Generated SDKs<br/>TypeScript and Python clients<br/>[Client.ts]"]
  node_frontend["Bundled React frontend<br/>web client"]
  node_embed_ui["Embeddable TrueForge UI<br/>UI package<br/>[TrueForgeUI.tsx]"]
end

node_server_entry -->|"starts"| node_http_app
node_cli -->|"starts locally"| node_http_app
node_http_app -->|"authenticates requests"| node_auth
node_http_app -->|"mounts"| node_routes
node_routes -->|"dispatches"| node_sessions_api
node_routes -->|"validates with"| node_schemas
node_sessions_api -->|"starts turns"| node_orchestrator
node_orchestrator -->|"resolves and persists"| node_sessions
node_orchestrator -->|"creates"| node_agent_thread
node_agent_thread -->|"invokes model"| node_llm
node_agent_thread -->|"applies"| node_capabilities
node_agent_thread -->|"executes tool calls"| node_mcp
node_mcp -->|"uses isolated tools"| node_sandbox
node_sessions -->|"uses"| node_stores
node_stores -.->|"hosted implementation"| node_postgres
node_http_app -->|"coordinates replicas"| node_redis
node_controller -->|"reads schedules"| node_stores
node_controller -->|"dispatches unattended work"| node_orchestrator
node_schemas -->|"OpenAPI generates"| node_sdk
node_frontend -->|"consumes API"| node_http_app
node_embed_ui -->|"uses server adapter"| node_http_app
node_helm -->|"deploys server"| node_server_entry
node_helm -->|"deploys controller"| node_controller

click node_server_entry "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/main.ts"
click node_cli "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/cli.ts"
click node_http_app "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/app.ts"
click node_routes "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/routes/sessionRoutes.ts"
click node_sessions_api "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/apis/sessions.ts"
click node_auth "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/auth/createAuthenticator.ts"
click node_orchestrator "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/core/runtime/AgentThreadOrchestrator.ts"
click node_agent_thread "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/core/runtime/AgentThread.ts"
click node_sessions "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/agent-session/Sessions.ts"
click node_llm "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/core/llm/ILLM.ts"
click node_capabilities "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/core/capabilities/AgentCapability.ts"
click node_mcp "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/core/mcp/ToolSet.ts"
click node_sandbox "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/core/sandbox/Sandbox.ts"
click node_stores "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/db/sqlite/session-store/SqliteSessionStore.ts"
click node_postgres "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/db/postgres/session-store/PostgresSessionStore.ts"
click node_redis "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/runtime/redis.ts"
click node_controller "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/controller/Controller.ts"
click node_sdk "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-sdk/src/Client.ts"
click node_embed_ui "https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-ui/src/containers/TrueForgeUI.tsx"
click node_helm "https://github.com/truefoundry/trueforge/blob/main/charts/trueforge/templates/deployment.yaml"

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_server_entry,node_cli,node_http_app,node_routes,node_sessions_api,node_schemas,node_auth toneBlue
class node_orchestrator,node_agent_thread,node_sessions,node_llm,node_capabilities,node_mcp,node_sandbox toneAmber
class node_stores,node_postgres,node_redis,node_controller,node_helm toneMint
class node_sdk,node_frontend,node_embed_ui toneRose
```

## Components

### Node.js Server

- [Server entry](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/main.ts): Node.js entry · `packages/trueforge/src/main.ts`
- [CLI / local startup](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/cli.ts): CLI entry · `packages/trueforge/src/cli.ts`
- [HTTP application](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/app.ts): API server · `packages/trueforge/src/app.ts`
- [REST and SSE routes](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/routes/sessionRoutes.ts): transport routes · `packages/trueforge/src/routes/sessionRoutes.ts`
- [Session API](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/apis/sessions.ts): API implementation · `packages/trueforge/src/apis/sessions.ts`
- **Request/response schemas**: validation contract · Also emits the OpenAPI contract.
- [Authentication & authorization](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/auth/createAuthenticator.ts): identity boundary · `packages/trueforge/src/auth/createAuthenticator.ts`

### Execution Core

- [Agent thread orchestrator](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/core/runtime/AgentThreadOrchestrator.ts): turn orchestration · `packages/trueforge-core/src/core/runtime/AgentThreadOrchestrator.ts`
- [Agent thread](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/core/runtime/AgentThread.ts): execution loop · Processes streaming events and tool calls. · `packages/trueforge-core/src/core/runtime/AgentThread.ts`
- [Session runtime](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/agent-session/Sessions.ts): session lifecycle · `packages/trueforge-core/src/agent-session/Sessions.ts`
- [LLM interface & Vercel adapter](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/core/llm/ILLM.ts): model provider adapter · `packages/trueforge-core/src/core/llm/ILLM.ts`
- [Agent capabilities](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/core/capabilities/AgentCapability.ts): context and tool behavior · Includes compaction and dynamic subagents. · `packages/trueforge-core/src/core/capabilities/AgentCapability.ts`
- [MCP tool boundary](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/core/mcp/ToolSet.ts): external tools · Normalizes, loads, and executes local or remote tools. · `packages/trueforge-core/src/core/mcp/ToolSet.ts`
- [Sandbox providers](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-core/src/core/sandbox/Sandbox.ts): isolated execution · Daytona, TrueFoundry, local, and NATS Code Mode. · `packages/trueforge-core/src/core/sandbox/Sandbox.ts`

### Hosted Runtime

- [Resource stores](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/db/sqlite/session-store/SqliteSessionStore.ts): persistence abstraction · Agents, sessions, providers, skills, tokens, schedules, and metrics. · `packages/trueforge/src/db/sqlite/session-store/SqliteSessionStore.ts`
- [Postgres](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/db/postgres/session-store/PostgresSessionStore.ts): hosted database · `packages/trueforge/src/db/postgres/session-store/PostgresSessionStore.ts`
- [Redis coordination](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/runtime/redis.ts): event and runtime state · `packages/trueforge/src/runtime/redis.ts`
- [Schedule controller](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/controller/Controller.ts): scheduled-work dispatcher · Creates unattended session work. · `packages/trueforge/src/controller/Controller.ts`
- [Helm deployments](https://github.com/truefoundry/trueforge/blob/main/charts/trueforge/templates/deployment.yaml): production topology · Deploys server and controller replicas. · `charts/trueforge/templates/deployment.yaml`

### Clients & UI

- [Generated SDKs](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-sdk/src/Client.ts): TypeScript and Python clients · Generated from the emitted OpenAPI contract. · `packages/trueforge-sdk/src/Client.ts`
- **Bundled React frontend**: web client
- [Embeddable TrueForge UI](https://github.com/truefoundry/trueforge/blob/main/packages/trueforge-ui/src/containers/TrueForgeUI.tsx): UI package · `packages/trueforge-ui/src/containers/TrueForgeUI.tsx`

## Connections

- Server entry → HTTP application: starts
- CLI / local startup → HTTP application: starts locally
- HTTP application → Authentication & authorization: authenticates requests
- HTTP application → REST and SSE routes: mounts
- REST and SSE routes → Session API: dispatches
- REST and SSE routes → Request/response schemas: validates with
- Session API → Agent thread orchestrator: starts turns
- Agent thread orchestrator → Session runtime: resolves and persists
- Agent thread orchestrator → Agent thread: creates
- Agent thread → LLM interface & Vercel adapter: invokes model
- Agent thread → Agent capabilities: applies
- Agent thread → MCP tool boundary: executes tool calls
- MCP tool boundary → Sandbox providers: uses isolated tools
- Session runtime → Resource stores: uses
- Resource stores → Postgres: hosted implementation
- HTTP application → Redis coordination: coordinates replicas
- Schedule controller → Resource stores: reads schedules
- Schedule controller → Agent thread orchestrator: dispatches unattended work
- Request/response schemas → Generated SDKs: OpenAPI generates
- Bundled React frontend → HTTP application: consumes API
- Embeddable TrueForge UI → HTTP application: uses server adapter
- Helm deployments → Server entry: deploys server
- Helm deployments → Schedule controller: deploys controller
