# berriai/moyai architecture

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

- Interactive diagram: https://gitdiagram.com/berriai/moyai
- Repository: https://github.com/berriai/moyai

## Overview

Moyai is a self-hosted coding agent: people submit background coding tasks through the browser or Slack, an agent works in an isolated workspace using a selectable harness and model, and the result can include saved files and a GitHub pull request. The map also includes documented search, automation, memory, attachments, and spend capabilities. Several modules are indexed but not excerpted; their links are included only where the README documents the behavior or the excerpts/index establish the relationship.

Main entry points: [`app/main.py`](https://github.com/berriai/moyai/blob/main/app/main.py) (Web application), [`app/runner.py`](https://github.com/berriai/moyai/blob/main/app/runner.py) (Session orchestration), [`sandbox/agent.py`](https://github.com/berriai/moyai/blob/main/sandbox/agent.py) (Agent runtime), [`sandbox/litellm_harness.py`](https://github.com/berriai/moyai/blob/main/sandbox/litellm_harness.py) (Model harnesses)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User entry points"]
  node_browser["Web workspace<br/>[app.js]"]
  node_slack["Slack chat<br/>[slack.py]"]
end

subgraph group_control["Workspace control plane"]
  node_api["Web application<br/>[main.py]"]
  node_sessions["Session orchestration<br/>[runner.py]"]
  node_automations["Automations<br/>[automations.py]"]
  node_connectors["Connections<br/>[connectors.py]"]
end

subgraph group_execution["Agent execution"]
  node_agent["Agent runtime<br/>[agent.py]"]
  node_harness["Model harnesses<br/>[litellm_harness.py]"]
  node_context["Context recovery"]
  node_tools["Workspace tools<br/>[skills.py]"]
  node_sandbox["Sandbox provider<br/>[modal.py]"]
end

subgraph group_integrations["Connected services"]
  node_model["LiteLLM providers"]
  node_github["GitHub integration<br/>[github.py]"]
  node_slackservice["Slack service"]
end

subgraph group_state["State and results"]
  node_store[("Workspace database<br/>[db.py]")]
  node_memory["Agent memory<br/>[memory.py]"]
  node_receipts[("Context receipts<br/>[context_store.py]")]
  node_files["Saved files<br/>[attachments.py]"]
  node_blob[("Private object storage<br/>[blob_storage.py]")]
  node_spend["Spend tracking<br/>[spend.py]"]
  node_pr["Pull request status"]
end

node_person(("Teammate"))

node_person -->|"submits tasks"| node_browser
node_person -->|"submits tasks"| node_slack
node_browser -->|"sends requests"| node_api
node_slack -->|"sends messages"| node_slackservice
node_slackservice -->|"starts work"| node_api
node_api -->|"dispatches work"| node_sessions
node_sessions -->|"creates workspace"| node_sandbox
node_sessions -->|"runs task"| node_agent
node_agent -->|"invokes harness"| node_harness
node_harness -->|"requests inference"| node_model
node_agent -->|"uses tools"| node_tools
node_harness -->|"recovers context"| node_context
node_context -->|"compacts history"| node_receipts
node_sessions -->|"persists sessions"| node_store
node_api -->|"configures connections"| node_connectors
node_agent -->|"works with repositories"| node_github
node_github -->|"provides PR state"| node_pr
node_sessions -->|"saves files"| node_files
node_files -->|"stores payloads"| node_blob
node_api -->|"offers automation"| node_automations
node_agent -->|"uses memory"| node_memory
node_api -->|"tracks spend"| node_spend

click node_browser "https://github.com/berriai/moyai/blob/main/app/static/app.js"
click node_slack "https://github.com/berriai/moyai/blob/main/app/slack.py"
click node_api "https://github.com/berriai/moyai/blob/main/app/main.py"
click node_sessions "https://github.com/berriai/moyai/blob/main/app/runner.py"
click node_automations "https://github.com/berriai/moyai/blob/main/app/automations.py"
click node_connectors "https://github.com/berriai/moyai/blob/main/app/connectors.py"
click node_agent "https://github.com/berriai/moyai/blob/main/sandbox/agent.py"
click node_harness "https://github.com/berriai/moyai/blob/main/sandbox/litellm_harness.py"
click node_context "https://github.com/berriai/moyai/blob/main/sandbox/context_recovery.py"
click node_tools "https://github.com/berriai/moyai/blob/main/app/skills.py"
click node_sandbox "https://github.com/berriai/moyai/blob/main/app/sandboxes/modal.py"
click node_github "https://github.com/berriai/moyai/blob/main/app/github.py"
click node_store "https://github.com/berriai/moyai/blob/main/app/db.py"
click node_memory "https://github.com/berriai/moyai/blob/main/app/memory.py"
click node_receipts "https://github.com/berriai/moyai/blob/main/sandbox/context_store.py"
click node_files "https://github.com/berriai/moyai/blob/main/app/attachments.py"
click node_blob "https://github.com/berriai/moyai/blob/main/app/blob_storage.py"
click node_spend "https://github.com/berriai/moyai/blob/main/app/spend.py"
click node_pr "https://github.com/berriai/moyai/blob/main/app/session_pull_requests.py"

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_browser,node_slack toneBlue
class node_api,node_sessions,node_automations,node_connectors toneAmber
class node_agent,node_harness,node_context,node_tools,node_sandbox toneMint
class node_model,node_github,node_slackservice toneRose
class node_store,node_memory,node_receipts,node_files,node_blob,node_spend,node_pr,node_person toneIndigo
```

## Components

### User entry points

- [Web workspace](https://github.com/berriai/moyai/blob/main/app/static/app.js): `app/static/app.js`
- [Slack chat](https://github.com/berriai/moyai/blob/main/app/slack.py): `app/slack.py`

### Workspace control plane

- [Web application](https://github.com/berriai/moyai/blob/main/app/main.py): `app/main.py`
- [Session orchestration](https://github.com/berriai/moyai/blob/main/app/runner.py): `app/runner.py`
- [Automations](https://github.com/berriai/moyai/blob/main/app/automations.py): `app/automations.py`
- [Connections](https://github.com/berriai/moyai/blob/main/app/connectors.py): `app/connectors.py`

### Agent execution

- [Agent runtime](https://github.com/berriai/moyai/blob/main/sandbox/agent.py): `sandbox/agent.py`
- [Model harnesses](https://github.com/berriai/moyai/blob/main/sandbox/litellm_harness.py): `sandbox/litellm_harness.py`
- [Context recovery](https://github.com/berriai/moyai/blob/main/sandbox/context_recovery.py): `sandbox/context_recovery.py`
- [Workspace tools](https://github.com/berriai/moyai/blob/main/app/skills.py): `app/skills.py`
- [Sandbox provider](https://github.com/berriai/moyai/blob/main/app/sandboxes/modal.py): `app/sandboxes/modal.py`

### Connected services

- **LiteLLM providers**
- [GitHub integration](https://github.com/berriai/moyai/blob/main/app/github.py): `app/github.py`
- **Slack service**

### State and results

- [Workspace database](https://github.com/berriai/moyai/blob/main/app/db.py): `app/db.py`
- [Agent memory](https://github.com/berriai/moyai/blob/main/app/memory.py): `app/memory.py`
- [Context receipts](https://github.com/berriai/moyai/blob/main/sandbox/context_store.py): `sandbox/context_store.py`
- [Saved files](https://github.com/berriai/moyai/blob/main/app/attachments.py): `app/attachments.py`
- [Private object storage](https://github.com/berriai/moyai/blob/main/app/blob_storage.py): `app/blob_storage.py`
- [Spend tracking](https://github.com/berriai/moyai/blob/main/app/spend.py): `app/spend.py`
- [Pull request status](https://github.com/berriai/moyai/blob/main/app/session_pull_requests.py): `app/session_pull_requests.py`

### Other components

- **Teammate**

## Connections

- Teammate → Web workspace: submits tasks (evidence: `README.md`)
- Teammate → Slack chat: submits tasks (evidence: `README.md`)
- Web workspace → Web application: sends requests (evidence: `README.md`)
- Slack chat → Slack service: sends messages (evidence: `README.md`)
- Slack service → Web application: starts work (evidence: `README.md`)
- Web application → Session orchestration: dispatches work (evidence: `app/main.py`)
- Session orchestration → Sandbox provider: creates workspace (evidence: `README.md`)
- Session orchestration → Agent runtime: runs task (evidence: `README.md`)
- Agent runtime → Model harnesses: invokes harness (evidence: `sandbox/litellm_harness.py`)
- Model harnesses → LiteLLM providers: requests inference (evidence: `README.md`)
- Agent runtime → Workspace tools: uses tools (evidence: `README.md`)
- Model harnesses → Context recovery: recovers context (evidence: `sandbox/litellm_harness.py`)
- Context recovery → Context receipts: compacts history (evidence: `sandbox/context_recovery.py`)
- Session orchestration → Workspace database: persists sessions (evidence: `app/main.py`)
- Web application → Connections: configures connections (evidence: `app/main.py`)
- Agent runtime → GitHub integration: works with repositories (evidence: `README.md`)
- GitHub integration → Pull request status: provides PR state (evidence: `app/session_pull_requests.py`)
- Session orchestration → Saved files: saves files (evidence: `README.md`)
- Saved files → Private object storage: stores payloads (evidence: `app/blob_storage.py`)
- Web application → Automations: offers automation (evidence: `app/main.py`)
- Agent runtime → Agent memory: uses memory (evidence: `README.md`)
- Web application → Spend tracking: tracks spend (evidence: `app/main.py`)
