# rvbyy/a1-libi architecture

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

- Interactive diagram: https://gitdiagram.com/rvbyy/a1-libi
- Repository: https://github.com/rvbyy/a1-libi

## Overview

A1Libi is a local AI assistant built on GalèreLM, with a CLI and a documented Gradio web interface. In the principal workflow, a user starts a session and submits a prompt; the engine applies intent checks, builds a prompt using short- and long-term memory and available tools, calls local Ollama, executes requested tools, and persists the conversation. The README also documents anti-hallucination retries and configuration-based model selection. Source evidence is partial, so edges for unsampled integrations and web wiring are omitted where their callers are not established.

Main entry points: [`src/main.py`](https://github.com/rvbyy/a1-libi/blob/main/src/main.py) (CLI application), [`src/galerelm/engine.py`](https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/engine.py) (Chat engine), [`src/repl.py`](https://github.com/rvbyy/a1-libi/blob/main/src/repl.py) (Chat REPL), [`src/galerelm/rag.py`](https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/rag.py) (Long-term memory RAG)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User interfaces"]
  node_cli["CLI application<br/>[main.py]"]
  node_repl["Chat REPL<br/>[repl.py]"]
  node_web["Web interface"]
  node_commands["CLI commands"]
end

subgraph group_conversation["Conversation engine"]
  node_engine["Chat engine<br/>[engine.py]"]
  node_guard["Intent guardrail"]
  node_workflow["Anti-hallucination graph<br/>[graph.py]"]
  node_prompt["Prompt construction<br/>[prompt.py]"]
  node_chat["Chat and messages<br/>[chat.py]"]
end

subgraph group_memory["Session and memory"]
  node_session["Session and profiles<br/>[session_manager.py]"]
  node_database[("Database<br/>[database.py]")]
  node_context["Conversation context<br/>[context.py]"]
  node_rag["Long-term memory RAG<br/>[rag.py]"]
  node_deepcontext["Long-term memory models<br/>[deep_context.py]"]
end

subgraph group_tools["Tools and scheduling"]
  node_registry["Tool registry and executor<br/>[registry.py]"]
  node_toolcontract["Tool contract<br/>[ITools.py]"]
  node_toolsets["Built-in tool sets"]
  node_taskmanager["Scheduled task manager<br/>[task_manager.py]"]
  node_scheduler["Task runner<br/>[runner.py]"]
end

subgraph group_integration["Model integration"]
  node_config["Configuration<br/>[config.py]"]
  node_api["Ollama HTTP client<br/>[client.py]"]
end

node_user(("User"))
node_ollama(("Ollama service"))

node_user -->|"starts chat"| node_cli
node_user -->|"uses interface"| node_web
node_cli -->|"assembles"| node_engine
node_cli -->|"loads profile"| node_session
node_cli -->|"initializes"| node_database
node_cli -->|"starts"| node_repl
node_repl -->|"dispatches"| node_commands
node_repl -->|"streams chat"| node_engine
node_cli -->|"configures"| node_guard
node_cli -->|"enables"| node_workflow
node_engine -->|"classifies prompt"| node_guard
node_engine -->|"runs workflow"| node_workflow
node_engine -->|"builds prompt"| node_prompt
node_engine -->|"prepares chat"| node_chat
node_engine -->|"executes tool calls"| node_registry
node_engine -->|"updates conversation"| node_context
node_engine -->|"requests model"| node_api
node_prompt -.->|"uses memories"| node_rag
node_deepcontext -->|"delegates search"| node_rag
node_rag -->|"archives memories"| node_deepcontext
node_session -.->|"persists sessions"| node_database
node_cli -->|"creates"| node_taskmanager
node_cli -->|"starts"| node_scheduler
node_scheduler -->|"gets due tasks"| node_taskmanager
node_taskmanager -->|"persists tasks"| node_database
node_registry -->|"executes implementations"| node_toolcontract
node_toolsets -.->|"implements"| node_toolcontract
node_config -->|"configures startup"| node_cli
node_api -.->|"sends HTTP requests"| node_ollama
node_web -.->|"serves chat"| node_engine

click node_cli "https://github.com/rvbyy/a1-libi/blob/main/src/main.py"
click node_repl "https://github.com/rvbyy/a1-libi/blob/main/src/repl.py"
click node_web "https://github.com/rvbyy/a1-libi/tree/main/src/webapp"
click node_engine "https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/engine.py"
click node_guard "https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/intent_classifier.py"
click node_workflow "https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/graph.py"
click node_prompt "https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/models/prompt.py"
click node_chat "https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/models/chat.py"
click node_commands "https://github.com/rvbyy/a1-libi/tree/main/src/commands"
click node_session "https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/session_manager.py"
click node_database "https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/database.py"
click node_context "https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/models/context.py"
click node_rag "https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/rag.py"
click node_deepcontext "https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/models/deep_context.py"
click node_registry "https://github.com/rvbyy/a1-libi/blob/main/src/tools/registry.py"
click node_toolcontract "https://github.com/rvbyy/a1-libi/blob/main/src/tools/ITools.py"
click node_toolsets "https://github.com/rvbyy/a1-libi/tree/main/src/tools"
click node_taskmanager "https://github.com/rvbyy/a1-libi/blob/main/src/scheduler/task_manager.py"
click node_scheduler "https://github.com/rvbyy/a1-libi/blob/main/src/scheduler/runner.py"
click node_config "https://github.com/rvbyy/a1-libi/blob/main/src/config.py"
click node_api "https://github.com/rvbyy/a1-libi/blob/main/src/rapideAPI/client.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_cli,node_repl,node_web,node_commands,node_user toneBlue
class node_engine,node_guard,node_workflow,node_prompt,node_chat toneAmber
class node_session,node_database,node_context,node_rag,node_deepcontext toneMint
class node_registry,node_toolcontract,node_toolsets,node_taskmanager,node_scheduler toneRose
class node_config,node_api,node_ollama toneIndigo
```

## Components

### User interfaces

- [CLI application](https://github.com/rvbyy/a1-libi/blob/main/src/main.py): `src/main.py`
- [Chat REPL](https://github.com/rvbyy/a1-libi/blob/main/src/repl.py): `src/repl.py`
- [Web interface](https://github.com/rvbyy/a1-libi/tree/main/src/webapp): `src/webapp`
- [CLI commands](https://github.com/rvbyy/a1-libi/tree/main/src/commands): `src/commands`

### Conversation engine

- [Chat engine](https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/engine.py): `src/galerelm/engine.py`
- [Intent guardrail](https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/intent_classifier.py): `src/galerelm/intent_classifier.py`
- [Anti-hallucination graph](https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/graph.py): `src/galerelm/graph.py`
- [Prompt construction](https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/models/prompt.py): `src/galerelm/models/prompt.py`
- [Chat and messages](https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/models/chat.py): `src/galerelm/models/chat.py`

### Session and memory

- [Session and profiles](https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/session_manager.py): `src/galerelm/session_manager.py`
- [Database](https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/database.py): `src/galerelm/database.py`
- [Conversation context](https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/models/context.py): `src/galerelm/models/context.py`
- [Long-term memory RAG](https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/rag.py): `src/galerelm/rag.py`
- [Long-term memory models](https://github.com/rvbyy/a1-libi/blob/main/src/galerelm/models/deep_context.py): `src/galerelm/models/deep_context.py`

### Tools and scheduling

- [Tool registry and executor](https://github.com/rvbyy/a1-libi/blob/main/src/tools/registry.py): `src/tools/registry.py`
- [Tool contract](https://github.com/rvbyy/a1-libi/blob/main/src/tools/ITools.py): `src/tools/ITools.py`
- [Built-in tool sets](https://github.com/rvbyy/a1-libi/tree/main/src/tools): `src/tools`
- [Scheduled task manager](https://github.com/rvbyy/a1-libi/blob/main/src/scheduler/task_manager.py): `src/scheduler/task_manager.py`
- [Task runner](https://github.com/rvbyy/a1-libi/blob/main/src/scheduler/runner.py): `src/scheduler/runner.py`

### Model integration

- [Configuration](https://github.com/rvbyy/a1-libi/blob/main/src/config.py): `src/config.py`
- [Ollama HTTP client](https://github.com/rvbyy/a1-libi/blob/main/src/rapideAPI/client.py): `src/rapideAPI/client.py`

### Other components

- **User**
- **Ollama service**

## Connections

- User → CLI application: starts chat
- User → Web interface: uses interface
- CLI application → Chat engine: assembles (evidence: `src/main.py`)
- CLI application → Session and profiles: loads profile (evidence: `src/main.py`)
- CLI application → Database: initializes (evidence: `src/main.py`)
- CLI application → Chat REPL: starts (evidence: `src/main.py`)
- Chat REPL → CLI commands: dispatches (evidence: `src/repl.py`)
- Chat REPL → Chat engine: streams chat (evidence: `src/repl.py`)
- CLI application → Intent guardrail: configures (evidence: `src/main.py`)
- CLI application → Anti-hallucination graph: enables (evidence: `src/main.py`)
- Chat engine → Intent guardrail: classifies prompt (evidence: `src/galerelm/engine.py`)
- Chat engine → Anti-hallucination graph: runs workflow (evidence: `src/galerelm/engine.py`)
- Chat engine → Prompt construction: builds prompt (evidence: `src/galerelm/engine.py`)
- Chat engine → Chat and messages: prepares chat (evidence: `src/galerelm/engine.py`)
- Chat engine → Tool registry and executor: executes tool calls (evidence: `src/galerelm/engine.py`)
- Chat engine → Conversation context: updates conversation (evidence: `src/galerelm/engine.py`)
- Chat engine → Ollama HTTP client: requests model (evidence: `src/galerelm/engine.py`)
- Prompt construction → Long-term memory RAG: uses memories
- Long-term memory models → Long-term memory RAG: delegates search (evidence: `src/galerelm/models/deep_context.py`)
- Long-term memory RAG → Long-term memory models: archives memories (evidence: `src/galerelm/models/deep_context.py`)
- Session and profiles → Database: persists sessions
- CLI application → Scheduled task manager: creates (evidence: `src/main.py`)
- CLI application → Task runner: starts (evidence: `src/main.py`)
- Task runner → Scheduled task manager: gets due tasks (evidence: `src/scheduler/runner.py`)
- Scheduled task manager → Database: persists tasks (evidence: `src/scheduler/task_manager.py`)
- Tool registry and executor → Tool contract: executes implementations (evidence: `src/tools/registry.py`)
- Built-in tool sets → Tool contract: implements (evidence: `src/tools/registry.py`)
- Configuration → CLI application: configures startup (evidence: `src/main.py`)
- Ollama HTTP client → Ollama service: sends HTTP requests
- Web interface → Chat engine: serves chat
