# lschaffer/tealkit architecture

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

- Interactive diagram: https://gitdiagram.com/lschaffer/tealkit
- Repository: https://github.com/lschaffer/tealkit

## Overview

#### Purpose and Entry Points
TealKit is a privacy-oriented, cross-platform agentic AI system: a local Flutter client creates, tests, schedules, and monitors workflows; an optional headless Dart server runs them continuously. Main entry points are the Flutter app at `src/lib/main.dart` and server daemon at `src/server/bin/tealkit_server.dart`. Deployment is Docker-oriented through `src/server/Dockerfile` and `src/server/docker-compose.yml`.

#### Client Application and UI State
The Flutter client presents the playground, workflow editors/list, interactive chat, settings, and visual pipeline builder. UI state is provider-backed and separates active task, LLM configuration, external tools, data sources, and local/remote server mode.
- `src/lib/screens/playground_screen.dart`
- `src/lib/screens/workflow_edit_screen.dart`
- `src/lib/providers/server_mode_provider.dart`

The client can execute locally or switch repositories/API clients to a configured headless server boundary.

#### Workflow Model, Persistence, and Execution
Workflows are modeled as tasks with steps, tool selection, LLM settings, schedules, outputs, and chained/conditional follow-on tasks. The local execution path coordinates prompt steps, tool calls, task outputs, delivery, and scheduling.
- `src/lib/models/workflow_task.dart`
- `src/lib/services/task_runner_service.dart`
- `src/lib/services/scheduler_service.dart`

Persistence is abstracted behind task repositories, allowing the same workflow-oriented UI to target local DuckDB or remote server APIs.
- `src/lib/repositories/i_task_repository.dart`
- `src/lib/repositories/local_task_repository.dart`
- `src/lib/repositories/remote_task_repository.dart`

#### LLM and Prompt Orchestration
LLM access is provider-independent, supporting configured remote providers/local OpenAI-compatible endpoints and embedded GGUF inference. Task execution can use multi-step prompts, passing prior raw tool/LLM results forward; workflow chaining passes completed task results to downstream workflows.
- `src/lib/services/llm_service.dart`
- `src/lib/services/embedded_llm/embedded_llm_adapter.dart`
- `src/lib/services/function_hint_generation_service.dart`

Function hints and tool usage rules form the model-facing contract that constrains and explains available operations.
- `src/lib/models/function_hint.dart`
- `src/lib/config/tool_usage_rules.dart`

#### Tool and MCP Integration Boundary
Tools are normalized through MCP clients/managers and an internal MCP registry. Built-in servers cover files, documents, Excel/PDF/chart generation, Gmail/Google services, web search, weather, SSH, shell, JavaScript/Python/PowerShell bridges, GitHub, and Home Assistant.
- `src/lib/services/multi_mcp_manager.dart`
- `src/lib/mcp/internal_mcp_registry.dart`
- `src/lib/utils/tool_router.dart`

External MCP servers may be remote or locally launched runtimes; registry/discovery and GitHub installation services manage this extensibility boundary.
- `src/lib/services/mcp_client.dart`
- `src/lib/services/github_mcp_runtime_service.dart`
- `src/lib/services/github_mcp_registry_service.dart`

#### Headless Server Runtime
The server owns its own DuckDB state, encrypted secrets, workflow runner, scheduler, tool registry, and server-side LLM/MCP adapters. It exposes the remote execution/control plane consumed by the client API package.
- `src/server/lib/runner/server_task_runner.dart`
- `src/server/lib/scheduler/server_scheduler.dart`
- `src/server/lib/database/server_duckdb_service.dart`

Server configuration, persistent database/output volumes, and encrypted credentials reside under `src/server/config/` and `src/server/data/`. Container deployment supports local, production, and WSL2 compose variants.

#### External Services and Offline Assets
Primary integrations include Gemini, OpenAI-compatible APIs, Anthropic, Mistral, Ollama/LM Studio, Hugging Face GGUF downloads, Gmail/Google Calendar/Drive, IMAP/SMTP, SSH/SFTP, SerpApi/DuckDuckGo, Slack/WhatsApp delivery, and remote MCP endpoints. DuckDB backs local/server workflow and RAG-style data storage; vendored native support exists in `src/third_party/dart_duckdb/`.

A separate Python training area produces and validates tool-calling datasets/contracts and LoRA-oriented artifacts; it is not on the application request path.
- `training/common/py/dataset/train_dataset_cli.py`
- `training/quality_gate/py/quality_gate.py`
- `training/train/py/train_lora.py`

