# cosm1cbug/echofox architecture

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

- Interactive diagram: https://gitdiagram.com/cosm1cbug/echofox
- Repository: https://github.com/cosm1cbug/echofox

## Overview

EchoFox is a WhatsApp automation bot with a live operations dashboard. Its principal workflow is WhatsApp events entering the worker, being routed to event handlers and command/AI processing, then using services and persistent storage to produce replies or update state. The graph also preserves documented AI, Telegram logging, alerts, metrics, and dashboard capabilities. Edges are limited to cited source references or README statements; uncertain wiring is omitted or marked dashed.

Main entry points: [`src/core/worker.js`](https://github.com/cosm1cbug/echofox/blob/main/src/core/worker.js) (Bot worker), [`src/dashboard/server.js`](https://github.com/cosm1cbug/echofox/blob/main/src/dashboard/server.js) (Dashboard API), [`src/services/alertEngine.js`](https://github.com/cosm1cbug/echofox/blob/main/src/services/alertEngine.js) (Alert engine), [`src/events/messages.upsert.js`](https://github.com/cosm1cbug/echofox/blob/main/src/events/messages.upsert.js) (Message handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot runtime"]
  node_worker["Bot worker<br/>[worker.js]"]
  node_lifecycle["Lifecycle manager<br/>[lifecycle.js]"]
  node_auth[("Auth backend<br/>[auth.js]")]
  node_caches["Signal caches<br/>[caches.js]"]
  node_eventrouter["Event router<br/>[router.js]"]
end

subgraph group_product["Messaging features"]
  node_messagehandler["Message handler<br/>[messages.upsert.js]"]
  node_commandregistry["Command registry<br/>[commandRegistry.js]"]
  node_commandrunner["Command runner<br/>[commandRunner.js]"]
  node_commands["Command catalog"]
  node_ai["AI service<br/>[router.js]"]
end

subgraph group_state["State and observability"]
  node_store[("Pluggable store<br/>[instance.js]")]
  node_metrics["Metrics service<br/>[metrics.js]"]
  node_alerts["Alert engine<br/>[alertEngine.js]"]
  node_audit["Admin audit"]
end

subgraph group_dashboard["Operations dashboard"]
  node_dashboardserver["Dashboard API<br/>[server.js]"]
  node_dashboardapp["Dashboard app<br/>[App.tsx]"]
  node_dashboardapi["Dashboard client API<br/>[api.ts]"]
  node_dashboardpages["Dashboard views"]
end

subgraph group_integrations["External integrations"]
  node_whatsapp{{"WhatsApp / Baileys"}}
  node_aiintegrations{{"LLM providers"}}
  node_telegram["Telegram bridge<br/>[index.js]"]
end

node_user(("WhatsApp user"))
node_operator(("Bot operator"))

node_user -->|"sends messages"| node_whatsapp
node_whatsapp -.->|"delivers events"| node_worker
node_worker -->|"selects runtime"| node_lifecycle
node_worker -->|"selects auth"| node_auth
node_worker -->|"uses caches"| node_caches
node_worker -->|"routes events"| node_eventrouter
node_eventrouter -->|"dispatches messages"| node_messagehandler
node_messagehandler -->|"runs commands"| node_commandrunner
node_messagehandler -->|"invokes AI"| node_ai
node_worker -->|"loads commands"| node_commandregistry
node_commandrunner -.->|"dispatches commands"| node_commands
node_ai -.->|"uses providers"| node_aiintegrations
node_lifecycle -->|"selects store"| node_store
node_worker -->|"initializes metrics"| node_metrics
node_worker -->|"initializes alerts"| node_alerts
node_alerts -->|"sends alerts"| node_telegram
node_alerts -->|"records outcomes"| node_metrics
node_dashboardserver -->|"reads metrics"| node_metrics
node_dashboardserver -->|"reads alert rates"| node_alerts
node_dashboardserver -->|"uses audit"| node_audit
node_dashboardserver -->|"queries state"| node_store
node_operator -->|"views dashboard"| node_dashboardapp
node_dashboardapp -->|"renders views"| node_dashboardpages
node_dashboardapp -->|"sets credentials"| node_dashboardapi
node_dashboardapi -.->|"requests API"| node_dashboardserver
node_worker -->|"starts dashboard"| node_dashboardserver

click node_worker "https://github.com/cosm1cbug/echofox/blob/main/src/core/worker.js"
click node_lifecycle "https://github.com/cosm1cbug/echofox/blob/main/src/core/lifecycle.js"
click node_auth "https://github.com/cosm1cbug/echofox/blob/main/src/core/auth.js"
click node_caches "https://github.com/cosm1cbug/echofox/blob/main/src/core/caches.js"
click node_eventrouter "https://github.com/cosm1cbug/echofox/blob/main/src/events/router.js"
click node_messagehandler "https://github.com/cosm1cbug/echofox/blob/main/src/events/messages.upsert.js"
click node_commandregistry "https://github.com/cosm1cbug/echofox/blob/main/src/core/commandRegistry.js"
click node_commandrunner "https://github.com/cosm1cbug/echofox/blob/main/src/core/commandRunner.js"
click node_commands "https://github.com/cosm1cbug/echofox/tree/main/src/commands"
click node_ai "https://github.com/cosm1cbug/echofox/blob/main/src/services/ai/router.js"
click node_aiintegrations "https://github.com/cosm1cbug/echofox/tree/main/src/services/ai/providers"
click node_telegram "https://github.com/cosm1cbug/echofox/blob/main/src/services/telegram/index.js"
click node_store "https://github.com/cosm1cbug/echofox/blob/main/src/store/instance.js"
click node_metrics "https://github.com/cosm1cbug/echofox/blob/main/src/services/metrics.js"
click node_alerts "https://github.com/cosm1cbug/echofox/blob/main/src/services/alertEngine.js"
click node_audit "https://github.com/cosm1cbug/echofox/blob/main/src/services/adminAuditService.js"
click node_dashboardserver "https://github.com/cosm1cbug/echofox/blob/main/src/dashboard/server.js"
click node_dashboardapp "https://github.com/cosm1cbug/echofox/blob/main/dashboard/src/App.tsx"
click node_dashboardapi "https://github.com/cosm1cbug/echofox/blob/main/dashboard/src/lib/api.ts"
click node_dashboardpages "https://github.com/cosm1cbug/echofox/tree/main/dashboard/src/pages"

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_worker,node_lifecycle,node_auth,node_caches,node_eventrouter,node_user toneBlue
class node_messagehandler,node_commandregistry,node_commandrunner,node_commands,node_ai toneAmber
class node_store,node_metrics,node_alerts,node_audit toneMint
class node_dashboardserver,node_dashboardapp,node_dashboardapi,node_dashboardpages toneRose
class node_whatsapp,node_aiintegrations,node_telegram,node_operator toneIndigo
```

## Components

### Bot runtime

- [Bot worker](https://github.com/cosm1cbug/echofox/blob/main/src/core/worker.js): `src/core/worker.js`
- [Lifecycle manager](https://github.com/cosm1cbug/echofox/blob/main/src/core/lifecycle.js): `src/core/lifecycle.js`
- [Auth backend](https://github.com/cosm1cbug/echofox/blob/main/src/core/auth.js): `src/core/auth.js`
- [Signal caches](https://github.com/cosm1cbug/echofox/blob/main/src/core/caches.js): `src/core/caches.js`
- [Event router](https://github.com/cosm1cbug/echofox/blob/main/src/events/router.js): `src/events/router.js`

### Messaging features

- [Message handler](https://github.com/cosm1cbug/echofox/blob/main/src/events/messages.upsert.js): `src/events/messages.upsert.js`
- [Command registry](https://github.com/cosm1cbug/echofox/blob/main/src/core/commandRegistry.js): `src/core/commandRegistry.js`
- [Command runner](https://github.com/cosm1cbug/echofox/blob/main/src/core/commandRunner.js): `src/core/commandRunner.js`
- [Command catalog](https://github.com/cosm1cbug/echofox/tree/main/src/commands): `src/commands`
- [AI service](https://github.com/cosm1cbug/echofox/blob/main/src/services/ai/router.js): `src/services/ai/router.js`

### State and observability

- [Pluggable store](https://github.com/cosm1cbug/echofox/blob/main/src/store/instance.js): `src/store/instance.js`
- [Metrics service](https://github.com/cosm1cbug/echofox/blob/main/src/services/metrics.js): `src/services/metrics.js`
- [Alert engine](https://github.com/cosm1cbug/echofox/blob/main/src/services/alertEngine.js): `src/services/alertEngine.js`
- [Admin audit](https://github.com/cosm1cbug/echofox/blob/main/src/services/adminAuditService.js): `src/services/adminAuditService.js`

### Operations dashboard

- [Dashboard API](https://github.com/cosm1cbug/echofox/blob/main/src/dashboard/server.js): `src/dashboard/server.js`
- [Dashboard app](https://github.com/cosm1cbug/echofox/blob/main/dashboard/src/App.tsx): `dashboard/src/App.tsx`
- [Dashboard client API](https://github.com/cosm1cbug/echofox/blob/main/dashboard/src/lib/api.ts): `dashboard/src/lib/api.ts`
- [Dashboard views](https://github.com/cosm1cbug/echofox/tree/main/dashboard/src/pages): `dashboard/src/pages`

### External integrations

- **WhatsApp / Baileys**
- [LLM providers](https://github.com/cosm1cbug/echofox/tree/main/src/services/ai/providers): `src/services/ai/providers`
- [Telegram bridge](https://github.com/cosm1cbug/echofox/blob/main/src/services/telegram/index.js): `src/services/telegram/index.js`

### Other components

- **WhatsApp user**
- **Bot operator**

## Connections

- WhatsApp user → WhatsApp / Baileys: sends messages
- WhatsApp / Baileys → Bot worker: delivers events
- Bot worker → Lifecycle manager: selects runtime (evidence: `src/core/worker.js`)
- Bot worker → Auth backend: selects auth (evidence: `src/core/worker.js`)
- Bot worker → Signal caches: uses caches (evidence: `src/core/worker.js`)
- Bot worker → Event router: routes events (evidence: `src/core/worker.js`)
- Event router → Message handler: dispatches messages (evidence: `src/events/router.js`)
- Message handler → Command runner: runs commands (evidence: `src/events/messages.upsert.js`)
- Message handler → AI service: invokes AI (evidence: `src/events/messages.upsert.js`)
- Bot worker → Command registry: loads commands (evidence: `src/core/worker.js`)
- Command runner → Command catalog: dispatches commands
- AI service → LLM providers: uses providers
- Lifecycle manager → Pluggable store: selects store (evidence: `src/core/lifecycle.js`)
- Bot worker → Metrics service: initializes metrics (evidence: `src/core/worker.js`)
- Bot worker → Alert engine: initializes alerts (evidence: `src/core/worker.js`)
- Alert engine → Telegram bridge: sends alerts (evidence: `src/services/alertEngine.js`)
- Alert engine → Metrics service: records outcomes (evidence: `src/services/alertEngine.js`)
- Dashboard API → Metrics service: reads metrics (evidence: `src/dashboard/server.js`)
- Dashboard API → Alert engine: reads alert rates (evidence: `src/dashboard/server.js`)
- Dashboard API → Admin audit: uses audit (evidence: `src/dashboard/server.js`)
- Dashboard API → Pluggable store: queries state (evidence: `src/dashboard/server.js`)
- Bot operator → Dashboard app: views dashboard
- Dashboard app → Dashboard views: renders views (evidence: `dashboard/src/App.tsx`)
- Dashboard app → Dashboard client API: sets credentials (evidence: `dashboard/src/App.tsx`)
- Dashboard client API → Dashboard API: requests API
- Bot worker → Dashboard API: starts dashboard (evidence: `src/core/worker.js`)
