# anentrypoint/freddie architecture

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

- Interactive diagram: https://gitdiagram.com/anentrypoint/freddie
- Repository: https://github.com/anentrypoint/freddie

## Overview

#### Purpose and Entry Points
Freddie is a JavaScript agent harness: it runs LLM-driven agent turns with tools, persistent sessions, plugins, multi-channel gateway delivery, and optional dashboard/IDE integration. The main executable is `bin/freddie.js`; command dispatch and interactive/noninteractive flows live in `src/cli/main.js`, `src/cli/interactive.js`, and `src/cli/oneshot.js`. It also exposes an ACP JSON-RPC stdio server (`src/acp/server.js`) and browser bundle entry (`src/browser/index.js`).

#### Agent Runtime and Model Boundary
The central control loop is the XState-based agent machine in `src/agent/machine.js`, bridged to the pi agent/model substrate through `src/agent/pi-bridge.js`. Provider selection, ordered failover, credentials, retry/rate-limit behavior, and provider-specific wire formats are separated into `src/agent/llm_resolver.js`, `src/credentials/pool.js`, and adapters such as `src/agent/adapters/anthropic_adapter.js`, `src/agent/adapters/openrouter_adapter.js`, and `src/agent/adapters/gemini_native_adapter.js`. External LLM APIs are therefore behind adapters rather than directly coupled to CLI or platforms.

#### Context, State, and Persistence
Before model invocation, context is assembled by `src/context/engine.js`; long conversations are reduced by the dedicated compressor pipeline in `src/agent/compress/index.js`, `src/agent/compress/compressor.js`, and `src/agent/compress/prune.js`. Local durable state includes SQLite-backed sessions/search (`src/sessions.js`, `src/db.js`), machine snapshots/journals (`src/machines/snapshot-store.js`, `src/machines/step-journal.js`), and home/profile/config state (`src/home.js`, `src/config.js`). This is the key persistence boundary between transient agent execution and user-scoped `~/.freddie` data.

#### Plugin Host and Tool Plane
The host loads native Freddie plugins and wraps plugsdk-compatible plugins; its contract, manifest schema, and middleware boundary are in `src/host/host.js`, `src/host/contract.js`, and `src/host/tool-middleware.js`. Plugin directories provide most capability surfaces: tools (`plugins/tools/files/plugin.js`, `plugins/tools/bash/handler.js`), memory (`plugins/memory/memory/handler.js`), workflows/agent controls (`plugins/core/delegate/handler.js`, `plugins/core/checkpoint/handler.js`), and security guards (`plugins/security/path_security/handler.js`). Skills are separately loaded from `SKILL.md` content through `src/skills/index.js` and `skills/`.

#### Gateway and Platform Adapters
Inbound messages and webhooks enter the gateway runtime in `src/gateway/run.js`, are routed through `src/gateway/service.js` and built-in hooks in `src/gateway/builtin_hooks/`, then reach agent execution/tooling. Channel-specific credential parsing and protocol formatting are plugin-owned, e.g. `plugins/platform/platform-telegram/handler.js`, `plugins/platform/platform-discord/handler.js`, and `plugins/platform/platform-slack/handler.js`. This isolates external messaging services from core agent semantics.

#### User Interfaces and Automation
The terminal REPL is the primary interactive interface; the dashboard is an Express/webjsx application rooted at `src/web/server.js`, `src/web/app.js`, and `src/web/routes.js`. Scheduled work uses `src/cron/scheduler.js`; parallel prompt execution is in `src/batch.js`. Agent workflows can also be represented as resumable persistent actors via `src/machines/persistent-actor.js` and templates under `src/machines/templates/`.

