# mofa-org/mofa architecture

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

- Interactive diagram: https://gitdiagram.com/mofa-org/mofa
- Repository: https://github.com/mofa-org/mofa

## Overview

MoFA is an enterprise agent framework and LLM infrastructure platform. Its principal workflow accepts user requests through an agent runtime, which uses models, tools, workflows or retrieval to produce results; the platform also documents per-call token metering, cost accounting and audit. Distinct supporting capabilities include programmable plugins, gateway access, monitoring, voice inference and polyglot bindings. The README describes credits, plans, billing and recharge as planned enterprise-track work, so those are not represented as implemented stages. Several links are documented capabilities rather than inspected call paths.

Main entry points: [`crates/mofa-foundation/src/llm/agent.rs`](https://github.com/mofa-org/mofa/blob/main/crates/mofa-foundation/src/llm/agent.rs) (Agent execution), [`crates/mofa-foundation/src/cost`](https://github.com/mofa-org/mofa/tree/main/crates/mofa-foundation/src/cost) (Token metering), [`crates/mofa-kernel/src/lib.rs`](https://github.com/mofa-org/mofa/blob/main/crates/mofa-kernel/src/lib.rs) (Microkernel), [`crates/mofa-gateway/src/openai_compat/server.rs`](https://github.com/mofa-org/mofa/blob/main/crates/mofa-gateway/src/openai_compat/server.rs) (API gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Agent Runtime"]
  node_agents["Agent execution<br/>[agent.rs]"]
  node_workflows["Workflows"]
  node_rag["RAG pipeline<br/>[pipeline.rs]"]
  node_voice["Voice inference<br/>[pipeline.rs]"]
  node_kernel["Microkernel<br/>[lib.rs]"]
end

subgraph group_extensions["Extensions"]
  node_rhai["Rhai scripts<br/>[engine.rs]"]
  node_hotreload["Plugin hot reload<br/>[manager.rs]"]
  node_wasm["WASM plugins<br/>[plugin.rs]"]
end

subgraph group_infrastructure["LLM Infrastructure"]
  node_llm["LLM providers<br/>[client.rs]"]
  node_metering["Token metering"]
  node_persistence[("Usage storage")]
end

subgraph group_interfaces["Interfaces"]
  node_gateway["API gateway<br/>[server.rs]"]
  node_bindings["Language bindings<br/>[uniffi_bindings.rs]"]
  node_cli["CLI and TUI<br/>[main.rs]"]
end

subgraph group_operations["Operations"]
  node_dashboard["Monitoring dashboard<br/>[server.rs]"]
  node_billing["Credits and billing"]
end

node_user(("End user"))

node_user -->|"sends request"| node_agents
node_agents -->|"calls models"| node_llm
node_agents -->|"accounts tokens"| node_metering
node_metering -->|"persists usage"| node_persistence
node_agents -.->|"runs workflows"| node_workflows
node_agents -.->|"uses retrieval"| node_rag
node_agents -.->|"supports voice"| node_voice
node_rhai -->|"extends runtime"| node_kernel
node_hotreload -->|"extends runtime"| node_kernel
node_wasm -->|"extends runtime"| node_kernel
node_user -->|"sends API request"| node_gateway
node_gateway -.->|"routes requests"| node_agents
node_cli -.->|"runs agents"| node_agents
node_dashboard -->|"shows costs"| node_metering
node_bindings -->|"exposes core"| node_kernel
node_metering -.->|"feeds planned billing"| node_billing

click node_agents "https://github.com/mofa-org/mofa/blob/main/crates/mofa-foundation/src/llm/agent.rs"
click node_workflows "https://github.com/mofa-org/mofa/tree/main/crates/mofa-foundation/src/workflow"
click node_rag "https://github.com/mofa-org/mofa/blob/main/crates/mofa-kernel/src/rag/pipeline.rs"
click node_voice "https://github.com/mofa-org/mofa/blob/main/crates/mofa-foundation/src/orchestrator/pipeline.rs"
click node_kernel "https://github.com/mofa-org/mofa/blob/main/crates/mofa-kernel/src/lib.rs"
click node_rhai "https://github.com/mofa-org/mofa/blob/main/crates/mofa-extra/src/rhai/engine.rs"
click node_hotreload "https://github.com/mofa-org/mofa/blob/main/crates/mofa-plugins/src/hot_reload/manager.rs"
click node_wasm "https://github.com/mofa-org/mofa/blob/main/crates/mofa-plugins/src/wasm_runtime/plugin.rs"
click node_llm "https://github.com/mofa-org/mofa/blob/main/crates/mofa-foundation/src/llm/client.rs"
click node_metering "https://github.com/mofa-org/mofa/tree/main/crates/mofa-foundation/src/cost"
click node_persistence "https://github.com/mofa-org/mofa/tree/main/crates/mofa-foundation/src/persistence"
click node_gateway "https://github.com/mofa-org/mofa/blob/main/crates/mofa-gateway/src/openai_compat/server.rs"
click node_bindings "https://github.com/mofa-org/mofa/blob/main/crates/mofa-ffi/src/uniffi_bindings.rs"
click node_cli "https://github.com/mofa-org/mofa/blob/main/crates/mofa-cli/src/main.rs"
click node_dashboard "https://github.com/mofa-org/mofa/blob/main/crates/mofa-monitoring/src/dashboard/server.rs"

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_agents,node_workflows,node_rag,node_voice,node_kernel,node_user toneBlue
class node_rhai,node_hotreload,node_wasm toneAmber
class node_llm,node_metering,node_persistence toneMint
class node_gateway,node_bindings,node_cli toneRose
class node_dashboard,node_billing toneIndigo
```

## Components

### Agent Runtime

- [Agent execution](https://github.com/mofa-org/mofa/blob/main/crates/mofa-foundation/src/llm/agent.rs): `crates/mofa-foundation/src/llm/agent.rs`
- [Workflows](https://github.com/mofa-org/mofa/tree/main/crates/mofa-foundation/src/workflow): `crates/mofa-foundation/src/workflow`
- [RAG pipeline](https://github.com/mofa-org/mofa/blob/main/crates/mofa-kernel/src/rag/pipeline.rs): `crates/mofa-kernel/src/rag/pipeline.rs`
- [Voice inference](https://github.com/mofa-org/mofa/blob/main/crates/mofa-foundation/src/orchestrator/pipeline.rs): `crates/mofa-foundation/src/orchestrator/pipeline.rs`
- [Microkernel](https://github.com/mofa-org/mofa/blob/main/crates/mofa-kernel/src/lib.rs): `crates/mofa-kernel/src/lib.rs`

### Extensions

- [Rhai scripts](https://github.com/mofa-org/mofa/blob/main/crates/mofa-extra/src/rhai/engine.rs): `crates/mofa-extra/src/rhai/engine.rs`
- [Plugin hot reload](https://github.com/mofa-org/mofa/blob/main/crates/mofa-plugins/src/hot_reload/manager.rs): `crates/mofa-plugins/src/hot_reload/manager.rs`
- [WASM plugins](https://github.com/mofa-org/mofa/blob/main/crates/mofa-plugins/src/wasm_runtime/plugin.rs): `crates/mofa-plugins/src/wasm_runtime/plugin.rs`

### LLM Infrastructure

- [LLM providers](https://github.com/mofa-org/mofa/blob/main/crates/mofa-foundation/src/llm/client.rs): `crates/mofa-foundation/src/llm/client.rs`
- [Token metering](https://github.com/mofa-org/mofa/tree/main/crates/mofa-foundation/src/cost): `crates/mofa-foundation/src/cost`
- [Usage storage](https://github.com/mofa-org/mofa/tree/main/crates/mofa-foundation/src/persistence): `crates/mofa-foundation/src/persistence`

### Interfaces

- [API gateway](https://github.com/mofa-org/mofa/blob/main/crates/mofa-gateway/src/openai_compat/server.rs): `crates/mofa-gateway/src/openai_compat/server.rs`
- [Language bindings](https://github.com/mofa-org/mofa/blob/main/crates/mofa-ffi/src/uniffi_bindings.rs): `crates/mofa-ffi/src/uniffi_bindings.rs`
- [CLI and TUI](https://github.com/mofa-org/mofa/blob/main/crates/mofa-cli/src/main.rs): `crates/mofa-cli/src/main.rs`

### Operations

- [Monitoring dashboard](https://github.com/mofa-org/mofa/blob/main/crates/mofa-monitoring/src/dashboard/server.rs): `crates/mofa-monitoring/src/dashboard/server.rs`
- **Credits and billing**

### Other components

- **End user**

## Connections

- End user → Agent execution: sends request (evidence: `README.md`)
- Agent execution → LLM providers: calls models (evidence: `crates/mofa-foundation/src/llm/agent.rs`)
- Agent execution → Token metering: accounts tokens (evidence: `README.md`)
- Token metering → Usage storage: persists usage (evidence: `README.md`)
- Agent execution → Workflows: runs workflows
- Agent execution → RAG pipeline: uses retrieval
- Agent execution → Voice inference: supports voice
- Rhai scripts → Microkernel: extends runtime (evidence: `README.md`)
- Plugin hot reload → Microkernel: extends runtime (evidence: `README.md`)
- WASM plugins → Microkernel: extends runtime (evidence: `README.md`)
- End user → API gateway: sends API request (evidence: `README.md`)
- API gateway → Agent execution: routes requests
- CLI and TUI → Agent execution: runs agents
- Monitoring dashboard → Token metering: shows costs (evidence: `README.md`)
- Language bindings → Microkernel: exposes core (evidence: `README.md`)
- Token metering → Credits and billing: feeds planned billing (evidence: `README.md`)
