# tungvoc3199/anh-duong-ai-coworker architecture

> Architecture diagram of the GitHub repository tungvoc3199/anh-duong-ai-coworker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tungvoc3199/anh-duong-ai-coworker
- Repository: https://github.com/tungvoc3199/anh-duong-ai-coworker

## Overview

Ánh Dương AI Coworker Core is a Python service that prepares user requests and supports durable, asynchronous workflow execution. The main path classifies a request, selects a capability, gathers persona and project/task context, then exposes a prepared result; execution proceeds separately through task planning, policy and approval checks, and a background worker. State, audit, visual tooling, and evaluation are supporting capabilities. The graph follows the sampled pipeline, API, worker, and integration excerpts; several subsystem links are omitted where wiring was not shown.

Main entry points: [`app/async_tasks/worker.py`](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/async_tasks/worker.py) (Background worker), [`app/orchestration/pipeline.py`](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/orchestration/pipeline.py) (Request pipeline), [`app/api/async_tasks.py`](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/api/async_tasks.py) (Async tasks API), [`app/api/prepared_requests.py`](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/api/prepared_requests.py) (Prepared requests API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API and integration"]
  node_api["FastAPI app<br/>[main.py]"]
  node_prepared_api["Prepared requests API"]
  node_async_api["Async tasks API<br/>[async_tasks.py]"]
  node_plugin["OpenClaw integration<br/>[index.js]"]
end

subgraph group_request["Request preparation"]
  node_pipeline["Request pipeline<br/>[pipeline.py]"]
  node_fast_router["Fast router<br/>[fast_router.py]"]
  node_cap_router["Capability router<br/>[router.py]"]
  node_context["Context builder<br/>[builder.py]"]
  node_persona["Persona loader<br/>[loader.py]"]
end

subgraph group_execution["Workflow execution"]
  node_async_service["Async task service<br/>[service.py]"]
  node_worker["Background worker<br/>[worker.py]"]
  node_planner["Workflow planning<br/>[planner.py]"]
  node_policy["Policy engine<br/>[engine.py]"]
  node_approvals["Approval service<br/>[service.py]"]
end

subgraph group_state["State and governance"]
  node_projects["Project service<br/>[service.py]"]
  node_tasks["Task service<br/>[service.py]"]
  node_audit["Audit writer<br/>[writer.py]"]
  node_database[("SQLite database<br/>[session.py]")]
end

subgraph group_capabilities["Product capabilities"]
  node_memory["Memory retrieval<br/>[retrieval.py]"]
  node_executor["OpenClaw executor<br/>[executor.py]"]
  node_visualforge["VisualForge client<br/>[client.py]"]
  node_evaluation["Evaluation service<br/>[service.py]"]
end

node_user(("User / caller"))
node_gateway(("OpenClaw gateway"))

node_user -->|"submits request"| node_prepared_api
node_prepared_api -->|"prepares request"| node_pipeline
node_pipeline -->|"routes text"| node_fast_router
node_pipeline -->|"selects capability"| node_cap_router
node_pipeline -->|"loads persona"| node_persona
node_pipeline -->|"builds context"| node_context
node_pipeline -->|"reads project"| node_projects
node_pipeline -->|"reads task"| node_tasks
node_pipeline -->|"writes events"| node_audit
node_context -.->|"retrieves context"| node_memory
node_user -->|"submits or manages run"| node_async_api
node_async_api -->|"creates or resolves run"| node_async_service
node_async_api -->|"reads and writes"| node_database
node_api -->|"starts worker"| node_worker
node_worker -->|"plans workflow"| node_planner
node_worker -->|"checks actions"| node_policy
node_worker -->|"handles approvals"| node_approvals
node_worker -->|"updates task"| node_tasks
node_worker -->|"persists run state"| node_database
node_worker -->|"records events"| node_audit
node_worker -->|"executes actions"| node_executor
node_executor -.->|"dispatches execution"| node_gateway
node_worker -.->|"invokes visual work"| node_visualforge
node_plugin -->|"requests preparation"| node_prepared_api
node_plugin -->|"creates and polls runs"| node_async_api
node_evaluation -->|"reads run data"| node_database

click node_api "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/main.py"
click node_prepared_api "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/api/prepared_requests.py"
click node_async_api "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/api/async_tasks.py"
click node_plugin "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/integrations/openclaw-anh-duong-core/index.js"
click node_pipeline "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/orchestration/pipeline.py"
click node_fast_router "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/routing/fast_router.py"
click node_cap_router "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/capabilities/router.py"
click node_context "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/context_builder/builder.py"
click node_persona "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/persona/loader.py"
click node_projects "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/projects/service.py"
click node_tasks "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/tasks/service.py"
click node_memory "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/memory/retrieval.py"
click node_async_service "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/async_tasks/service.py"
click node_worker "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/async_tasks/worker.py"
click node_planner "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/planning/planner.py"
click node_policy "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/policy/engine.py"
click node_approvals "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/approvals/service.py"
click node_executor "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/openclaw/executor.py"
click node_visualforge "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/visualforge/client.py"
click node_evaluation "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/evaluation/service.py"
click node_audit "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/audit/writer.py"
click node_database "https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/db/session.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_api,node_prepared_api,node_async_api,node_plugin,node_user toneBlue
class node_pipeline,node_fast_router,node_cap_router,node_context,node_persona toneAmber
class node_async_service,node_worker,node_planner,node_policy,node_approvals toneMint
class node_projects,node_tasks,node_audit,node_database toneRose
class node_memory,node_executor,node_visualforge,node_evaluation,node_gateway toneIndigo
```

## Components

### API and integration

- [FastAPI app](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/main.py): `app/main.py`
- [Prepared requests API](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/api/prepared_requests.py): `app/api/prepared_requests.py`
- [Async tasks API](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/api/async_tasks.py): `app/api/async_tasks.py`
- [OpenClaw integration](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/integrations/openclaw-anh-duong-core/index.js): `integrations/openclaw-anh-duong-core/index.js`

### Request preparation

- [Request pipeline](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/orchestration/pipeline.py): `app/orchestration/pipeline.py`
- [Fast router](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/routing/fast_router.py): `app/routing/fast_router.py`
- [Capability router](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/capabilities/router.py): `app/capabilities/router.py`
- [Context builder](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/context_builder/builder.py): `app/context_builder/builder.py`
- [Persona loader](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/persona/loader.py): `app/persona/loader.py`

### Workflow execution

- [Async task service](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/async_tasks/service.py): `app/async_tasks/service.py`
- [Background worker](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/async_tasks/worker.py): `app/async_tasks/worker.py`
- [Workflow planning](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/planning/planner.py): `app/planning/planner.py`
- [Policy engine](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/policy/engine.py): `app/policy/engine.py`
- [Approval service](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/approvals/service.py): `app/approvals/service.py`

### State and governance

- [Project service](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/projects/service.py): `app/projects/service.py`
- [Task service](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/tasks/service.py): `app/tasks/service.py`
- [Audit writer](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/audit/writer.py): `app/audit/writer.py`
- [SQLite database](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/db/session.py): `app/db/session.py`

### Product capabilities

- [Memory retrieval](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/memory/retrieval.py): `app/memory/retrieval.py`
- [OpenClaw executor](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/openclaw/executor.py): `app/openclaw/executor.py`
- [VisualForge client](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/visualforge/client.py): `app/visualforge/client.py`
- [Evaluation service](https://github.com/tungvoc3199/anh-duong-ai-coworker/blob/main/app/evaluation/service.py): `app/evaluation/service.py`

### Other components

- **User / caller**
- **OpenClaw gateway**

## Connections

- User / caller → Prepared requests API: submits request
- Prepared requests API → Request pipeline: prepares request
- Request pipeline → Fast router: routes text
- Request pipeline → Capability router: selects capability
- Request pipeline → Persona loader: loads persona
- Request pipeline → Context builder: builds context
- Request pipeline → Project service: reads project
- Request pipeline → Task service: reads task
- Request pipeline → Audit writer: writes events
- Context builder → Memory retrieval: retrieves context
- User / caller → Async tasks API: submits or manages run
- Async tasks API → Async task service: creates or resolves run
- Async tasks API → SQLite database: reads and writes
- FastAPI app → Background worker: starts worker
- Background worker → Workflow planning: plans workflow
- Background worker → Policy engine: checks actions
- Background worker → Approval service: handles approvals
- Background worker → Task service: updates task
- Background worker → SQLite database: persists run state
- Background worker → Audit writer: records events
- Background worker → OpenClaw executor: executes actions
- OpenClaw executor → OpenClaw gateway: dispatches execution
- Background worker → VisualForge client: invokes visual work
- OpenClaw integration → Prepared requests API: requests preparation
- OpenClaw integration → Async tasks API: creates and polls runs
- Evaluation service → SQLite database: reads run data