Main entry points: [`src/server/lib/runner/server_task_runner.dart`](https://github.com/lschaffer/tealkit/blob/master/src/server/lib/runner/server_task_runner.dart) (Server workflow runner), [`src/lib/screens/playground_screen.dart`](https://github.com/lschaffer/tealkit/blob/master/src/lib/screens/playground_screen.dart) (Playground and editors), [`src/lib/services/task_runner_service.dart`](https://github.com/lschaffer/tealkit/blob/master/src/lib/services/task_runner_service.dart) (Local task runner), [`src/server/bin/tealkit_server.dart`](https://github.com/lschaffer/tealkit/blob/master/src/server/bin/tealkit_server.dart) (Server daemon)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Flutter client"]
  node_flutter_entry["Flutter app<br/>entry point<br/>[main.dart]"]
  node_ui["Playground and editors<br/>Flutter UI"]
  node_server_mode["Server mode<br/>provider state"]
  node_workflow_model["Workflow task<br/>workflow model<br/>[workflow_task.dart]"]
  node_task_repositories["Task repositories<br/>persistence abstraction"]
  node_local_repository[("Local task repository<br/>DuckDB repository")]
  node_remote_repository["Remote task repository<br/>server API client"]
  node_local_runner["Local task runner<br/>workflow executor"]
  node_local_scheduler["Local scheduler"]
end

subgraph group_server["Headless server"]
  node_server_entry["Server daemon<br/>Dart entry point"]
  node_server_runner["Server workflow runner<br/>workflow executor"]
  node_server_scheduler["Server scheduler"]
  node_server_state[("Server DuckDB state<br/>workflow database")]
  node_container_deployment{{"Docker deployment<br/>container deployment"}}
end

subgraph group_integrations["AI and tool boundary"]
  node_llm_orchestration["LLM orchestration<br/>LLM service<br/>[llm_service.dart]"]
  node_embedded_llm["Embedded GGUF inference<br/>local LLM adapter"]
  node_tool_contract["Function hints and rules<br/>model tool contract"]
  node_mcp_manager["MCP tool manager<br/>tool integration manager"]
  node_mcp_registry["Internal MCP registry<br/>tool registry"]
end

subgraph group_training["Training pipeline"]
  node_dataset_cli["Dataset builder<br/>Python CLI"]
  node_quality_gate["Contract quality gate<br/>Python validation<br/>[quality_gate.py]"]
  node_lora_training["LoRA training<br/>Python training<br/>[train_lora.py]"]
end

node_flutter_entry -->|"renders"| node_ui
node_ui -->|"selects mode"| node_server_mode
node_ui -->|"edits"| node_workflow_model
node_ui -->|"loads and saves"| node_task_repositories
node_server_mode -->|"local mode"| node_local_repository
node_server_mode -->|"remote mode"| node_remote_repository
node_task_repositories -->|"implemented by"| node_local_repository
node_task_repositories -->|"implemented by"| node_remote_repository
node_workflow_model -->|"executes locally"| node_local_runner
node_local_scheduler -->|"triggers"| node_local_runner
node_local_runner -->|"runs prompts"| node_llm_orchestration
node_local_runner -->|"calls tools"| node_mcp_manager
node_llm_orchestration -->|"can use"| node_embedded_llm
node_tool_contract -->|"guides tool use"| node_llm_orchestration
node_mcp_manager -->|"resolves built-ins"| node_mcp_registry
node_remote_repository -->|"remote control plane"| node_server_entry
node_server_entry -->|"hosts"| node_server_runner
node_server_entry -->|"hosts"| node_server_scheduler
node_server_runner -->|"persists state"| node_server_state
node_server_scheduler -->|"triggers"| node_server_runner
node_server_runner -.->|"uses LLM adapters"| node_llm_orchestration
node_server_runner -.->|"uses tool adapters"| node_mcp_manager
node_container_deployment -->|"deploys"| node_server_entry
node_dataset_cli -->|"validates datasets"| node_quality_gate
node_quality_gate -->|"approved data"| node_lora_training

click node_flutter_entry "https://github.com/lschaffer/tealkit/blob/master/src/lib/main.dart"
click node_ui "https://github.com/lschaffer/tealkit/blob/master/src/lib/screens/playground_screen.dart"
click node_server_mode "https://github.com/lschaffer/tealkit/blob/master/src/lib/providers/server_mode_provider.dart"
click node_workflow_model "https://github.com/lschaffer/tealkit/blob/master/src/lib/models/workflow_task.dart"
click node_task_repositories "https://github.com/lschaffer/tealkit/blob/master/src/lib/repositories/i_task_repository.dart"
click node_local_repository "https://github.com/lschaffer/tealkit/blob/master/src/lib/repositories/local_task_repository.dart"
click node_remote_repository "https://github.com/lschaffer/tealkit/blob/master/src/lib/repositories/remote_task_repository.dart"
click node_local_runner "https://github.com/lschaffer/tealkit/blob/master/src/lib/services/task_runner_service.dart"
click node_local_scheduler "https://github.com/lschaffer/tealkit/blob/master/src/lib/services/scheduler_service.dart"
click node_llm_orchestration "https://github.com/lschaffer/tealkit/blob/master/src/lib/services/llm_service.dart"
click node_embedded_llm "https://github.com/lschaffer/tealkit/blob/master/src/lib/services/embedded_llm/embedded_llm_adapter.dart"
click node_tool_contract "https://github.com/lschaffer/tealkit/blob/master/src/lib/services/function_hint_generation_service.dart"
click node_mcp_manager "https://github.com/lschaffer/tealkit/blob/master/src/lib/services/multi_mcp_manager.dart"
click node_mcp_registry "https://github.com/lschaffer/tealkit/blob/master/src/lib/mcp/internal_mcp_registry.dart"
click node_server_entry "https://github.com/lschaffer/tealkit/blob/master/src/server/bin/tealkit_server.dart"
click node_server_runner "https://github.com/lschaffer/tealkit/blob/master/src/server/lib/runner/server_task_runner.dart"
click node_server_scheduler "https://github.com/lschaffer/tealkit/blob/master/src/server/lib/scheduler/server_scheduler.dart"
click node_server_state "https://github.com/lschaffer/tealkit/blob/master/src/server/lib/database/server_duckdb_service.dart"
click node_container_deployment "https://github.com/lschaffer/tealkit/blob/master/src/server/Dockerfile"
click node_dataset_cli "https://github.com/lschaffer/tealkit/blob/master/training/common/py/dataset/train_dataset_cli.py"
click node_quality_gate "https://github.com/lschaffer/tealkit/blob/master/training/quality_gate/py/quality_gate.py"
click node_lora_training "https://github.com/lschaffer/tealkit/blob/master/training/train/py/train_lora.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_flutter_entry,node_ui,node_server_mode,node_workflow_model,node_task_repositories,node_local_repository,node_remote_repository,node_local_runner,node_local_scheduler toneBlue
class node_server_entry,node_server_runner,node_server_scheduler,node_server_state,node_container_deployment toneAmber
class node_llm_orchestration,node_embedded_llm,node_tool_contract,node_mcp_manager,node_mcp_registry toneMint
class node_dataset_cli,node_quality_gate,node_lora_training toneRose
```

## Components

### Flutter client

- [Flutter app](https://github.com/lschaffer/tealkit/blob/master/src/lib/main.dart): entry point · `src/lib/main.dart`
- [Playground and editors](https://github.com/lschaffer/tealkit/blob/master/src/lib/screens/playground_screen.dart): Flutter UI · Workflow editing, chat, settings, and visual pipeline views. · `src/lib/screens/playground_screen.dart`
- [Server mode](https://github.com/lschaffer/tealkit/blob/master/src/lib/providers/server_mode_provider.dart): provider state · Selects local repositories or the remote server boundary. · `src/lib/providers/server_mode_provider.dart`
- [Workflow task](https://github.com/lschaffer/tealkit/blob/master/src/lib/models/workflow_task.dart): workflow model · Tasks contain steps, tools, LLM settings, schedules, outputs, and follow-ons. · `src/lib/models/workflow_task.dart`
- [Task repositories](https://github.com/lschaffer/tealkit/blob/master/src/lib/repositories/i_task_repository.dart): persistence abstraction · Common local and remote workflow access contract. · `src/lib/repositories/i_task_repository.dart`
- [Local task repository](https://github.com/lschaffer/tealkit/blob/master/src/lib/repositories/local_task_repository.dart): DuckDB repository · `src/lib/repositories/local_task_repository.dart`
- [Remote task repository](https://github.com/lschaffer/tealkit/blob/master/src/lib/repositories/remote_task_repository.dart): server API client · `src/lib/repositories/remote_task_repository.dart`
- [Local task runner](https://github.com/lschaffer/tealkit/blob/master/src/lib/services/task_runner_service.dart): workflow executor · Coordinates prompt steps, tools, outputs, delivery, and chained tasks. · `src/lib/services/task_runner_service.dart`
- [Local scheduler](https://github.com/lschaffer/tealkit/blob/master/src/lib/services/scheduler_service.dart): scheduler · `src/lib/services/scheduler_service.dart`

### Headless server

- [Server daemon](https://github.com/lschaffer/tealkit/blob/master/src/server/bin/tealkit_server.dart): Dart entry point · `src/server/bin/tealkit_server.dart`
- [Server workflow runner](https://github.com/lschaffer/tealkit/blob/master/src/server/lib/runner/server_task_runner.dart): workflow executor · Continuously executes remotely controlled workflows. · `src/server/lib/runner/server_task_runner.dart`
- [Server scheduler](https://github.com/lschaffer/tealkit/blob/master/src/server/lib/scheduler/server_scheduler.dart): scheduler · `src/server/lib/scheduler/server_scheduler.dart`
- [Server DuckDB state](https://github.com/lschaffer/tealkit/blob/master/src/server/lib/database/server_duckdb_service.dart): workflow database · Server-owned workflow state, outputs, and encrypted-secret context. · `src/server/lib/database/server_duckdb_service.dart`
- [Docker deployment](https://github.com/lschaffer/tealkit/blob/master/src/server/Dockerfile): container deployment · Supports persistent server state and compose-based deployment variants. · `src/server/Dockerfile`

### AI and tool boundary

- [LLM orchestration](https://github.com/lschaffer/tealkit/blob/master/src/lib/services/llm_service.dart): LLM service · Runs provider-independent multi-step prompts and forwards prior results. · `src/lib/services/llm_service.dart`
- [Embedded GGUF inference](https://github.com/lschaffer/tealkit/blob/master/src/lib/services/embedded_llm/embedded_llm_adapter.dart): local LLM adapter · `src/lib/services/embedded_llm/embedded_llm_adapter.dart`
- [Function hints and rules](https://github.com/lschaffer/tealkit/blob/master/src/lib/services/function_hint_generation_service.dart): model tool contract · Constrains and explains available operations to models. · `src/lib/services/function_hint_generation_service.dart`
- [MCP tool manager](https://github.com/lschaffer/tealkit/blob/master/src/lib/services/multi_mcp_manager.dart): tool integration manager · Normalizes built-in, remote, and locally launched tool runtimes. · `src/lib/services/multi_mcp_manager.dart`
- [Internal MCP registry](https://github.com/lschaffer/tealkit/blob/master/src/lib/mcp/internal_mcp_registry.dart): tool registry · Built-in tools span files, cloud services, code bridges, search, and automation. · `src/lib/mcp/internal_mcp_registry.dart`

### Training pipeline

Offline dataset and LoRA artifact production.

- [Dataset builder](https://github.com/lschaffer/tealkit/blob/master/training/common/py/dataset/train_dataset_cli.py): Python CLI · `training/common/py/dataset/train_dataset_cli.py`
- [Contract quality gate](https://github.com/lschaffer/tealkit/blob/master/training/quality_gate/py/quality_gate.py): Python validation · `training/quality_gate/py/quality_gate.py`
- [LoRA training](https://github.com/lschaffer/tealkit/blob/master/training/train/py/train_lora.py): Python training · Produces offline fine-tuning artifacts. · `training/train/py/train_lora.py`

## Connections

- Flutter app → Playground and editors: renders
- Playground and editors → Server mode: selects mode
- Playground and editors → Workflow task: edits
- Playground and editors → Task repositories: loads and saves
- Server mode → Local task repository: local mode
- Server mode → Remote task repository: remote mode
- Task repositories → Local task repository: implemented by
- Task repositories → Remote task repository: implemented by
- Workflow task → Local task runner: executes locally
- Local scheduler → Local task runner: triggers
- Local task runner → LLM orchestration: runs prompts
- Local task runner → MCP tool manager: calls tools
- LLM orchestration → Embedded GGUF inference: can use
- Function hints and rules → LLM orchestration: guides tool use
- MCP tool manager → Internal MCP registry: resolves built-ins
- Remote task repository → Server daemon: remote control plane
- Server daemon → Server workflow runner: hosts
- Server daemon → Server scheduler: hosts
- Server workflow runner → Server DuckDB state: persists state
- Server scheduler → Server workflow runner: triggers
- Server workflow runner → LLM orchestration: uses LLM adapters
- Server workflow runner → MCP tool manager: uses tool adapters
- Docker deployment → Server daemon: deploys
- Dataset builder → Contract quality gate: validates datasets
- Contract quality gate → LoRA training: approved data
