# aotol/ai_automation architecture

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

- Interactive diagram: https://gitdiagram.com/aotol/ai_automation
- Repository: https://github.com/aotol/ai_automation

## Overview

#### Purpose and Entry Points
Node.js CLI framework for controlled AI automation: an LLM may choose approved skills and fill parameters, while code validates and executes every transition. CLI and admin workflow commands enter via `src/app.js`; programmatic callers construct `TaskEngine` from `src/task-engine.js`.

#### Composition Root and Runtime Services
Configuration is loaded from `config.json` through `src/config.js`. The runtime is Node.js 18+, with Ollama as the local LLM endpoint, SQLite for durable state, and optional SMTP/IMAP email infrastructure. `src/logger.js` provides operational event logging.

#### Task Orchestration State Machine
`src/task-engine.js` owns the task lifecycle: normalize input, locate/reuse or create a workflow, build step payloads, execute steps serially, validate outputs, persist progress, and return task/workflow/step results. It is the trust boundary: LLM output informs plans but never directly controls arbitrary execution.

#### Input, Planning, and Guardrails
`src/input-provider.js` accepts and bounds raw requests. `src/prompt-builder.js` creates restricted planning and parameter-filling prompts from registered skills and prior context; `src/llm-provider.js` invokes Ollama. `src/validators.js` validates structured LLM responses and state transitions. New plans are limited to known skill names and can produce parameter-retrieval guardrails for retries on later matching inputs.

#### Dynamic Skill Registry and Execution
`src/skills-loader.js` discovers skill modules under `src/skills/`; `src/skill-utils.js` supports their shared execution/data behavior. Each skill exposes a named atomic operation, payload schema, executor, and result validator. Representative boundary-facing skills include web acquisition (`src/skills/fetch_url.js`, `src/skills/search_web.js`), content processing (`src/skills/extract_text_from_html.js`, `src/skills/summarize_text.js`, `src/skills/translate_text.js`), and email I/O (`src/skills/receive_email.js`, `src/skills/send_email.js`).

#### Data Flow Between Steps
A request becomes a normalized reusable template, then an ordered skill plan. For each plan item, payload filling receives the raw request, skill payload definition, and accumulated prior outputs. Step results become execution context for downstream skills, are validated after execution, and are persisted. The final result contains identifiers, workflow provenance, normalized template, plan, and step outputs.

#### Persistence and Workflow Governance
`src/task-repository.js` encapsulates SQLite initialization and access for tasks, ordered task steps, events, and workflow templates. Templates are keyed by normalized request patterns and carry active/inactive/rejected status. Active templates bypass planning; inactive matches require administrative approval; execution failures may inactivate reusable workflows. Admin controls are routed through `src/app.js`.

