# opengigantic/hachi architecture

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

- Interactive diagram: https://gitdiagram.com/opengigantic/hachi
- Repository: https://github.com/opengigantic/hachi

## Overview

Hachi is a governed personal AI agent, surfaced through a CLI/TUI, gateway and web UI, and messaging channels. The principal workflow is a user request entering a surface, reaching the gateway orchestrator, and being handled by the execution loop: model calls and tool use are constrained by budgets and permission/security guards, with skills and memory informing the turn. The repository also includes model routing, integrations, voice, scheduling and durable jobs. Relationships are limited to README architecture statements and source-index references; unsampled implementation details are not inferred.

Main entry points: [`src/hachi/gateway/orchestrator.py`](https://github.com/opengigantic/hachi/blob/main/src/hachi/gateway/orchestrator.py) (Session orchestrator), [`src/hachi/core/loop.py`](https://github.com/opengigantic/hachi/blob/main/src/hachi/core/loop.py) (Execution loop), [`src/hachi/gateway/fastapi_app.py`](https://github.com/opengigantic/hachi/blob/main/src/hachi/gateway/fastapi_app.py) (REST and SSE), [`src/hachi/core/routing/router.py`](https://github.com/opengigantic/hachi/blob/main/src/hachi/core/routing/router.py) (Model routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_surfaces["User surfaces"]
  node_cli["CLI<br/>[main.py]"]
  node_tui["Terminal cockpit<br/>[app.py]"]
  node_gateway["REST and SSE<br/>[fastapi_app.py]"]
  node_web["Web interface<br/>[conversation.tsx]"]
  node_channels["Messaging channels<br/>[router.py]"]
end

subgraph group_runtime["Agent runtime"]
  node_orchestrator["Session orchestrator<br/>[orchestrator.py]"]
  node_loop["Execution loop<br/>[loop.py]"]
  node_jobs["Durable jobs<br/>[job_handlers.py]"]
  node_sessions[("Session storage<br/>[session_store.py]")]
end

subgraph group_governance["Governance and models"]
  node_model["LLM clients<br/>[llm.py]"]
  node_routing["Model routing<br/>[router.py]"]
  node_registry["Model registry<br/>[registry.py]"]
  node_permissions["Permission gate<br/>[permissions.py]"]
  node_settings["Configuration<br/>[settings.py]"]
end

subgraph group_knowledge["Skills and memory"]
  node_skills["ObjectGraph skills<br/>[engine.py]"]
  node_ogparser["OG parser<br/>[parser.py]"]
  node_memory["Memory system<br/>[memory.py]"]
  node_vault[("Memory vault<br/>[memory_vault.py]")]
end

subgraph group_capabilities["Tools and integrations"]
  node_tools["Built-in tools"]
  node_mcp["MCP connections<br/>[mcp_client.py]"]
  node_integrations["Service integrations"]
end

node_user(("User"))
node_provider{{"Model providers"}}

node_user -->|"requests"| node_cli
node_user -->|"requests"| node_tui
node_user -->|"requests"| node_gateway
node_user -->|"requests"| node_web
node_user -->|"messages"| node_channels
node_cli -->|"starts sessions"| node_orchestrator
node_tui -->|"uses client"| node_gateway
node_gateway -->|"routes requests"| node_orchestrator
node_web -->|"uses API"| node_gateway
node_channels -->|"routes messages"| node_orchestrator
node_orchestrator -->|"wires session"| node_loop
node_orchestrator -->|"binds skills"| node_skills
node_orchestrator -->|"binds memory"| node_memory
node_orchestrator -->|"binds gate"| node_permissions
node_orchestrator -->|"binds MCP"| node_mcp
node_orchestrator -->|"uses storage"| node_sessions
node_loop -->|"calls model"| node_model
node_loop -->|"dispatches tools"| node_tools
node_loop -->|"checks calls"| node_permissions
node_loop -.->|"selects model"| node_routing
node_routing -->|"selects candidates"| node_registry
node_routing -->|"builds client"| node_model
node_model -.->|"sends completions"| node_provider
node_skills -->|"parses skills"| node_ogparser
node_memory -.->|"uses vault"| node_vault
node_orchestrator -->|"binds services"| node_integrations
node_orchestrator -.->|"coordinates jobs"| node_jobs
node_settings -->|"configures models"| node_registry

click node_cli "https://github.com/opengigantic/hachi/blob/main/src/hachi/cli/main.py"
click node_tui "https://github.com/opengigantic/hachi/blob/main/src/hachi/tui/cockpit/app.py"
click node_gateway "https://github.com/opengigantic/hachi/blob/main/src/hachi/gateway/fastapi_app.py"
click node_web "https://github.com/opengigantic/hachi/blob/main/frontend/src/routes/conversation.tsx"
click node_channels "https://github.com/opengigantic/hachi/blob/main/src/hachi/channels/router.py"
click node_orchestrator "https://github.com/opengigantic/hachi/blob/main/src/hachi/gateway/orchestrator.py"
click node_loop "https://github.com/opengigantic/hachi/blob/main/src/hachi/core/loop.py"
click node_jobs "https://github.com/opengigantic/hachi/blob/main/src/hachi/core/runtime/job_handlers.py"
click node_model "https://github.com/opengigantic/hachi/blob/main/src/hachi/core/llm.py"
click node_routing "https://github.com/opengigantic/hachi/blob/main/src/hachi/core/routing/router.py"
click node_registry "https://github.com/opengigantic/hachi/blob/main/src/hachi/core/routing/registry.py"
click node_permissions "https://github.com/opengigantic/hachi/blob/main/src/hachi/core/permissions.py"
click node_settings "https://github.com/opengigantic/hachi/blob/main/src/hachi/core/settings.py"
click node_skills "https://github.com/opengigantic/hachi/blob/main/src/hachi/og_engine/engine.py"
click node_ogparser "https://github.com/opengigantic/hachi/blob/main/src/hachi/og_engine/parser.py"
click node_memory "https://github.com/opengigantic/hachi/blob/main/src/hachi/core/memory.py"
click node_vault "https://github.com/opengigantic/hachi/blob/main/src/hachi/core/memory_vault.py"
click node_sessions "https://github.com/opengigantic/hachi/blob/main/src/hachi/core/session_store.py"
click node_tools "https://github.com/opengigantic/hachi/tree/main/src/hachi/tools"
click node_mcp "https://github.com/opengigantic/hachi/blob/main/src/hachi/core/mcp_client.py"
click node_integrations "https://github.com/opengigantic/hachi/tree/main/src/hachi/integrations"

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_tui,node_gateway,node_web,node_channels,node_user toneBlue
class node_orchestrator,node_loop,node_jobs,node_sessions toneAmber
class node_model,node_routing,node_registry,node_permissions,node_settings toneMint
class node_skills,node_ogparser,node_memory,node_vault toneRose
class node_tools,node_mcp,node_integrations,node_provider toneIndigo
```

## Components

### User surfaces

- [CLI](https://github.com/opengigantic/hachi/blob/main/src/hachi/cli/main.py): `src/hachi/cli/main.py`
- [Terminal cockpit](https://github.com/opengigantic/hachi/blob/main/src/hachi/tui/cockpit/app.py): `src/hachi/tui/cockpit/app.py`
- [REST and SSE](https://github.com/opengigantic/hachi/blob/main/src/hachi/gateway/fastapi_app.py): `src/hachi/gateway/fastapi_app.py`
- [Web interface](https://github.com/opengigantic/hachi/blob/main/frontend/src/routes/conversation.tsx): `frontend/src/routes/conversation.tsx`
- [Messaging channels](https://github.com/opengigantic/hachi/blob/main/src/hachi/channels/router.py): `src/hachi/channels/router.py`

### Agent runtime

- [Session orchestrator](https://github.com/opengigantic/hachi/blob/main/src/hachi/gateway/orchestrator.py): `src/hachi/gateway/orchestrator.py`
- [Execution loop](https://github.com/opengigantic/hachi/blob/main/src/hachi/core/loop.py): `src/hachi/core/loop.py`
- [Durable jobs](https://github.com/opengigantic/hachi/blob/main/src/hachi/core/runtime/job_handlers.py): `src/hachi/core/runtime/job_handlers.py`
- [Session storage](https://github.com/opengigantic/hachi/blob/main/src/hachi/core/session_store.py): `src/hachi/core/session_store.py`

### Governance and models

- [LLM clients](https://github.com/opengigantic/hachi/blob/main/src/hachi/core/llm.py): `src/hachi/core/llm.py`
- [Model routing](https://github.com/opengigantic/hachi/blob/main/src/hachi/core/routing/router.py): `src/hachi/core/routing/router.py`
- [Model registry](https://github.com/opengigantic/hachi/blob/main/src/hachi/core/routing/registry.py): `src/hachi/core/routing/registry.py`
- [Permission gate](https://github.com/opengigantic/hachi/blob/main/src/hachi/core/permissions.py): `src/hachi/core/permissions.py`
- [Configuration](https://github.com/opengigantic/hachi/blob/main/src/hachi/core/settings.py): `src/hachi/core/settings.py`

### Skills and memory

- [ObjectGraph skills](https://github.com/opengigantic/hachi/blob/main/src/hachi/og_engine/engine.py): `src/hachi/og_engine/engine.py`
- [OG parser](https://github.com/opengigantic/hachi/blob/main/src/hachi/og_engine/parser.py): `src/hachi/og_engine/parser.py`
- [Memory system](https://github.com/opengigantic/hachi/blob/main/src/hachi/core/memory.py): `src/hachi/core/memory.py`
- [Memory vault](https://github.com/opengigantic/hachi/blob/main/src/hachi/core/memory_vault.py): `src/hachi/core/memory_vault.py`

### Tools and integrations

- [Built-in tools](https://github.com/opengigantic/hachi/tree/main/src/hachi/tools): `src/hachi/tools`
- [MCP connections](https://github.com/opengigantic/hachi/blob/main/src/hachi/core/mcp_client.py): `src/hachi/core/mcp_client.py`
- [Service integrations](https://github.com/opengigantic/hachi/tree/main/src/hachi/integrations): `src/hachi/integrations`

### Other components

- **User**
- **Model providers**

## Connections

- User → CLI: requests
- User → Terminal cockpit: requests
- User → REST and SSE: requests
- User → Web interface: requests
- User → Messaging channels: messages
- CLI → Session orchestrator: starts sessions (evidence: `src/hachi/cli/main.py`)
- Terminal cockpit → REST and SSE: uses client (evidence: `src/hachi/tui/cockpit/app.py`)
- REST and SSE → Session orchestrator: routes requests
- Web interface → REST and SSE: uses API
- Messaging channels → Session orchestrator: routes messages
- Session orchestrator → Execution loop: wires session (evidence: `src/hachi/gateway/orchestrator.py`)
- Session orchestrator → ObjectGraph skills: binds skills (evidence: `src/hachi/gateway/orchestrator.py`)
- Session orchestrator → Memory system: binds memory (evidence: `src/hachi/gateway/orchestrator.py`)
- Session orchestrator → Permission gate: binds gate (evidence: `src/hachi/gateway/orchestrator.py`)
- Session orchestrator → MCP connections: binds MCP (evidence: `src/hachi/gateway/orchestrator.py`)
- Session orchestrator → Session storage: uses storage (evidence: `src/hachi/gateway/orchestrator.py`)
- Execution loop → LLM clients: calls model
- Execution loop → Built-in tools: dispatches tools
- Execution loop → Permission gate: checks calls
- Execution loop → Model routing: selects model
- Model routing → Model registry: selects candidates (evidence: `src/hachi/core/routing/router.py`)
- Model routing → LLM clients: builds client (evidence: `src/hachi/core/routing/router.py`)
- LLM clients → Model providers: sends completions
- ObjectGraph skills → OG parser: parses skills (evidence: `src/hachi/og_engine/engine.py`)
- Memory system → Memory vault: uses vault
- Session orchestrator → Service integrations: binds services (evidence: `src/hachi/gateway/orchestrator.py`)
- Session orchestrator → Durable jobs: coordinates jobs (evidence: `src/hachi/core/runtime/job_handlers.py`)
- Configuration → Model registry: configures models (evidence: `src/hachi/core/routing/registry.py`)
