Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
docs: simplify README Nerdy Docs for contributors, add 4 SVG diagrams
trohitgffa5fb12b327
diff --git a/README.md b/README.mdindex 623836ba..66137a99 100644--- a/README.md+++ b/README.md@@ -140,499 +140,110 @@ MIT## Nerdy Docs-A detailed look at how MachinaOS works under the hood. For the TL;DR just use the product; this section is for contributors, system designers, and the curious. For a deep, navigable tour the [DeepWiki badge](https://deepwiki.com/trohitg/MachinaOS) at the top of this README covers the same ground with hyperlinks. In-repo docs live under [docs-internal/](docs-internal/).+A contributor's map to the codebase. This section tells you *where things live* and *where to start reading* when you want to add a feature. For the full architecture tour, use the [DeepWiki badge](https://deepwiki.com/trohitg/MachinaOS) at the top of this README or browse [docs-internal/](docs-internal/).### System Overview-MachinaOS is three loosely-coupled tiers talking over a single persistent WebSocket connection:+-```-+------------------------------------------------------------------------+-| Frontend tier (client/) |-| React + TypeScript + React Flow + Zustand + Ant Design |-| Dracula-themed canvas, parameter panel, credentials modal |-+------------------------------------------------------------------------+- |- WebSocket | /ws/status (single long-lived connection)- v-+------------------------------------------------------------------------+-| Backend tier (server/) |-| FastAPI + 89 WebSocket handlers + dependency injection container |-| WorkflowService (facade) -> NodeExecutor -> per-node handlers |-| ParameterResolver -> template {{node.field}} substitution |-| AuthService -> encrypted credentials (Fernet + PBKDF2) |-+------------------------------------------------------------------------+- |- v-+------------------------------------------------------------------------+-| Execution tier |-| Temporal workers (distributed) or local asyncio decide loop |-| Redis (cache, locks, streams) SQLite (machina.db, credentials.db) |-| Node.js server (JS/TS code exec) WhatsApp RPC (port 9400) |-| Android relay WebSocket Temporal server (ports 7233/8080) |-+------------------------------------------------------------------------+- |- v- External services: OpenAI, Anthropic, Gemini, OpenRouter, xAI,- DeepSeek, Kimi, Mistral, Groq, Cerebras, Google Workspace, WhatsApp,- Telegram, Twitter/X, Brave, Serper, Perplexity, Apify, residential- proxies, webhooks.-```--Notable characteristics at a glance:+At a glance:-- **96 workflow nodes** across AI models, agents, social, Android, document processing, Google Workspace, code executors, proxies, and utilities-- **10 LLM providers**: OpenAI, Anthropic, Gemini, OpenRouter, xAI, DeepSeek, Kimi, Mistral, Groq, Cerebras-- **15 specialized agents**: android, coding, web, task, social, travel, tool, productivity, payments, consumer, autonomous, orchestrator, ai_employee, rlm, claude_code+- **96 workflow nodes** across 21 categories (AI, agents, social, Android, Google Workspace, documents, code, proxies, utilities)+- **10 LLM providers** via a hybrid native SDK + LangChain architecture+- **15 specialized AI agents** with the Agent Teams delegation pattern- **89 WebSocket handlers** replacing most REST endpoints-- **49 built-in skills** across 10 categories (assistant, android_agent, autonomous, coding_agent, productivity_agent, rlm_agent, social_agent, task_agent, travel_agent, web_agent)-- **Three execution modes** with automatic fallback: Temporal distributed -> Redis parallel -> sequential-- **Encrypted credentials** stored in a separate SQLite database using Fernet + PBKDF2 (600K iterations)--<details>-<summary><b>Execution Engine</b></summary>--### Conductor's Decide Pattern--Workflow orchestration is a single function with fork/join parallelism:--```-_workflow_decide(ctx):- 1. Find ready nodes (all dependencies satisfied)- 2. asyncio.gather() the ready layer -> run in parallel- 3. Checkpoint state to Redis/SQLite- 4. Recurse until every node terminal (completed / skipped / failed)-```--Each workflow run has its own isolated `ExecutionContext` (`server/services/execution/models.py`). No shared global state between concurrent runs. Decide loops serialize per execution via Redis `SETNX` distributed locks.--### Three Execution Modes--```-workflow.execute(workflow_id, workflow_data)- |- v- TEMPORAL_ENABLED and server reachable?- |- yes -> _execute_temporal() -- per-node activities,- retries, horizontal scaling- (primary production mode)- no -> Redis available?- |- yes -> _execute_parallel() -- decide loop + Kahn layers- + Prefect-style input hash cache- + DLQ + heartbeat recovery- no -> _execute_sequential() -- topological walk- (fallback for minimal env)-```--### Layer Computation via Kahn's Algorithm--Before execution, the DAG is sorted into layers. Layer 0 is the set of nodes with no dependencies; each subsequent layer depends only on earlier layers. Parallel execution runs each layer with `asyncio.gather()`:--```-Layer 0: [start, cronScheduler]-Layer 1: [httpRequest, whatsappReceive]-Layer 2: [aiAgent]-Layer 3: [whatsappSend, console]-```--Toolkit sub-nodes (e.g., Android service nodes connected to `androidTool`) are detected and excluded from execution layers -- they run only when the parent toolkit invokes them via tool calling. See the Toolkit Sub-Node Execution Pattern in [CLAUDE.md](CLAUDE.md).--### Result Caching, Recovery, and DLQ--- **Prefect-style caching**: every node result is stored in Redis/SQLite keyed by `hash_inputs(inputs)`. Re-running an identical node returns the cached result with status `TaskStatus.CACHED`.-- **Heartbeat recovery**: `RecoverySweeper` scans `executions:active` every 60s; nodes with stale heartbeats (>5 min) are marked stuck and recovered on next startup.-- **Dead Letter Queue**: failed nodes (after retry exhaustion) are quarantined in `dlq:entries:*` with full input snapshot. Inspect, replay, or purge via the `get_dlq_*` / `replay_dlq_entry` / `purge_dlq` WebSocket handlers.--### Edge Conditions--Edges carry optional conditions for runtime branching with 20+ operators (`eq`, `neq`, `gt`, `lt`, `contains`, `exists`, `matches`, `in`, ...). Unmatched branches are marked `TaskStatus.SKIPPED`.--**Read more**: [DESIGN.md](docs-internal/DESIGN.md) - [TEMPORAL_ARCHITECTURE.md](docs-internal/TEMPORAL_ARCHITECTURE.md) - [workflow-schema.md](docs-internal/workflow-schema.md)--</details>--<details>-<summary><b>Event-Driven Deployment</b></summary>--Deployments are event-driven: each trigger event spawns an **independent concurrent execution run**. There is no iteration loop.--```-deploy_workflow(workflow_id)- |- v- Set up triggers, return- |- +-> cronScheduler fires -> ExecutionRun 1 (isolated context)- +-> cronScheduler fires -> ExecutionRun 2 (isolated context)- +-> whatsappReceive fires -> ExecutionRun 3 (isolated context)- +-> webhookTrigger fires -> ExecutionRun 4 (isolated context)- +-> telegramReceive fires -> ExecutionRun 5 (isolated context)- +-> taskTrigger fires -> ExecutionRun 6 (from delegated agent)-```--Multiple runs execute simultaneously with no interference. The firing trigger is marked complete before downstream execution starts; every other trigger node in the same run is auto-marked `_pre_executed` with `{not_triggered: True}` so they never block as event waiters.--### Push vs Polling Triggers+- **49 built-in skills** across 10 categories, editable in-UI with SKILL.md defaults on disk+- **Three execution modes** with automatic fallback: Temporal distributed, Redis parallel, sequential-```-Push triggers (asyncio.Future + dispatch):- whatsappReceive, webhookTrigger, chatTrigger, taskTrigger,- telegramReceive, start+### How Workflows Execute-Polling triggers (asyncio.Queue + poll coroutine):- twitterReceive (X API has no webhook on free tier)- gmailReceive (Gmail push requires paid Google Cloud setup)+-Scheduler:- cronScheduler (APScheduler directly, not through event waiter)-```+[WorkflowService](server/services/workflow.py) is a thin facade that routes each run through one of three execution modes. Every run has an isolated `ExecutionContext` with no shared global state, orchestrated by Conductor's decide pattern (`_workflow_decide` under a Redis `SETNX` lock). Layers are computed via Kahn's algorithm and each layer runs via `asyncio.gather()`. Results are cached by input hash (Prefect pattern), failed nodes go to a Dead Letter Queue, and a `RecoverySweeper` handles crashes via heartbeats.-Every push trigger goes through the generic `event_waiter` module: register a `Waiter` with a filter closure, suspend on `wait_for_event()`, resume when an external service dispatches a matching event. Backend supports both in-memory (`asyncio.Future`) and Redis Streams modes for Temporal multi-worker deployments.+Deep dives: [DESIGN.md](docs-internal/DESIGN.md) - [TEMPORAL_ARCHITECTURE.md](docs-internal/TEMPORAL_ARCHITECTURE.md) - [event_waiter_system.md](docs-internal/event_waiter_system.md)-**Read more**: [event_waiter_system.md](docs-internal/event_waiter_system.md) - [workflow-schema.md](docs-internal/workflow-schema.md)+### AI Agent System-</details>--<details>-<summary><b>Node System (96 Nodes)</b></summary>+-### INodeProperties Interface+AI execution splits into two paths. `execute_chat()` for direct chat completions prefers the native SDK layer in [services/llm/](server/services/llm/) (10 providers, lazy imports, normalized `LLMResponse`), falling back to LangChain for Groq and Cerebras. `execute_agent()` and `execute_chat_agent()` always use LangChain + LangGraph because tool-calling, state graphs, and the checkpointer have no native equivalent today. Team leads (`orchestrator_agent`, `ai_employee`) auto-inject `delegate_to_<type>` tools for every agent connected to their `input-teammates` handle.-Node definitions follow an n8n-inspired TypeScript interface system. Every node has a strongly-typed `INodeTypeDescription` with `displayName`, `group`, `inputs`, `outputs`, and `properties`. Parameters support conditional display via `displayOptions.show`, type-specific editors (string, number, boolean, options, collection, file, array), drag-and-drop template variable mapping, and live validation.+Deep dives: [agent_architecture.md](docs-internal/agent_architecture.md) - [native_llm_sdk.md](docs-internal/native_llm_sdk.md) - [agent_teams.md](docs-internal/agent_teams.md) - [memory_compaction.md](docs-internal/memory_compaction.md)-Source of truth: `client/src/nodeDefinitions/` (23 files).+### Repository Map-### Category Breakdown--| Category | Count | File |+| Directory | What lives here | Start reading ||---|---|---|-| AI Chat Models | 9 | `aiModelNodes.ts` |-| AI Agents + Memory | 3 | `aiAgentNodes.ts` |-| Specialized Agents | 15 | `specializedAgentNodes.ts` |-| AI Tools (dedicated) | 4 | `toolNodes.ts` |-| Skills (masterSkill) | 1 | `skillNodes.ts` |-| Search (dual-purpose) | 3 | `searchNodes.ts` |-| Location / Maps | 3 | `locationNodes.ts` |-| Google Workspace | 7 | `googleWorkspaceNodes.ts` |-| WhatsApp | 3 | `whatsappNodes.ts` |-| Twitter/X | 4 | `twitterNodes.ts` |-| Telegram | 2 | `telegramNodes.ts` |-| Social (unified) | 2 | `socialNodes.ts` |-| Android services | 16 | `androidServiceNodes.ts` |-| Code executors | 3 | `codeNodes.ts` |-| Document processing | 6 | `documentNodes.ts` |-| Utilities | 6 | `utilityNodes.ts` |-| Proxy | 3 | `proxyNodes.ts` |-| Web scraping | 2 | `apifyNodes.ts` + `crawleeNodes.ts` |-| Chat | 2 | `chatNodes.ts` |-| Schedulers | 2 | `schedulerNodes.ts` |-| Workflow triggers | 2 | `workflowNodes.ts` |--### Dispatch Registry (backend)--`NodeExecutor` in `server/services/node_executor.py` uses a registry built with `functools.partial` for dependency injection:--```python-registry = {- 'start': handle_start,- 'aiAgent': partial(handle_ai_agent, ai_service=self.ai_service, database=self.database),- 'chatAgent': partial(handle_chat_agent, ai_service=self.ai_service, database=self.database),- 'rlm_agent': partial(handle_rlm_agent, ai_service=self.ai_service, database=self.database),- 'gmail': partial(handle_google_gmail, database=self.database),- 'whatsappSend': partial(handle_whatsapp_send, database=self.database),- # ... one entry per node type-}-```--No if-else chains, no global singletons.--### Dual-Purpose Nodes--Many nodes work as **both** workflow nodes and AI Agent tools. Examples: `whatsappSend`, `whatsappDb`, `twitterSend`, `twitterSearch`, `twitterUser`, `telegramSend`, `socialSend`, `httpRequest`, `pythonExecutor`, `javascriptExecutor`, `typescriptExecutor`, `braveSearch`, `serperSearch`, `perplexitySearch`, `apifyActor`, `proxyConfig`, `gmaps_locations`, `gmaps_nearby_places`, and all 7 Google Workspace nodes. When connected to an AI agent's `input-tools` handle, the LLM fills the node's parameter schema via structured tool calls.--### Config Node Pattern--Four special handles on agent nodes accept **config nodes** instead of main data flow:--| Handle | Purpose |-|---|---|-| `input-memory` | Connect a `simpleMemory` node for conversation history |-| `input-tools` | Connect tool nodes (dedicated tools or dual-purpose nodes) |-| `input-skill` | Connect skill nodes (`masterSkill` aggregator) |-| `input-teammates` | Connect other agents (team lead pattern only) |--Config nodes are automatically excluded from parallel execution layers and inherit their parent agent's main-input connections for template variable mapping.--**Read more**: [node_creation.md](docs-internal/node_creation.md) - [dual_purpose_tool_node_creation.md](docs-internal/dual_purpose_tool_node_creation.md) - [ai_tool_node_creation.md](docs-internal/ai_tool_node_creation.md)--</details>--<details>-<summary><b>AI Agent System</b></summary>--### 10 LLM Providers--| Provider | Native SDK Path | LangChain Path | Notes |-|---|---|---|---|-| OpenAI | yes (`providers/openai.py`) | yes | GPT 4.x/5.x + o-series reasoning |-| Anthropic | yes (`providers/anthropic.py`) | yes | Extended thinking via `budget_tokens` |-| Gemini | yes (`providers/gemini.py`) | yes (fallback) | Native bypasses LangChain Windows hang |-| OpenRouter | yes (`providers/openrouter.py`) | yes | 200+ models through one API |-| xAI | yes (shared OpenAIProvider) | yes | OpenAI-compatible |-| DeepSeek | yes (shared OpenAIProvider) | yes | Chat + Reasoner (always-on CoT) |-| Kimi | yes (shared OpenAIProvider) | yes | Moonshot K2.5 / K2-thinking |-| Mistral | yes (shared OpenAIProvider) | yes | Large / Small / Codestral |-| Groq | no (LangChain only) | yes | Llama 4, Qwen3, GPT-OSS |-| Cerebras | no (LangChain only) | yes | Llama, Qwen |--### Dual-Path Architecture--```-execute_chat(parameters) execute_agent(parameters)- direct chat completions LangGraph tool-calling loop- | |- v v-is_native_provider(provider)? create_model(provider, ...)- | |- yes -+-- create_provider() -> LLMResponse v- | LangChain ChatOpenAI /- no -+-- create_model() -> chat_model ChatAnthropic /- .invoke() -> LLMResponse ChatGoogleGenerativeAI- |- v- bind_tools(...)- |- v- LangGraph StateGraph- (agent node <-> tools node loop)-```--The native path returns a normalized `LLMResponse` dataclass across all providers. The LangChain path is used for agent tool-calling because LangGraph's checkpointer, state graph, and tool-execution callback layer have no native equivalent today.--### 15 Specialized Agents--All specialized agents share the same handle architecture (`input-main`, `input-memory`, `input-skill`, `input-tools`, `input-task`) and inherit `AI_AGENT_PROPERTIES`. They only differ in icon, title, theme color, and default prompt.--```-android_agent coding_agent web_agent task_agent-social_agent travel_agent tool_agent productivity_agent-payments_agent consumer_agent autonomous_agent orchestrator_agent-ai_employee rlm_agent claude_code_agent-```--Routing:--- **13 agents** route to `handle_chat_agent` (LangGraph loop, shared code path)-- **`rlm_agent`** routes to `handle_rlm_agent` -> `RLMService` (REPL-based recursive LM)-- **`claude_code_agent`** routes to `handle_claude_code_agent` -> Claude Code SDK--### Agent Teams Topology--`orchestrator_agent` and `ai_employee` have an extra `input-teammates` handle. Connected agents become `delegate_to_<agent_type>` tools automatically:+| `client/src/nodeDefinitions/` | 96 workflow node definitions (TypeScript) | [node_creation.md](docs-internal/node_creation.md) |+| `client/src/components/` | React Flow canvas, parameter panel, modals | [CLAUDE.md](CLAUDE.md) |+| `server/services/` | WorkflowService, NodeExecutor, AI service | [DESIGN.md](docs-internal/DESIGN.md) |+| `server/services/handlers/` | One handler per node type (dispatch targets) | [node_creation.md](docs-internal/node_creation.md) |+| `server/services/llm/` | Native LLM SDK layer (10 providers) | [native_llm_sdk.md](docs-internal/native_llm_sdk.md) |+| `server/services/execution/` | Decide pattern, DLQ, recovery, conditions | [DESIGN.md](docs-internal/DESIGN.md) |+| `server/services/temporal/` | Distributed execution via Temporal | [TEMPORAL_ARCHITECTURE.md](docs-internal/TEMPORAL_ARCHITECTURE.md) |+| `server/routers/websocket.py` | 89 WebSocket handlers | [status_broadcaster.md](docs-internal/status_broadcaster.md) |+| `server/core/` | Cache, encryption, DI container, config | [credentials_encryption.md](docs-internal/credentials_encryption.md) |+| `server/skills/` | 49 skill SKILL.md files in 10 folders | [GUIDE.md](server/skills/GUIDE.md) |+| `server/config/` | llm_defaults.json, pricing.json, model_registry.json | [pricing_service.md](docs-internal/pricing_service.md) |+| `docs-internal/` | In-repo architecture deep dives (28 files) | Index below |++### How to Contribute++++The diagram above shows the full lifecycle of a workflow node from TypeScript definition to Python handler. Use these recipes as a starting point:++**Add a workflow node**+- Node definition: `client/src/nodeDefinitions/<yourCategory>.ts`+- Backend handler: `server/services/handlers/<your_handler>.py`+- Register in: `server/services/node_executor.py` registry+- Guide: [node_creation.md](docs-internal/node_creation.md)++**Add an LLM provider**+- OpenAI-compatible (DeepSeek, Kimi, Mistral pattern): config-only in `server/config/llm_defaults.json`+- Custom-SDK provider: new file in `server/services/llm/providers/`, branch in `factory.py`+- Frontend node: `client/src/nodeDefinitions/aiModelNodes.ts`+- Guide: [native_llm_sdk.md](docs-internal/native_llm_sdk.md)++**Add a dual-purpose tool (workflow node + AI tool)**+- Mark node `group: ['category', 'tool']`+- Pydantic schema in `server/services/ai.py` (`_get_tool_schema`)+- Dispatch in `server/services/handlers/tools.py`+- Guide: [dual_purpose_tool_node_creation.md](docs-internal/dual_purpose_tool_node_creation.md)++**Add a specialized AI agent**+- `client/src/nodeDefinitions/specializedAgentNodes.ts`+- Add to `SPECIALIZED_AGENT_TYPES` in `server/constants.py`+- Register in `server/services/node_executor.py`+- Guide: [specialized_agent_node_creation.md](docs-internal/specialized_agent_node_creation.md)++**Add a skill**+- New folder under `server/skills/<category>/`+- Create `SKILL.md` with YAML frontmatter + markdown body+- Guide: [GUIDE.md](server/skills/GUIDE.md)++**Add an event-based trigger**+- Register in `TRIGGER_REGISTRY` in `server/services/event_waiter.py`+- Add a filter builder in the same file+- Frontend node with `group: ['category', 'trigger']`+- Guide: [event_waiter_system.md](docs-internal/event_waiter_system.md)++**Integrate a new external service with OAuth**+- Reference implementation: Google Workspace (7 nodes sharing one OAuth connection)+- Guide: [new_service_integration.md](docs-internal/new_service_integration.md)++### Local Dev Quick Reference+```bash+npm run dev # start frontend + backend + Temporal + WhatsApp+npm run stop # stop everything+npx tsc --noEmit # typecheck client (from client/)+python -m pytest # run backend tests (from server/)+npm run build # production build```- +-------------------------+- | AI Employee |- | (orchestrator_agent) |- +-----+------+------+-----+- | | | input-teammates- +-------------+ | +------------+- | | |- +------v------+ +-------v-----+ +-------v-----+- | coding_agent| | web_agent | | task_agent |- +-------------+ +-------------+ +-------------+- delegate_ delegate_ delegate_- to_coding_ to_web_ to_task_- agent tool agent tool agent tool-```--The team lead's LLM decides when to delegate based on task context. Delegation is **fire-and-forget**: the child spawns as `asyncio.create_task()`, the parent continues, and the child broadcasts its own status updates independently. Results can be retrieved via the auto-injected `check_delegated_tasks` tool or consumed by `taskTrigger` nodes elsewhere in the workflow.--### LangGraph StateGraph Flow--```- +---------+- START ---> | agent |- | (LLM) |- +----+----+- |- should_continue()?- / \- tools / \ end- v v- +---------+ END- | tools |- | (exec) |- +----+----+- |- +---------> loop back to agent-```--Max iterations guard against infinite tool loops. Tools are built as Pydantic-schema `StructuredTool` instances with the node's parameter schema.--**Read more**: [agent_architecture.md](docs-internal/agent_architecture.md) - [agent_teams.md](docs-internal/agent_teams.md) - [agent_delegation.md](docs-internal/agent_delegation.md) - [native_llm_sdk.md](docs-internal/native_llm_sdk.md) - [rlm_service.md](docs-internal/rlm_service.md)--</details>--<details>-<summary><b>Memory, Skills, Tokens, and Cost</b></summary>--### Markdown-Based Memory--The `simpleMemory` node stores conversation history as editable Markdown in the parameter panel. The AI Agent handler reads, parses to LangChain messages, executes, appends the new exchange, trims to a window, and archives removed messages to an `InMemoryVectorStore` (optional) using HuggingFace `BAAI/bge-small-en-v1.5` embeddings.--```-AI Agent reads memoryContent (Markdown)- |- v-_parse_memory_markdown() -> LangChain Messages- |- v-(optional) vector store similarity_search(prompt, k=retrievalCount)- |- v-Execute LLM with full history + retrieved context- |- v-Append human + ai messages to Markdown- |- v-_trim_markdown_window(windowSize) -> (kept, removed)- |- v-If longTermEnabled: store.add_texts(removed)- |- v-Save updated Markdown back to node parameters-```--### Skill System--49 built-in skills across 10 folders under `server/skills/`:--```-assistant/ (5) android_agent/ (12) autonomous/ (5)-coding_agent/ (2) productivity_agent/ (6) rlm_agent/ (1)-social_agent/ (5) task_agent/ (3) travel_agent/ (2)-web_agent/ (8)-```--Each skill is a folder with a `SKILL.md` file containing YAML frontmatter (name, description, allowed-tools, metadata) and Markdown instructions. First load seeds the database; after that the database is source of truth so users can edit skill instructions in the UI. "Reset to Default" reloads the original `SKILL.md`.--The `masterSkill` node aggregates multiple skills with enable/disable toggles. A split-panel editor shows the skill list on the left and the selected skill's Markdown on the right. When connected to an agent, the backend expands the `skillsConfig` parameter into individual skill entries injected into the agent's system message.--### Token Tracking and Compaction--Every AI execution stores a `TokenUsageMetric` row with input/output/cache/reasoning token counts and calculated costs (USD) based on `server/config/pricing.json`. Cumulative state per session lives in `SessionTokenState`.--Compaction threshold priority:--1. Per-session `custom_threshold` (user-set)-2. **Model-aware**: 50% of the model's context window (e.g., 500K for Claude Opus 4.6 with 1M context)-3. Global `COMPACTION_THRESHOLD` fallback from `.env`--When the cumulative session tokens cross the threshold, `CompactionService.compact_context()` generates a 5-section summary (Task Overview, Current State, Important Discoveries, Next Steps, Context to Preserve) following the Claude Code pattern and replaces the memory content. Anthropic and OpenAI also have native compaction APIs (`context_management` edits, `compact_threshold`) that are configured transparently via `svc.anthropic_api_config()` and `svc.openai_config()`.--**Read more**: [memory_compaction.md](docs-internal/memory_compaction.md) - [pricing_service.md](docs-internal/pricing_service.md) - [Skill Creation Guide](server/skills/GUIDE.md)--</details>--<details>-<summary><b>Communication Layer</b></summary>--A single persistent WebSocket at `/ws/status` handles all frontend-backend communication. There are **89 WebSocket handlers** registered with the `@ws_handler` decorator in `server/routers/websocket.py`, covering: node parameters, tool schemas, node execution, triggers, dead letter queue, deployment, AI operations, API keys, OAuth flows (Claude, Twitter, Google), Android, WhatsApp, Telegram, workflow storage, chat messages, console logs, skills, memory, user settings, pricing, agent teams, and model registry.--### Request/Response Pattern--```-Frontend Backend- | |- |-- {type: "execute_node", data: ...}-->|- | |-- dispatch to handle_execute_node()- | |-- run node handler- | |- |<-- {type: "node_status", ... }---------| (broadcast)- |<-- {type: "node_output", ... }---------| (broadcast)- |<-- {type: "execute_node_response", ...}| (direct reply, request_id matched)-```--### Broadcast Message Types--```-node_status workflow_status api_key_status-node_output android_status token_usage_update-variable_update compaction_starting node_parameters_updated-variables_update compaction_completed-```--### Auto-Reconnect and Keepalive--Frontend sends `{"type": "ping"}` every 30 seconds. On disconnect, the `WebSocketContext` schedules a reconnect after 3 seconds with a 100ms mount delay to avoid React Strict Mode double-connect in development. Connection is gated on `isAuthenticated` so logged-out users never connect.--**Read more**: [status_broadcaster.md](docs-internal/status_broadcaster.md)--</details>--<details>-<summary><b>Cache, Persistence, and Security</b></summary>--### Cache Fallback Hierarchy--MachinaOS follows the n8n cache pattern with automatic environment-based fallback:--```-Production (Docker): Redis -> SQLite (cache_entries) -> in-memory dict-Local development: SQLite (cache_entries) -> in-memory dict- (Redis disabled via REDIS_ENABLED=false)-```--`CacheService` in `server/core/cache.py` checks each backend in order. TTL expiration is supported across all three. A background `cleanup_expired_cache()` task removes expired SQLite rows.--### Encrypted Credentials--API keys and OAuth tokens live in a **separate SQLite database** (`credentials.db`) isolated from the main `machina.db`. Encryption uses Fernet (AES-128-CBC + HMAC-SHA256) with keys derived from a server-scoped config key via PBKDF2HMAC (600K iterations, OWASP 2024 recommendation).--```-API_KEY_ENCRYPTION_KEY (.env) + salt (from credentials.db, 256 bits)- |- v- PBKDF2HMAC-SHA256- (600,000 iterations)- |- v- urlsafe_b64encode -> Fernet key- |- v- held in memory only- |- v- encrypt() / decrypt() inside EncryptionService-```--Two separate credential systems inside `credentials.db`:-- **API key system** (`EncryptedAPIKey` table): provider keys the user enters manually-- **OAuth token system** (`EncryptedOAuthToken` table): tokens from OAuth flows (Google, Twitter, Claude.ai)--All routers access credentials through `AuthService` only. Direct database access is forbidden. Decrypted values are cached in `AuthService` memory dicts and never written to disk or Redis.--For cloud deployments, `CREDENTIAL_BACKEND` can be switched to `keyring` (OS-native) or `aws` (Secrets Manager) via `CredentialBackend` abstraction.--### Authentication--JWT in HttpOnly cookies following the n8n pattern. Two modes:--- `AUTH_MODE=single` - first user becomes owner, registration disabled after-- `AUTH_MODE=multi` - open registration for cloud deployments-- `VITE_AUTH_ENABLED=false` - bypass login entirely for local development--WebSocket connections check the JWT cookie before accepting. Auth context has exponential-backoff retry (5 attempts) to survive race conditions where the frontend starts before the backend is ready.--**Read more**: [credentials_encryption.md](docs-internal/credentials_encryption.md)--</details>+Full setup and scripts reference: [SETUP.md](docs-internal/SETUP.md) - [SCRIPTS.md](docs-internal/SCRIPTS.md)<details><summary><b>Full Documentation Index</b></summary>diff --git a/docs/diagrams/ai-agent-routing.svg b/docs/diagrams/ai-agent-routing.svgnew file mode 100644index 00000000..f6e74090--- /dev/null+++ b/docs/diagrams/ai-agent-routing.svg@@ -0,0 +1,138 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1400 900" font-family="ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace">+ <defs>+ <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse">+ <path d="M0,0 L10,5 L0,10 z" fill="#f8f8f2"/>+ </marker>+ <style>+ .bg { fill: #282a36; }+ .entry { fill: #44475a; stroke: #f1fa8c; stroke-width: 2.5; }+ .method { fill: #44475a; stroke: #ffb86c; stroke-width: 2; }+ .decision { fill: #44475a; stroke: #bd93f9; stroke-width: 2.5; }+ .native { fill: #44475a; stroke: #8be9fd; stroke-width: 2; }+ .langchain { fill: #44475a; stroke: #bd93f9; stroke-width: 2; }+ .shared { fill: #44475a; stroke: #50fa7b; stroke-width: 2.5; }+ .title { fill: #f8f8f2; font-size: 16px; font-weight: 700; }+ .big { fill: #f8f8f2; font-size: 17px; font-weight: 700; }+ .sub { fill: #f8f8f2; font-size: 11px; }+ .path { fill: #8be9fd; font-size: 11px; }+ .path-lc { fill: #bd93f9; font-size: 11px; }+ .conn { stroke: #f8f8f2; stroke-width: 1.8; fill: none; }+ .conn-native { stroke: #8be9fd; stroke-width: 2; fill: none; }+ .conn-lc { stroke: #bd93f9; stroke-width: 2; fill: none; }+ .branch-label { fill: #f1fa8c; font-size: 12px; font-style: italic; font-weight: 700; }+ .col-header { fill: #6272a4; font-size: 13px; text-transform: uppercase; letter-spacing: 1.5px; font-weight: 700; }+ .caption { fill: #6272a4; font-size: 11px; }+ </style>+ </defs>++ <rect class="bg" width="1400" height="900"/>++ <!-- Title -->+ <text x="700" y="35" class="title" text-anchor="middle" font-size="20">AI Service: Native SDK vs LangChain Routing</text>+ <text x="700" y="58" class="caption" text-anchor="middle">server/services/ai.py + server/services/llm/</text>++ <!-- AIService entry -->+ <rect class="entry" x="540" y="85" width="320" height="70" rx="8"/>+ <text x="700" y="115" class="big" text-anchor="middle">AIService</text>+ <text x="700" y="138" class="sub" text-anchor="middle">server/services/ai.py (~4500 lines)</text>++ <!-- Branch arrows to two methods -->+ <path class="conn" d="M 700 155 L 700 185 L 300 185 L 300 215" marker-end="url(#arrow)"/>+ <path class="conn" d="M 700 155 L 700 185 L 1100 185 L 1100 215" marker-end="url(#arrow)"/>++ <!-- Column headers -->+ <text x="300" y="205" class="col-header" text-anchor="middle">Method 1: Direct Chat</text>+ <text x="1100" y="205" class="col-header" text-anchor="middle">Method 2: Agent Tool-Calling</text>++ <!-- LEFT COLUMN: execute_chat -->+ <rect class="method" x="120" y="215" width="360" height="75" rx="8"/>+ <text x="300" y="243" class="big" text-anchor="middle">execute_chat(parameters)</text>+ <text x="300" y="265" class="sub" text-anchor="middle">Used by chat model nodes</text>+ <text x="300" y="283" class="caption" text-anchor="middle">openaiChatModel, anthropicChatModel, ...</text>++ <!-- Decision: is_native_provider -->+ <polygon class="decision" points="300,310 470,385 300,460 130,385"/>+ <text x="300" y="375" class="big" text-anchor="middle">is_native_provider</text>+ <text x="300" y="400" class="big" text-anchor="middle">(provider)?</text>++ <!-- Arrow from method to decision -->+ <path class="conn" d="M 300 290 L 300 310" marker-end="url(#arrow)"/>++ <!-- Branch yes (native) -->+ <path class="conn-native" d="M 470 385 L 530 385 L 530 495" marker-end="url(#arrow)"/>+ <text x="505" y="375" class="branch-label">yes</text>++ <!-- Branch no (LangChain fallback) -->+ <path class="conn-lc" d="M 130 385 L 70 385 L 70 495" marker-end="url(#arrow)"/>+ <text x="95" y="375" class="branch-label">no</text>++ <!-- Native path box -->+ <rect class="native" x="340" y="495" width="380" height="150" rx="8"/>+ <text x="530" y="522" class="title" text-anchor="middle" fill="#8be9fd">Native SDK Path</text>+ <text x="530" y="545" class="sub" text-anchor="middle">create_provider(name, api_key)</text>+ <text x="530" y="563" class="sub" text-anchor="middle">lazy-imports one of:</text>+ <text x="530" y="582" class="path" text-anchor="middle">AnthropicProvider / OpenAIProvider</text>+ <text x="530" y="600" class="path" text-anchor="middle">GeminiProvider / OpenRouterProvider</text>+ <text x="530" y="622" class="sub" text-anchor="middle">OpenAI-compatible (xAI, DeepSeek,</text>+ <text x="530" y="638" class="sub" text-anchor="middle">Kimi, Mistral): shared OpenAIProvider + base_url</text>++ <!-- LangChain fallback box -->+ <rect class="langchain" x="10" y="495" width="260" height="150" rx="8"/>+ <text x="140" y="522" class="title" text-anchor="middle" fill="#bd93f9">LangChain Fallback</text>+ <text x="140" y="545" class="sub" text-anchor="middle">create_model()</text>+ <text x="140" y="565" class="path-lc" text-anchor="middle">ChatGroq</text>+ <text x="140" y="583" class="path-lc" text-anchor="middle">ChatCerebras</text>+ <text x="140" y="608" class="sub" text-anchor="middle">(providers without native</text>+ <text x="140" y="624" class="sub" text-anchor="middle">SDK implementation yet)</text>++ <!-- Both converge on LLMResponse -->+ <path class="conn-native" d="M 530 645 L 530 690" marker-end="url(#arrow)"/>+ <path class="conn-lc" d="M 140 645 L 140 680 L 340 680 L 340 690" marker-end="url(#arrow)"/>++ <!-- RIGHT COLUMN: execute_agent / execute_chat_agent -->+ <rect class="method" x="920" y="215" width="360" height="75" rx="8"/>+ <text x="1100" y="243" class="big" text-anchor="middle">execute_agent(parameters)</text>+ <text x="1100" y="263" class="sub" text-anchor="middle">execute_chat_agent(parameters)</text>+ <text x="1100" y="283" class="caption" text-anchor="middle">aiAgent, chatAgent, 13 specialized agents</text>++ <!-- Arrow -->+ <path class="conn-lc" d="M 1100 290 L 1100 330" marker-end="url(#arrow)"/>++ <!-- LangChain + LangGraph box -->+ <rect class="langchain" x="920" y="330" width="360" height="130" rx="8"/>+ <text x="1100" y="358" class="title" text-anchor="middle" fill="#bd93f9">LangChain + LangGraph</text>+ <text x="1100" y="382" class="sub" text-anchor="middle">create_model() -> LangChain class</text>+ <text x="1100" y="402" class="path-lc" text-anchor="middle">ChatOpenAI / ChatAnthropic</text>+ <text x="1100" y="420" class="path-lc" text-anchor="middle">ChatGoogleGenerativeAI / ChatGroq / ...</text>+ <text x="1100" y="442" class="sub" text-anchor="middle">.bind_tools([StructuredTool, ...])</text>++ <!-- Arrow to state graph -->+ <path class="conn-lc" d="M 1100 460 L 1100 500" marker-end="url(#arrow)"/>++ <!-- LangGraph StateGraph box -->+ <rect class="langchain" x="900" y="500" width="400" height="155" rx="8"/>+ <text x="1100" y="528" class="title" text-anchor="middle" fill="#bd93f9">LangGraph StateGraph</text>+ <text x="1100" y="552" class="sub" text-anchor="middle">START -> agent (LLM) -> should_continue?</text>+ <text x="1100" y="572" class="sub" text-anchor="middle">if tools needed: tools node -> loop back</text>+ <text x="1100" y="592" class="sub" text-anchor="middle">else: END</text>+ <text x="1100" y="615" class="caption" text-anchor="middle">Max iterations guard against tool loops</text>+ <text x="1100" y="635" class="caption" text-anchor="middle">Agent Teams: delegate_to_<type> tools auto-injected</text>++ <!-- Both columns converge on shared LLMResponse -->+ <rect class="shared" x="340" y="690" width="720" height="85" rx="8"/>+ <text x="700" y="718" class="title" text-anchor="middle" fill="#50fa7b">Normalized LLMResponse</text>+ <text x="700" y="740" class="sub" text-anchor="middle">content, thinking, tool_calls, usage (tokens), model, finish_reason</text>+ <text x="700" y="758" class="caption" text-anchor="middle">services/llm/protocol.py -- dataclass shared across all providers</text>++ <!-- Arrow from right column to shared -->+ <path class="conn-lc" d="M 1100 655 L 1100 685 L 720 685 L 720 690" marker-end="url(#arrow)"/>++ <!-- Shared infrastructure at bottom -->+ <rect class="shared" x="200" y="800" width="1000" height="80" rx="8"/>+ <text x="700" y="828" class="title" text-anchor="middle" fill="#50fa7b">Shared Infrastructure</text>+ <text x="700" y="850" class="sub" text-anchor="middle">compaction.py: token tracking, cost calculation, model-aware compaction (50% of context window)</text>+ <text x="700" y="868" class="sub" text-anchor="middle">pricing.py: USD cost per provider from config/pricing.json  |  model_registry.py: context length lookup</text>++ <!-- Arrow from LLMResponse down to shared infra -->+ <path class="conn" d="M 700 775 L 700 800" marker-end="url(#arrow)"/>+</svg>diff --git a/docs/diagrams/execution-flow.svg b/docs/diagrams/execution-flow.svgnew file mode 100644index 00000000..bc0591f4--- /dev/null+++ b/docs/diagrams/execution-flow.svg@@ -0,0 +1,108 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800" font-family="ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace">+ <defs>+ <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse">+ <path d="M0,0 L10,5 L0,10 z" fill="#f8f8f2"/>+ </marker>+ <style>+ .bg { fill: #282a36; }+ .entry { fill: #44475a; stroke: #8be9fd; stroke-width: 2.5; }+ .decision { fill: #44475a; stroke: #bd93f9; stroke-width: 2.5; }+ .path-temporal { fill: #44475a; stroke: #50fa7b; stroke-width: 2; }+ .path-redis { fill: #44475a; stroke: #8be9fd; stroke-width: 2; }+ .path-seq { fill: #44475a; stroke: #ffb86c; stroke-width: 2; }+ .shared { fill: #44475a; stroke: #f1fa8c; stroke-width: 2.5; }+ .output { fill: #44475a; stroke: #ff79c6; stroke-width: 2.5; }+ .title { fill: #f8f8f2; font-size: 16px; font-weight: 700; }+ .big { fill: #f8f8f2; font-size: 18px; font-weight: 700; }+ .sub { fill: #f8f8f2; font-size: 12px; }+ .mode-label { fill: #f8f8f2; font-size: 14px; font-weight: 700; }+ .conn { stroke: #f8f8f2; stroke-width: 1.8; fill: none; }+ .conn-yes { stroke: #50fa7b; stroke-width: 1.8; fill: none; }+ .conn-no { stroke: #ff79c6; stroke-width: 1.8; fill: none; }+ .branch-label { fill: #f1fa8c; font-size: 12px; font-style: italic; font-weight: 700; }+ .caption { fill: #6272a4; font-size: 11px; }+ </style>+ </defs>++ <rect class="bg" width="1200" height="800"/>++ <!-- Entry node -->+ <rect class="entry" x="460" y="30" width="280" height="60" rx="8"/>+ <text x="600" y="58" class="title" text-anchor="middle">workflow.execute()</text>+ <text x="600" y="78" class="sub" text-anchor="middle">(WorkflowService facade)</text>++ <!-- Arrow to first decision -->+ <path class="conn" d="M 600 90 L 600 135" marker-end="url(#arrow)"/>++ <!-- First decision: Temporal? -->+ <polygon class="decision" points="600,140 780,210 600,280 420,210"/>+ <text x="600" y="200" class="big" text-anchor="middle">TEMPORAL_ENABLED</text>+ <text x="600" y="225" class="big" text-anchor="middle">and reachable?</text>++ <!-- Branch yes to Temporal path -->+ <path class="conn-yes" d="M 780 210 L 950 210 L 950 320" marker-end="url(#arrow)"/>+ <text x="830" y="200" class="branch-label">yes</text>++ <!-- Branch no to second decision -->+ <path class="conn-no" d="M 420 210 L 260 210 L 260 280" marker-end="url(#arrow)"/>+ <text x="325" y="200" class="branch-label">no</text>++ <!-- Second decision: Redis? -->+ <polygon class="decision" points="260,285 430,350 260,415 90,350"/>+ <text x="260" y="345" class="big" text-anchor="middle">Redis</text>+ <text x="260" y="370" class="big" text-anchor="middle">available?</text>++ <!-- Branch yes from second decision -->+ <path class="conn-yes" d="M 430 350 L 600 350 L 600 320" marker-end="url(#arrow)"/>+ <text x="475" y="340" class="branch-label">yes</text>++ <!-- Branch no from second decision -->+ <path class="conn-no" d="M 260 415 L 260 445" marker-end="url(#arrow)"/>+ <text x="200" y="440" class="branch-label">no</text>++ <!-- Three execution mode boxes -->+ <!-- Temporal Distributed (right) -->+ <rect class="path-temporal" x="820" y="320" width="260" height="150" rx="8"/>+ <text x="950" y="348" class="mode-label" text-anchor="middle">Temporal Distributed</text>+ <text x="950" y="372" class="sub" text-anchor="middle">per-node activities</text>+ <text x="950" y="392" class="sub" text-anchor="middle">3 retries, 10 min timeout</text>+ <text x="950" y="412" class="sub" text-anchor="middle">horizontal scaling</text>+ <text x="950" y="432" class="sub" text-anchor="middle">FIRST_COMPLETED scheduling</text>+ <text x="950" y="458" class="caption" text-anchor="middle">services/temporal/</text>++ <!-- Parallel Local Redis (center) -->+ <rect class="path-redis" x="470" y="320" width="260" height="150" rx="8"/>+ <text x="600" y="348" class="mode-label" text-anchor="middle">Parallel Local (Redis)</text>+ <text x="600" y="372" class="sub" text-anchor="middle">decide loop + Kahn layers</text>+ <text x="600" y="392" class="sub" text-anchor="middle">asyncio.gather() fork/join</text>+ <text x="600" y="412" class="sub" text-anchor="middle">Prefect-style input hash cache</text>+ <text x="600" y="432" class="sub" text-anchor="middle">DLQ + heartbeat recovery</text>+ <text x="600" y="458" class="caption" text-anchor="middle">services/execution/</text>++ <!-- Sequential fallback (left) -->+ <rect class="path-seq" x="120" y="445" width="280" height="120" rx="8"/>+ <text x="260" y="473" class="mode-label" text-anchor="middle">Sequential Fallback</text>+ <text x="260" y="497" class="sub" text-anchor="middle">simple topological walk</text>+ <text x="260" y="517" class="sub" text-anchor="middle">no cache, no retry, no DLQ</text>+ <text x="260" y="537" class="sub" text-anchor="middle">minimal environments only</text>+ <text x="260" y="558" class="caption" text-anchor="middle">_execute_sequential()</text>++ <!-- Converge arrows to shared node executor box -->+ <path class="conn" d="M 950 470 L 950 590 L 600 590" marker-end="url(#arrow)"/>+ <path class="conn" d="M 600 470 L 600 590" marker-end="url(#arrow)"/>+ <path class="conn" d="M 260 565 L 260 590 L 600 590" marker-end="url(#arrow)"/>++ <!-- Shared node handler box -->+ <rect class="shared" x="330" y="595" width="540" height="90" rx="8"/>+ <text x="600" y="625" class="title" text-anchor="middle">NodeExecutor.execute()</text>+ <text x="600" y="648" class="sub" text-anchor="middle">registry dispatch: {node_type: handler via functools.partial}</text>+ <text x="600" y="668" class="sub" text-anchor="middle">handlers/*.py -> result dict -> ExecutionContext</text>++ <!-- Arrow down to status broadcast -->+ <path class="conn" d="M 600 685 L 600 715" marker-end="url(#arrow)"/>++ <!-- Status broadcast -->+ <rect class="output" x="380" y="720" width="440" height="60" rx="8"/>+ <text x="600" y="745" class="title" text-anchor="middle">Status broadcast via StatusBroadcaster</text>+ <text x="600" y="765" class="sub" text-anchor="middle">node_status + node_output -> Frontend WebSocket</text>+</svg>diff --git a/docs/diagrams/node-anatomy.svg b/docs/diagrams/node-anatomy.svgnew file mode 100644index 00000000..7ed3df2b--- /dev/null+++ b/docs/diagrams/node-anatomy.svg@@ -0,0 +1,138 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1400 800" font-family="ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace">+ <defs>+ <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse">+ <path d="M0,0 L10,5 L0,10 z" fill="#f8f8f2"/>+ </marker>+ <style>+ .bg { fill: #282a36; }+ .col-header { fill: #6272a4; font-size: 13px; text-transform: uppercase; letter-spacing: 1.5px; font-weight: 700; }+ .col-sub { fill: #6272a4; font-size: 11px; }+ .fe-box { fill: #44475a; stroke: #8be9fd; stroke-width: 2; }+ .be-box { fill: #44475a; stroke: #bd93f9; stroke-width: 2; }+ .comm-box { fill: #44475a; stroke: #f1fa8c; stroke-width: 2; }+ .ai-box { fill: #44475a; stroke: #50fa7b; stroke-width: 2; }+ .title { fill: #f8f8f2; font-size: 14px; font-weight: 700; }+ .path { fill: #8be9fd; font-size: 11px; font-family: ui-monospace, monospace; }+ .path-be { fill: #bd93f9; font-size: 11px; font-family: ui-monospace, monospace; }+ .sub { fill: #f8f8f2; font-size: 11px; }+ .conn { stroke: #f8f8f2; stroke-width: 1.8; fill: none; }+ .label { fill: #f1fa8c; font-size: 11px; font-style: italic; }+ .step { fill: #ffb86c; font-size: 12px; font-weight: 700; }+ </style>+ </defs>++ <rect class="bg" width="1400" height="800"/>++ <!-- Title -->+ <text x="700" y="35" class="title" text-anchor="middle" font-size="20">Anatomy of a Workflow Node</text>+ <text x="700" y="58" class="col-sub" text-anchor="middle" font-size="12">Where to touch code when adding a new node</text>++ <!-- Column headers -->+ <text x="230" y="100" class="col-header" text-anchor="middle">Frontend (client/)</text>+ <text x="230" y="118" class="col-sub" text-anchor="middle">TypeScript + React</text>++ <text x="700" y="100" class="col-header" text-anchor="middle">Communication</text>+ <text x="700" y="118" class="col-sub" text-anchor="middle">WebSocket</text>++ <text x="1170" y="100" class="col-header" text-anchor="middle">Backend (server/)</text>+ <text x="1170" y="118" class="col-sub" text-anchor="middle">Python + FastAPI</text>++ <!-- Frontend column boxes -->+ <!-- 1. Node definition -->+ <rect class="fe-box" x="50" y="145" width="360" height="85" rx="8"/>+ <text x="70" y="170" class="title">1. Node definition</text>+ <text x="70" y="190" class="path">client/src/nodeDefinitions/<category>.ts</text>+ <text x="70" y="210" class="sub">INodeProperties: displayName, group, inputs,</text>+ <text x="70" y="224" class="sub">outputs, properties[], displayOptions.show</text>++ <!-- 2. Parameter renderer -->+ <rect class="fe-box" x="50" y="255" width="360" height="85" rx="8"/>+ <text x="70" y="280" class="title">2. Parameter panel</text>+ <text x="70" y="300" class="path">client/src/components/ParameterRenderer.tsx</text>+ <text x="70" y="320" class="sub">Renders parameters, conditional display,</text>+ <text x="70" y="334" class="sub">drag-and-drop template variables</text>++ <!-- 3. Canvas / execution -->+ <rect class="fe-box" x="50" y="365" width="360" height="85" rx="8"/>+ <text x="70" y="390" class="title">3. Canvas & Run button</text>+ <text x="70" y="410" class="path">client/src/Dashboard.tsx</text>+ <text x="70" y="430" class="sub">React Flow canvas, useExecution hook,</text>+ <text x="70" y="444" class="sub">sends execute_node via WebSocket</text>++ <!-- 4. Registry/credentials -->+ <rect class="fe-box" x="50" y="475" width="360" height="85" rx="8"/>+ <text x="70" y="500" class="title">4. Credentials (if needed)</text>+ <text x="70" y="520" class="path">client/src/components/CredentialsModal.tsx</text>+ <text x="70" y="540" class="sub">API key entry + OAuth flows</text>+ <text x="70" y="554" class="sub">via useApiKeys hook</text>++ <!-- Communication column -->+ <rect class="comm-box" x="530" y="255" width="340" height="250" rx="8"/>+ <text x="700" y="290" class="title" text-anchor="middle">WebSocket /ws/status</text>+ <text x="700" y="315" class="sub" text-anchor="middle">Single persistent connection</text>+ <text x="700" y="335" class="sub" text-anchor="middle">between UI and backend</text>++ <!-- Message type arrows -->+ <text x="700" y="375" class="label" text-anchor="middle">execute_node</text>+ <path class="conn" d="M 570 385 L 830 385" marker-end="url(#arrow)"/>++ <text x="700" y="420" class="label" text-anchor="middle">node_status</text>+ <path class="conn" d="M 830 430 L 570 430" marker-end="url(#arrow)"/>++ <text x="700" y="465" class="label" text-anchor="middle">node_output</text>+ <path class="conn" d="M 830 475 L 570 475" marker-end="url(#arrow)"/>++ <text x="700" y="495" class="sub" text-anchor="middle" fill="#6272a4" font-size="10">89 handler message types</text>++ <!-- Arrows from frontend column into comm column -->+ <path class="conn" d="M 410 405 L 530 385" marker-end="url(#arrow)"/>++ <!-- Backend column boxes -->+ <!-- A. Router / dispatch -->+ <rect class="be-box" x="990" y="145" width="360" height="85" rx="8"/>+ <text x="1010" y="170" class="title">A. Router / dispatch</text>+ <text x="1010" y="190" class="path-be">server/routers/websocket.py</text>+ <text x="1010" y="210" class="sub">@ws_handler decorators, dispatches</text>+ <text x="1010" y="224" class="sub">incoming messages to handlers</text>++ <!-- B. Node executor registry -->+ <rect class="be-box" x="990" y="255" width="360" height="85" rx="8"/>+ <text x="1010" y="280" class="title">B. Registry dispatch</text>+ <text x="1010" y="300" class="path-be">server/services/node_executor.py</text>+ <text x="1010" y="320" class="sub">Dict[node_type, handler] via</text>+ <text x="1010" y="334" class="sub">functools.partial dependency injection</text>++ <!-- C. Handler -->+ <rect class="be-box" x="990" y="365" width="360" height="85" rx="8"/>+ <text x="1010" y="390" class="title">C. Business logic</text>+ <text x="1010" y="410" class="path-be">server/services/handlers/<name>.py</text>+ <text x="1010" y="430" class="sub">handle_<name>(node_id, parameters,</text>+ <text x="1010" y="444" class="sub">context, ...) -> result dict</text>++ <!-- D. AI service (optional) -->+ <rect class="ai-box" x="990" y="475" width="360" height="85" rx="8"/>+ <text x="1010" y="500" class="title">D. AI layer (for AI nodes)</text>+ <text x="1010" y="520" class="path-be">server/services/ai.py + llm/</text>+ <text x="1010" y="540" class="sub">Native SDK path or LangChain + LangGraph</text>+ <text x="1010" y="554" class="sub">with tool calling</text>++ <!-- Arrows inside backend column (vertical flow) -->+ <path class="conn" d="M 1170 230 L 1170 255" marker-end="url(#arrow)"/>+ <path class="conn" d="M 1170 340 L 1170 365" marker-end="url(#arrow)"/>+ <path class="conn" d="M 1170 450 L 1170 475" marker-end="url(#arrow)"/>++ <!-- Arrow from comm column into backend -->+ <path class="conn" d="M 870 385 L 990 185" marker-end="url(#arrow)"/>++ <!-- Registration step note -->+ <rect class="be-box" x="450" y="590" width="520" height="80" rx="8" fill="#282a36" stroke="#ff79c6"/>+ <text x="710" y="615" class="title" text-anchor="middle" fill="#ff79c6">Register the handler</text>+ <text x="710" y="635" class="sub" text-anchor="middle">Add entry to registry dict in services/node_executor.py:</text>+ <text x="710" y="655" class="path-be" text-anchor="middle">registry['yourNode'] = partial(handle_your_node, database=self.database)</text>++ <!-- Flow legend -->+ <text x="50" y="710" class="step">Contribution checklist</text>+ <text x="50" y="732" class="sub">1. Define node in TypeScript (left col) -> 2. Write handler in Python (right col)</text>+ <text x="50" y="750" class="sub">3. Register in node_executor.py -> 4. Restart dev server -> Node appears in palette</text>+ <text x="50" y="770" class="sub" fill="#6272a4">Full step-by-step guide: docs-internal/node_creation.md</text>+</svg>diff --git a/docs/diagrams/system-overview.svg b/docs/diagrams/system-overview.svgnew file mode 100644index 00000000..c896e358--- /dev/null+++ b/docs/diagrams/system-overview.svg@@ -0,0 +1,129 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 720" font-family="ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace">+ <defs>+ <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse">+ <path d="M0,0 L10,5 L0,10 z" fill="#f8f8f2"/>+ </marker>+ <style>+ .bg { fill: #282a36; }+ .panel { fill: #44475a; stroke-width: 2; }+ .panel-frontend { stroke: #8be9fd; }+ .panel-backend { stroke: #bd93f9; }+ .panel-exec { stroke: #ffb86c; }+ .panel-ext { stroke: #50fa7b; }+ .title { fill: #f8f8f2; font-size: 18px; font-weight: 700; }+ .sub { fill: #f8f8f2; font-size: 12px; }+ .label { fill: #f1fa8c; font-size: 11px; font-style: italic; }+ .conn { stroke: #f8f8f2; stroke-width: 1.8; fill: none; }+ .small-box { fill: #282a36; stroke-width: 1.5; }+ .small-exec { stroke: #ffb86c; }+ .small-ext { stroke: #50fa7b; }+ .tier-label { fill: #6272a4; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }+ </style>+ </defs>++ <rect class="bg" width="1200" height="720"/>++ <!-- Tier label: Frontend -->+ <text x="40" y="55" class="tier-label">Tier 1</text>+ <!-- Frontend panel -->+ <rect class="panel panel-frontend" x="40" y="70" width="760" height="110" rx="8"/>+ <text x="60" y="100" class="title">Frontend (client/)</text>+ <text x="60" y="128" class="sub">React + TypeScript + React Flow + Zustand + Ant Design</text>+ <text x="60" y="148" class="sub">Dracula-themed canvas, parameter panel, credentials modal</text>+ <text x="60" y="168" class="sub">96 workflow nodes rendered via INodeProperties interface</text>++ <!-- Arrow Frontend -> Backend -->+ <path class="conn" d="M 420 180 L 420 240" marker-end="url(#arrow)"/>+ <path class="conn" d="M 420 240 L 420 180" marker-end="url(#arrow)"/>+ <text x="435" y="215" class="label">WebSocket /ws/status</text>++ <!-- Tier label: Backend -->+ <text x="40" y="260" class="tier-label">Tier 2</text>+ <!-- Backend panel -->+ <rect class="panel panel-backend" x="40" y="275" width="760" height="130" rx="8"/>+ <text x="60" y="305" class="title">Backend (server/)</text>+ <text x="60" y="333" class="sub">FastAPI + 89 WebSocket handlers + dependency injection container</text>+ <text x="60" y="353" class="sub">WorkflowService (facade) -> NodeExecutor -> per-node handlers</text>+ <text x="60" y="373" class="sub">ParameterResolver -> template {{node.field}} substitution</text>+ <text x="60" y="393" class="sub">AuthService -> encrypted credentials (Fernet + PBKDF2)</text>++ <!-- Arrow Backend -> Execution -->+ <path class="conn" d="M 420 405 L 420 465" marker-end="url(#arrow)"/>+ <text x="435" y="440" class="label">async handlers</text>++ <!-- Tier label: Execution -->+ <text x="40" y="485" class="tier-label">Tier 3</text>+ <!-- Execution tier panel -->+ <rect class="panel panel-exec" x="40" y="500" width="760" height="180" rx="8"/>+ <text x="60" y="530" class="title">Execution tier</text>++ <!-- Sub-boxes inside execution tier -->+ <rect class="small-box small-exec" x="60" y="545" width="140" height="50" rx="6"/>+ <text x="130" y="568" class="sub" text-anchor="middle">Temporal</text>+ <text x="130" y="584" class="sub" text-anchor="middle" font-size="10">distributed workers</text>++ <rect class="small-box small-exec" x="215" y="545" width="140" height="50" rx="6"/>+ <text x="285" y="568" class="sub" text-anchor="middle">Redis</text>+ <text x="285" y="584" class="sub" text-anchor="middle" font-size="10">cache + locks + streams</text>++ <rect class="small-box small-exec" x="370" y="545" width="140" height="50" rx="6"/>+ <text x="440" y="568" class="sub" text-anchor="middle">SQLite</text>+ <text x="440" y="584" class="sub" text-anchor="middle" font-size="10">machina.db + credentials.db</text>++ <rect class="small-box small-exec" x="525" y="545" width="140" height="50" rx="6"/>+ <text x="595" y="568" class="sub" text-anchor="middle">Node.js server</text>+ <text x="595" y="584" class="sub" text-anchor="middle" font-size="10">JS/TS code executor</text>++ <rect class="small-box small-exec" x="60" y="608" width="220" height="50" rx="6"/>+ <text x="170" y="631" class="sub" text-anchor="middle">WhatsApp RPC (port 9400)</text>+ <text x="170" y="647" class="sub" text-anchor="middle" font-size="10">whatsapp-rpc binary</text>++ <rect class="small-box small-exec" x="295" y="608" width="220" height="50" rx="6"/>+ <text x="405" y="631" class="sub" text-anchor="middle">Android relay</text>+ <text x="405" y="647" class="sub" text-anchor="middle" font-size="10">persistent WebSocket</text>++ <rect class="small-box small-exec" x="530" y="608" width="250" height="50" rx="6"/>+ <text x="655" y="631" class="sub" text-anchor="middle">Temporal server</text>+ <text x="655" y="647" class="sub" text-anchor="middle" font-size="10">ports 7233 / 8233 / 8080</text>++ <!-- Right sidebar: External services -->+ <text x="830" y="55" class="tier-label">External</text>+ <rect class="panel panel-ext" x="830" y="70" width="340" height="610" rx="8"/>+ <text x="850" y="100" class="title">External services</text>++ <text x="850" y="130" class="sub" font-weight="700" fill="#8be9fd">LLM providers (10)</text>+ <text x="850" y="150" class="sub">OpenAI, Anthropic, Gemini, OpenRouter,</text>+ <text x="850" y="168" class="sub">xAI, DeepSeek, Kimi, Mistral, Groq, Cerebras</text>++ <text x="850" y="200" class="sub" font-weight="700" fill="#8be9fd">Google Workspace</text>+ <text x="850" y="220" class="sub">Gmail, Calendar, Drive, Sheets,</text>+ <text x="850" y="238" class="sub">Tasks, Contacts (unified OAuth)</text>++ <text x="850" y="270" class="sub" font-weight="700" fill="#8be9fd">Social platforms</text>+ <text x="850" y="290" class="sub">WhatsApp, Telegram, Twitter/X,</text>+ <text x="850" y="308" class="sub">Discord, Slack, Signal (unified)</text>++ <text x="850" y="340" class="sub" font-weight="700" fill="#8be9fd">Search APIs</text>+ <text x="850" y="360" class="sub">Brave, Serper, Perplexity,</text>+ <text x="850" y="378" class="sub">DuckDuckGo (free)</text>++ <text x="850" y="410" class="sub" font-weight="700" fill="#8be9fd">Web scraping</text>+ <text x="850" y="430" class="sub">Apify actors, Crawlee scraper,</text>+ <text x="850" y="448" class="sub">residential proxy providers</text>++ <text x="850" y="480" class="sub" font-weight="700" fill="#8be9fd">Device integration</text>+ <text x="850" y="500" class="sub">Android via ADB relay,</text>+ <text x="850" y="518" class="sub">16 Android service nodes</text>++ <text x="850" y="550" class="sub" font-weight="700" fill="#8be9fd">Vector + RAG</text>+ <text x="850" y="570" class="sub">ChromaDB, Qdrant, Pinecone,</text>+ <text x="850" y="588" class="sub">HuggingFace embeddings</text>++ <text x="850" y="620" class="sub" font-weight="700" fill="#8be9fd">Maps</text>+ <text x="850" y="640" class="sub">Google Maps Geocoding,</text>+ <text x="850" y="658" class="sub">Places nearbySearch</text>++ <!-- Arrow Execution -> External -->+ <path class="conn" d="M 800 590 L 830 590" marker-end="url(#arrow)"/>+ <text x="805" y="580" class="label">HTTP / SDK</text>+</svg>