#### Runtime, Delivery, and Observability
The project runs on Node.js/CommonJS-style JavaScript with pi-mono, XState, floosie, Express, SQLite/FTS, and plugin-provided external APIs. Structured diagnostics and machine visibility are centralized in `src/observability/log.js`, `src/observability/metrics.js`, and `src/observability/state-machines.js`. GitHub Actions cover test, browser bundle, model matrix, publication, Pages, and upstream synchronization under `.github/workflows/`; static documentation is built from `website/` and deployed through the Pages workflow.

Main entry points: [`src/agent/machine.js`](https://github.com/anentrypoint/freddie/blob/main/src/agent/machine.js) (Agent machine), [`src/gateway/service.js`](https://github.com/anentrypoint/freddie/blob/main/src/gateway/service.js) (Gateway service), [`src/host/host.js`](https://github.com/anentrypoint/freddie/blob/main/src/host/host.js) (Plugin host), [`src/cli/main.js`](https://github.com/anentrypoint/freddie/blob/main/src/cli/main.js) (CLI flows)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_cli["CLI flows<br/>Node.js CLI<br/>[main.js]"]
  node_acp["ACP server<br/>JSON-RPC stdio<br/>[server.js]"]
  node_browser["Browser entry<br/>browser bundle<br/>[index.js]"]
  node_dashboard["Dashboard<br/>Express/webjsx<br/>[server.js]"]
  node_gateway["Gateway service<br/>message gateway<br/>[service.js]"]
end

subgraph group_runtime["Agent runtime"]
  node_agent{{"Agent machine<br/>XState control loop<br/>[machine.js]"}}
  node_context["Context engine<br/>context assembly<br/>[engine.js]"]
  node_compression["Conversation compressor<br/>context reduction<br/>[index.js]"]
  node_pi_bridge["Pi bridge<br/>model substrate bridge<br/>[pi-bridge.js]"]
  node_resolver["LLM resolver<br/>provider selection<br/>[llm_resolver.js]"]
  node_adapters["LLM adapters<br/>provider adapters"]
end

subgraph group_extension["Extensions &amp; channels"]
  node_host{{"Plugin host<br/>plugin runtime<br/>[host.js]"}}
  node_tools["Tools &amp; controls<br/>capability plugins<br/>[plugin.js]"]
  node_skills["Skills<br/>SKILL.md loader<br/>[index.js]"]
  node_platforms["Platform plugins<br/>channel adapters<br/>[handler.js]"]
end

subgraph group_state["State &amp; operations"]
  node_sessions[("Sessions &amp; search<br/>SQLite/FTS<br/>[sessions.js]")]
  node_machine_state[("Machine durability<br/>snapshots &amp; journals<br/>[snapshot-store.js]")]
  node_actors["Persistent actors<br/>resumable workflows"]
  node_automation["Cron &amp; batch<br/>automation runners<br/>[scheduler.js]"]
  node_observability["Observability<br/>logs, metrics, state views<br/>[log.js]"]
  node_user_state[("User home/config<br/>profile state<br/>[home.js]")]
end

node_cli -->|"runs turns"| node_agent
node_acp -->|"RPC turns"| node_agent
node_browser -->|"client integration"| node_agent
node_dashboard -->|"views sessions"| node_sessions
node_gateway -->|"inbound messages"| node_agent
node_platforms -->|"channel events"| node_gateway
node_agent -->|"assembles context"| node_context
node_context -->|"reduces long history"| node_compression
node_agent -->|"invokes model"| node_pi_bridge
node_pi_bridge -->|"resolves provider"| node_resolver
node_resolver -->|"provider requests"| node_adapters
node_agent -->|"executes capabilities"| node_host
node_host -->|"loads tools and controls"| node_tools
node_host -->|"loads skills"| node_skills
node_agent -->|"reads/writes conversation"| node_sessions
node_agent -->|"snapshots steps"| node_machine_state
node_actors -->|"resumes workflows"| node_agent
node_actors -->|"persists actor state"| node_machine_state
node_automation -->|"starts prompts"| node_agent
node_agent -->|"emits diagnostics"| node_observability
node_dashboard -->|"machine visibility"| node_observability
node_cli -->|"loads profile"| node_user_state
node_gateway -->|"loads channel config"| node_user_state

click node_cli "https://github.com/anentrypoint/freddie/blob/main/src/cli/main.js"
click node_acp "https://github.com/anentrypoint/freddie/blob/main/src/acp/server.js"
click node_browser "https://github.com/anentrypoint/freddie/blob/main/src/browser/index.js"
click node_dashboard "https://github.com/anentrypoint/freddie/blob/main/src/web/server.js"
click node_gateway "https://github.com/anentrypoint/freddie/blob/main/src/gateway/service.js"
click node_agent "https://github.com/anentrypoint/freddie/blob/main/src/agent/machine.js"
click node_context "https://github.com/anentrypoint/freddie/blob/main/src/context/engine.js"
click node_compression "https://github.com/anentrypoint/freddie/blob/main/src/agent/compress/index.js"
click node_pi_bridge "https://github.com/anentrypoint/freddie/blob/main/src/agent/pi-bridge.js"
click node_resolver "https://github.com/anentrypoint/freddie/blob/main/src/agent/llm_resolver.js"
click node_adapters "https://github.com/anentrypoint/freddie/blob/main/src/agent/adapters/anthropic_adapter.js"
click node_host "https://github.com/anentrypoint/freddie/blob/main/src/host/host.js"
click node_tools "https://github.com/anentrypoint/freddie/blob/main/plugins/tools/files/plugin.js"
click node_skills "https://github.com/anentrypoint/freddie/blob/main/src/skills/index.js"
click node_platforms "https://github.com/anentrypoint/freddie/blob/main/plugins/platform/platform-telegram/handler.js"
click node_sessions "https://github.com/anentrypoint/freddie/blob/main/src/sessions.js"
click node_machine_state "https://github.com/anentrypoint/freddie/blob/main/src/machines/snapshot-store.js"
click node_actors "https://github.com/anentrypoint/freddie/blob/main/src/machines/persistent-actor.js"
click node_automation "https://github.com/anentrypoint/freddie/blob/main/src/cron/scheduler.js"
click node_observability "https://github.com/anentrypoint/freddie/blob/main/src/observability/log.js"
click node_user_state "https://github.com/anentrypoint/freddie/blob/main/src/home.js"

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_acp,node_browser,node_dashboard,node_gateway toneBlue
class node_agent,node_context,node_compression,node_pi_bridge,node_resolver,node_adapters toneAmber
class node_host,node_tools,node_skills,node_platforms toneMint
class node_sessions,node_machine_state,node_actors,node_automation,node_observability,node_user_state toneRose
```

## Components

### Entry points

- [CLI flows](https://github.com/anentrypoint/freddie/blob/main/src/cli/main.js): Node.js CLI · Command dispatch plus interactive and one-shot execution. · `src/cli/main.js`
- [ACP server](https://github.com/anentrypoint/freddie/blob/main/src/acp/server.js): JSON-RPC stdio · `src/acp/server.js`
- [Browser entry](https://github.com/anentrypoint/freddie/blob/main/src/browser/index.js): browser bundle · `src/browser/index.js`
- [Dashboard](https://github.com/anentrypoint/freddie/blob/main/src/web/server.js): Express/webjsx · `src/web/server.js`
- [Gateway service](https://github.com/anentrypoint/freddie/blob/main/src/gateway/service.js): message gateway · Routes inbound channel messages and built-in hooks. · `src/gateway/service.js`

### Agent runtime

- [Agent machine](https://github.com/anentrypoint/freddie/blob/main/src/agent/machine.js): XState control loop · Central turn orchestration and tool execution state machine. · `src/agent/machine.js`
- [Context engine](https://github.com/anentrypoint/freddie/blob/main/src/context/engine.js): context assembly · `src/context/engine.js`
- [Conversation compressor](https://github.com/anentrypoint/freddie/blob/main/src/agent/compress/index.js): context reduction · Prunes and compresses long conversations. · `src/agent/compress/index.js`
- [Pi bridge](https://github.com/anentrypoint/freddie/blob/main/src/agent/pi-bridge.js): model substrate bridge · `src/agent/pi-bridge.js`
- [LLM resolver](https://github.com/anentrypoint/freddie/blob/main/src/agent/llm_resolver.js): provider selection · Selects providers with ordered failover and retry behavior. · `src/agent/llm_resolver.js`
- [LLM adapters](https://github.com/anentrypoint/freddie/blob/main/src/agent/adapters/anthropic_adapter.js): provider adapters · Provider-specific API wire formats. · `src/agent/adapters/anthropic_adapter.js`

### Extensions & channels

- [Plugin host](https://github.com/anentrypoint/freddie/blob/main/src/host/host.js): plugin runtime · Loads native and plugsdk-compatible plugins with middleware. · `src/host/host.js`
- [Tools & controls](https://github.com/anentrypoint/freddie/blob/main/plugins/tools/files/plugin.js): capability plugins · Files, shell, memory, delegation, checkpoints, and security guards. · `plugins/tools/files/plugin.js`
- [Skills](https://github.com/anentrypoint/freddie/blob/main/src/skills/index.js): SKILL.md loader · `src/skills/index.js`
- [Platform plugins](https://github.com/anentrypoint/freddie/blob/main/plugins/platform/platform-telegram/handler.js): channel adapters · Telegram, Discord, Slack credentials and message formatting. · `plugins/platform/platform-telegram/handler.js`

### State & operations

- [Sessions & search](https://github.com/anentrypoint/freddie/blob/main/src/sessions.js): SQLite/FTS · Durable user sessions and search index. · `src/sessions.js`
- [Machine durability](https://github.com/anentrypoint/freddie/blob/main/src/machines/snapshot-store.js): snapshots & journals · Persists resumable machine state and step history. · `src/machines/snapshot-store.js`
- [Persistent actors](https://github.com/anentrypoint/freddie/blob/main/src/machines/persistent-actor.js): resumable workflows · Workflow actors backed by durable machine state. · `src/machines/persistent-actor.js`
- [Cron & batch](https://github.com/anentrypoint/freddie/blob/main/src/cron/scheduler.js): automation runners · Scheduled and parallel prompt execution. · `src/cron/scheduler.js`
- [Observability](https://github.com/anentrypoint/freddie/blob/main/src/observability/log.js): logs, metrics, state views · `src/observability/log.js`
- [User home/config](https://github.com/anentrypoint/freddie/blob/main/src/home.js): profile state · User-scoped ~/.freddie configuration and profile data. · `src/home.js`

## Connections

- CLI flows → Agent machine: runs turns
- ACP server → Agent machine: RPC turns
- Browser entry → Agent machine: client integration
- Dashboard → Sessions & search: views sessions
- Gateway service → Agent machine: inbound messages
- Platform plugins → Gateway service: channel events
- Agent machine → Context engine: assembles context
- Context engine → Conversation compressor: reduces long history
- Agent machine → Pi bridge: invokes model
- Pi bridge → LLM resolver: resolves provider
- LLM resolver → LLM adapters: provider requests
- Agent machine → Plugin host: executes capabilities
- Plugin host → Tools & controls: loads tools and controls
- Plugin host → Skills: loads skills
- Agent machine → Sessions & search: reads/writes conversation
- Agent machine → Machine durability: snapshots steps
- Persistent actors → Agent machine: resumes workflows
- Persistent actors → Machine durability: persists actor state
- Cron & batch → Agent machine: starts prompts
- Agent machine → Observability: emits diagnostics
- Dashboard → Observability: machine visibility
- CLI flows → User home/config: loads profile
- Gateway service → User home/config: loads channel config