Main entry points: [`src/task-engine.js`](https://github.com/aotol/ai_automation/blob/main/src/task-engine.js) (TaskEngine), [`src/skills-loader.js`](https://github.com/aotol/ai_automation/blob/main/src/skills-loader.js) (Skills loader), [`src/skills/fetch_url.js`](https://github.com/aotol/ai_automation/blob/main/src/skills/fetch_url.js) (Web acquisition skills), [`src/skills/receive_email.js`](https://github.com/aotol/ai_automation/blob/main/src/skills/receive_email.js) (Email I/O skills)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry &amp; Control"]
  node_cli["CLI &amp; admin commands<br/>Node.js entrypoint<br/>[app.js]"]
  node_config["Configuration<br/>runtime config<br/>[config.js]"]
  node_logger["Operational logger<br/>logging<br/>[logger.js]"]
end

subgraph group_orchestration["Task Orchestration"]
  node_engine{{"TaskEngine<br/>orchestrator<br/>[task-engine.js]"}}
  node_input["Input provider<br/>request boundary<br/>[input-provider.js]"]
end

subgraph group_ai["AI Planning &amp; Validation"]
  node_prompts["Prompt builder<br/>prompt policy<br/>[prompt-builder.js]"]
  node_llm["LLM provider<br/>Ollama client<br/>[llm-provider.js]"]
  node_validators{{"Validators<br/>guardrails<br/>[validators.js]"}}
  node_ollama(("Ollama endpoint<br/>local LLM runtime"))
end

subgraph group_skills["Skill Execution"]
  node_skill_loader["Skills loader<br/>dynamic registry<br/>[skills-loader.js]"]
  node_skill_utils["Skill utilities<br/>shared skill support<br/>[skill-utils.js]"]
  node_web_skills["Web acquisition skills<br/>skill modules<br/>[fetch_url.js]"]
  node_content_skills["Content processing skills<br/>skill modules"]
  node_email_skills["Email I/O skills<br/>skill modules<br/>[receive_email.js]"]
  node_external_web(("Web services<br/>external services"))
  node_mail(("SMTP / IMAP<br/>email infrastructure"))
end

subgraph group_state["Durable State"]
  node_repository[("Task repository<br/>persistence gateway<br/>[task-repository.js]")]
  node_sqlite[("SQLite<br/>durable database")]
end

node_cli -->|"runs tasks and admin actions"| node_engine
node_config -->|"runtime settings"| node_engine
node_config -->|"endpoint settings"| node_llm
node_engine -->|"normalizes request"| node_input
node_engine -->|"loads templates; persists progress"| node_repository
node_repository -->|"stores tasks, steps, events, templates"| node_sqlite
node_engine -->|"loads approved registry"| node_skill_loader
node_engine -->|"builds plan and payload prompts"| node_prompts
node_prompts -->|"restricted prompts"| node_llm
node_llm -->|"inference"| node_ollama
node_engine -->|"validates plans, transitions, outputs"| node_validators
node_skill_loader -->|"discovers"| node_web_skills
node_skill_loader -->|"discovers"| node_content_skills
node_skill_loader -->|"discovers"| node_email_skills
node_engine -->|"executes serial plan steps"| node_web_skills
node_engine -->|"passes prior step context"| node_content_skills
node_engine -->|"executes validated payloads"| node_email_skills
node_web_skills -->|"shared execution support"| node_skill_utils
node_content_skills -->|"shared execution support"| node_skill_utils
node_email_skills -->|"shared execution support"| node_skill_utils
node_web_skills -->|"acquires content"| node_external_web
node_email_skills -->|"receives and sends"| node_mail
node_engine -->|"operational events"| node_logger

click node_cli "https://github.com/aotol/ai_automation/blob/main/src/app.js"
click node_engine "https://github.com/aotol/ai_automation/blob/main/src/task-engine.js"
click node_input "https://github.com/aotol/ai_automation/blob/main/src/input-provider.js"
click node_config "https://github.com/aotol/ai_automation/blob/main/src/config.js"
click node_logger "https://github.com/aotol/ai_automation/blob/main/src/logger.js"
click node_prompts "https://github.com/aotol/ai_automation/blob/main/src/prompt-builder.js"
click node_llm "https://github.com/aotol/ai_automation/blob/main/src/llm-provider.js"
click node_validators "https://github.com/aotol/ai_automation/blob/main/src/validators.js"
click node_skill_loader "https://github.com/aotol/ai_automation/blob/main/src/skills-loader.js"
click node_skill_utils "https://github.com/aotol/ai_automation/blob/main/src/skill-utils.js"
click node_web_skills "https://github.com/aotol/ai_automation/blob/main/src/skills/fetch_url.js"
click node_content_skills "https://github.com/aotol/ai_automation/blob/main/src/skills/extract_text_from_html.js"
click node_email_skills "https://github.com/aotol/ai_automation/blob/main/src/skills/receive_email.js"
click node_repository "https://github.com/aotol/ai_automation/blob/main/src/task-repository.js"

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_config,node_logger toneBlue
class node_engine,node_input toneAmber
class node_prompts,node_llm,node_validators,node_ollama toneMint
class node_skill_loader,node_skill_utils,node_web_skills,node_content_skills,node_email_skills,node_external_web,node_mail toneRose
class node_repository,node_sqlite toneIndigo
```

## Components

### Entry & Control

- [CLI & admin commands](https://github.com/aotol/ai_automation/blob/main/src/app.js): Node.js entrypoint · Starts task runs and workflow governance actions. · `src/app.js`
- [Configuration](https://github.com/aotol/ai_automation/blob/main/src/config.js): runtime config · `src/config.js`
- [Operational logger](https://github.com/aotol/ai_automation/blob/main/src/logger.js): logging · `src/logger.js`

### Task Orchestration

- [TaskEngine](https://github.com/aotol/ai_automation/blob/main/src/task-engine.js): orchestrator · Trust boundary for the serial task lifecycle. · `src/task-engine.js`
- [Input provider](https://github.com/aotol/ai_automation/blob/main/src/input-provider.js): request boundary · Bounds and normalizes raw requests. · `src/input-provider.js`

### AI Planning & Validation

- [Prompt builder](https://github.com/aotol/ai_automation/blob/main/src/prompt-builder.js): prompt policy · Restricts planning and parameter-filling context to registered skills. · `src/prompt-builder.js`
- [LLM provider](https://github.com/aotol/ai_automation/blob/main/src/llm-provider.js): Ollama client · `src/llm-provider.js`
- [Validators](https://github.com/aotol/ai_automation/blob/main/src/validators.js): guardrails · Validates LLM structures, transitions, and skill results. · `src/validators.js`
- **Ollama endpoint**: local LLM runtime

### Skill Execution

- [Skills loader](https://github.com/aotol/ai_automation/blob/main/src/skills-loader.js): dynamic registry · Discovers approved atomic skill modules. · `src/skills-loader.js`
- [Skill utilities](https://github.com/aotol/ai_automation/blob/main/src/skill-utils.js): shared skill support · `src/skill-utils.js`
- [Web acquisition skills](https://github.com/aotol/ai_automation/blob/main/src/skills/fetch_url.js): skill modules · Fetch URL and web search operations. · `src/skills/fetch_url.js`
- [Content processing skills](https://github.com/aotol/ai_automation/blob/main/src/skills/extract_text_from_html.js): skill modules · HTML extraction, summarization, and translation. · `src/skills/extract_text_from_html.js`
- [Email I/O skills](https://github.com/aotol/ai_automation/blob/main/src/skills/receive_email.js): skill modules · Receive and send email operations. · `src/skills/receive_email.js`
- **Web services**: external services
- **SMTP / IMAP**: email infrastructure

### Durable State

- [Task repository](https://github.com/aotol/ai_automation/blob/main/src/task-repository.js): persistence gateway · Manages tasks, ordered steps, events, and workflow templates. · `src/task-repository.js`
- **SQLite**: durable database

## Connections

- CLI & admin commands → TaskEngine: runs tasks and admin actions
- Configuration → TaskEngine: runtime settings
- Configuration → LLM provider: endpoint settings
- TaskEngine → Input provider: normalizes request
- TaskEngine → Task repository: loads templates; persists progress
- Task repository → SQLite: stores tasks, steps, events, templates
- TaskEngine → Skills loader: loads approved registry
- TaskEngine → Prompt builder: builds plan and payload prompts
- Prompt builder → LLM provider: restricted prompts
- LLM provider → Ollama endpoint: inference
- TaskEngine → Validators: validates plans, transitions, outputs
- Skills loader → Web acquisition skills: discovers
- Skills loader → Content processing skills: discovers
- Skills loader → Email I/O skills: discovers
- TaskEngine → Web acquisition skills: executes serial plan steps
- TaskEngine → Content processing skills: passes prior step context
- TaskEngine → Email I/O skills: executes validated payloads
- Web acquisition skills → Skill utilities: shared execution support
- Content processing skills → Skill utilities: shared execution support
- Email I/O skills → Skill utilities: shared execution support
- Web acquisition skills → Web services: acquires content
- Email I/O skills → SMTP / IMAP: receives and sends
- TaskEngine → Operational logger: operational events
