# materwan/clara architecture

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

- Interactive diagram: https://gitdiagram.com/materwan/clara
- Repository: https://github.com/materwan/clara

## Overview

Clara is a single-process HTTP AI assistant: clients authenticate and submit conversations, the server coordinates model turns, shared SQLite memory, projects, and optional connected-resource tools, then returns streamed or direct answers. The web app and Discord adapter are distinct clients; administrator and account-management functions are additional product branches. Major capabilities are represented using paths in the tree and README; unsampled implementations are linked only where the README or indexed source establishes the relationship.

Main entry points: [`src/clara/server.py`](https://github.com/materwan/clara/blob/main/src/clara/server.py) (HTTP API), [`src/clara/agent.py`](https://github.com/materwan/clara/blob/main/src/clara/agent.py) (Conversation agent), [`src/clara/integrations/broker.py`](https://github.com/materwan/clara/blob/main/src/clara/integrations/broker.py) (Tool broker), [`src/clara/discord_bot/handler.py`](https://github.com/materwan/clara/blob/main/src/clara/discord_bot/handler.py) (Discord adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Clients"]
  node_terminal["Terminal client<br/>[client.py]"]
  node_discord["Discord adapter<br/>[handler.py]"]
  node_discord_route["Message routing<br/>[routing.py]"]
  node_web["Web application<br/>[app.js]"]
  node_web_chat["Web chat<br/>[chat.js]"]
  node_discord_service["Discord service<br/>[service.py]"]
end

subgraph group_server["Server runtime"]
  node_http["HTTP API<br/>[server.py]"]
  node_agent["Conversation agent<br/>[agent.py]"]
  node_model["Model providers<br/>[providers.py]"]
end

subgraph group_memory["Memory and projects"]
  node_memory_store[("SQLite memory<br/>[memory.py]")]
  node_projects["Projects and files<br/>[projects.py]"]
  node_ingest["File ingestion<br/>[ingest.py]"]
end

subgraph group_integrations["Connected tools"]
  node_integrations_api["Integration API<br/>[integrationapi.py]"]
  node_broker["Tool broker<br/>[broker.py]"]
  node_permissions["Permission rules<br/>[permissions.py]"]
  node_integration_store[("Integration state<br/>[store.py]")]
  node_connectors["Resource connectors"]
  node_approvals["Approvals<br/>[approvals.py]"]
end

subgraph group_operations["Accounts and admin"]
  node_users["User accounts<br/>[users.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_tasks["Tasks and reminders<br/>[tasks.py]"]
  node_notifications["Notifications<br/>[notifications.py]"]
  node_web_admin["Web administration<br/>[admin.js]"]
end

node_person(("User"))
node_ollama_web["Ollama web tools"]

node_person -->|"asks"| node_terminal
node_terminal -->|"sends chat"| node_http
node_person -->|"uses"| node_web
node_web -->|"opens chat"| node_web_chat
node_web_chat -.->|"sends chat"| node_http
node_person -->|"messages"| node_discord
node_discord -->|"routes messages"| node_discord_route
node_discord -->|"forwards requests"| node_http
node_http -->|"runs turn"| node_agent
node_agent -.->|"requests completion"| node_model
node_agent -.->|"reads and writes"| node_memory_store
node_agent -.->|"uses project context"| node_projects
node_projects -->|"extracts files"| node_ingest
node_integrations_api -.->|"exposes tools"| node_broker
node_broker -->|"checks access"| node_permissions
node_broker -->|"loads resources"| node_integration_store
node_broker -->|"dispatches operations"| node_connectors
node_broker -->|"requests approval"| node_approvals
node_person -->|"signs in"| node_auth
node_auth -->|"checks accounts"| node_users
node_http -.->|"authenticates"| node_auth
node_person -->|"administers"| node_web_admin
node_web_admin -.->|"calls API"| node_http
node_person -.->|"manages tasks"| node_tasks
node_tasks -->|"persists state"| node_memory_store
node_tasks -->|"sends notices"| node_notifications
node_agent -.->|"uses web tools"| node_ollama_web
node_discord_service -->|"runs adapter"| node_discord

click node_terminal "https://github.com/materwan/clara/blob/main/src/clara/client.py"
click node_discord "https://github.com/materwan/clara/blob/main/src/clara/discord_bot/handler.py"
click node_discord_route "https://github.com/materwan/clara/blob/main/src/clara/discord_bot/routing.py"
click node_web "https://github.com/materwan/clara/blob/main/src/clara/web/app.js"
click node_web_chat "https://github.com/materwan/clara/blob/main/src/clara/web/chat.js"
click node_http "https://github.com/materwan/clara/blob/main/src/clara/server.py"
click node_agent "https://github.com/materwan/clara/blob/main/src/clara/agent.py"
click node_model "https://github.com/materwan/clara/blob/main/src/clara/providers.py"
click node_memory_store "https://github.com/materwan/clara/blob/main/src/clara/memory.py"
click node_projects "https://github.com/materwan/clara/blob/main/src/clara/projects.py"
click node_ingest "https://github.com/materwan/clara/blob/main/src/clara/ingest.py"
click node_integrations_api "https://github.com/materwan/clara/blob/main/src/clara/integrationapi.py"
click node_broker "https://github.com/materwan/clara/blob/main/src/clara/integrations/broker.py"
click node_permissions "https://github.com/materwan/clara/blob/main/src/clara/integrations/permissions.py"
click node_integration_store "https://github.com/materwan/clara/blob/main/src/clara/integrations/store.py"
click node_connectors "https://github.com/materwan/clara/tree/main/src/clara/integrations/connectors"
click node_approvals "https://github.com/materwan/clara/blob/main/src/clara/integrations/approvals.py"
click node_users "https://github.com/materwan/clara/blob/main/src/clara/users.py"
click node_auth "https://github.com/materwan/clara/blob/main/src/clara/auth.py"
click node_tasks "https://github.com/materwan/clara/blob/main/src/clara/tasks.py"
click node_notifications "https://github.com/materwan/clara/blob/main/src/clara/notifications.py"
click node_web_admin "https://github.com/materwan/clara/blob/main/src/clara/web/admin.js"
click node_discord_service "https://github.com/materwan/clara/blob/main/src/clara/discord_bot/service.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_terminal,node_discord,node_discord_route,node_web,node_web_chat,node_discord_service,node_person toneBlue
class node_http,node_agent,node_model toneAmber
class node_memory_store,node_projects,node_ingest toneMint
class node_integrations_api,node_broker,node_permissions,node_integration_store,node_connectors,node_approvals toneRose
class node_users,node_auth,node_tasks,node_notifications,node_web_admin,node_ollama_web toneIndigo
```

## Components

### Clients

- [Terminal client](https://github.com/materwan/clara/blob/main/src/clara/client.py): `src/clara/client.py`
- [Discord adapter](https://github.com/materwan/clara/blob/main/src/clara/discord_bot/handler.py): `src/clara/discord_bot/handler.py`
- [Message routing](https://github.com/materwan/clara/blob/main/src/clara/discord_bot/routing.py): `src/clara/discord_bot/routing.py`
- [Web application](https://github.com/materwan/clara/blob/main/src/clara/web/app.js): `src/clara/web/app.js`
- [Web chat](https://github.com/materwan/clara/blob/main/src/clara/web/chat.js): `src/clara/web/chat.js`
- [Discord service](https://github.com/materwan/clara/blob/main/src/clara/discord_bot/service.py): `src/clara/discord_bot/service.py`

### Server runtime

- [HTTP API](https://github.com/materwan/clara/blob/main/src/clara/server.py): `src/clara/server.py`
- [Conversation agent](https://github.com/materwan/clara/blob/main/src/clara/agent.py): `src/clara/agent.py`
- [Model providers](https://github.com/materwan/clara/blob/main/src/clara/providers.py): `src/clara/providers.py`

### Memory and projects

- [SQLite memory](https://github.com/materwan/clara/blob/main/src/clara/memory.py): `src/clara/memory.py`
- [Projects and files](https://github.com/materwan/clara/blob/main/src/clara/projects.py): `src/clara/projects.py`
- [File ingestion](https://github.com/materwan/clara/blob/main/src/clara/ingest.py): `src/clara/ingest.py`

### Connected tools

- [Integration API](https://github.com/materwan/clara/blob/main/src/clara/integrationapi.py): `src/clara/integrationapi.py`
- [Tool broker](https://github.com/materwan/clara/blob/main/src/clara/integrations/broker.py): `src/clara/integrations/broker.py`
- [Permission rules](https://github.com/materwan/clara/blob/main/src/clara/integrations/permissions.py): `src/clara/integrations/permissions.py`
- [Integration state](https://github.com/materwan/clara/blob/main/src/clara/integrations/store.py): `src/clara/integrations/store.py`
- [Resource connectors](https://github.com/materwan/clara/tree/main/src/clara/integrations/connectors): `src/clara/integrations/connectors`
- [Approvals](https://github.com/materwan/clara/blob/main/src/clara/integrations/approvals.py): `src/clara/integrations/approvals.py`

### Accounts and admin

- [User accounts](https://github.com/materwan/clara/blob/main/src/clara/users.py): `src/clara/users.py`
- [Authentication](https://github.com/materwan/clara/blob/main/src/clara/auth.py): `src/clara/auth.py`
- [Tasks and reminders](https://github.com/materwan/clara/blob/main/src/clara/tasks.py): `src/clara/tasks.py`
- [Notifications](https://github.com/materwan/clara/blob/main/src/clara/notifications.py): `src/clara/notifications.py`
- [Web administration](https://github.com/materwan/clara/blob/main/src/clara/web/admin.js): `src/clara/web/admin.js`

### Other components

- **User**
- **Ollama web tools**

## Connections

- User → Terminal client: asks
- Terminal client → HTTP API: sends chat
- User → Web application: uses
- Web application → Web chat: opens chat (evidence: `src/clara/web/app.js`)
- Web chat → HTTP API: sends chat
- User → Discord adapter: messages
- Discord adapter → Message routing: routes messages (evidence: `src/clara/discord_bot/handler.py`)
- Discord adapter → HTTP API: forwards requests
- HTTP API → Conversation agent: runs turn (evidence: `src/clara/server.py`)
- Conversation agent → Model providers: requests completion
- Conversation agent → SQLite memory: reads and writes
- Conversation agent → Projects and files: uses project context
- Projects and files → File ingestion: extracts files (evidence: `src/clara/projects.py`)
- Integration API → Tool broker: exposes tools
- Tool broker → Permission rules: checks access (evidence: `src/clara/integrations/broker.py`)
- Tool broker → Integration state: loads resources (evidence: `src/clara/integrations/broker.py`)
- Tool broker → Resource connectors: dispatches operations (evidence: `src/clara/integrations/broker.py`)
- Tool broker → Approvals: requests approval (evidence: `src/clara/integrations/broker.py`)
- User → Authentication: signs in
- Authentication → User accounts: checks accounts (evidence: `src/clara/auth.py`)
- HTTP API → Authentication: authenticates (evidence: `src/clara/server.py`)
- User → Web administration: administers
- Web administration → HTTP API: calls API
- User → Tasks and reminders: manages tasks
- Tasks and reminders → SQLite memory: persists state (evidence: `src/clara/tasks.py`)
- Tasks and reminders → Notifications: sends notices (evidence: `src/clara/tasks.py`)
- Conversation agent → Ollama web tools: uses web tools
- Discord service → Discord adapter: runs adapter (evidence: `src/clara/discord_bot/service.py`)
