```mermaid
%% MCP Application Architecture
%% Updated from codebase analysis -- March 2026
graph TD
%% =========================================================================
%% SUPERVISION TREE
%% =========================================================================
subgraph Supervisor["Mcp.Supervisor (one_for_one)"]
direction TB
UsersDB["Sqler
:users_db"]
CompileLogDB["Sqler
:compile_log_db"]
Manager["MCPServer.Manager"]
HTTPS["Bandit HTTPS :8443
MCPServer.Router"]
AC["AutoCompile"]
LS["LogSubscriber"]
AL["Alarm"]
PO["Pushover"]
MCT["MCPClientTracker"]
ChatDB["Sqler
:chat_db"]
SCT["ServerChatTracker"]
SchedDB["Sqler
:scheduler"]
A2ADB["Sqler
:a2a_db"]
TasksDB["Sqler
:tasks_db"]
PSDB["Sqler
:page_scraper_db"]
PSReg["Registry
PageScraperRegistry"]
ZmqReg["Registry
ZmqCounter"]
WsReg["Registry
WsRegistry"]
ToolAudit["ToolAudit"]
MonSrv["MonitorServer"]
APP["App"]
WFExec["WorkflowExecutor"]
MCPConnReg["MCPConnectionRegistry"]
MCPConnRegR["Registry
MCPConnectionRegistry"]
MCPConnSup["MCPConnectionRegistry
Supervisor"]
KnowledgeDB["Sqler
:knowledge_db"]
ContactFormsDB["Sqler
:contact_forms_db"]
LLMFinch["LLMGateway.Finch"]
LLMGwDB["Sqler
:llm_gateway_db"]
PermPubSub["Registry
PermissionPubSub"]
SseReg["Registry
SseRegistry"]
SessionReg["Registry
McpSessionRegistry"]
BFW["BlogFileWatcher"]
SLW["ServerLogWriter"]
Tidewave["Bandit :4001
Tidewave (dev)"]
end
%% =========================================================================
%% EXTERNAL ACTORS
%% =========================================================================
Browser(("Browser
(User)"))
IEx(("IEx
Console"))
FS(("Filesystem
Events"))
PushAPI(("Pushover
API"))
AnthropicAPI(("Anthropic
API"))
OpenRouterAPI(("OpenRouter
API"))
PerplexityAPI(("Perplexity
API"))
GeminiAPI(("Google
Gemini API"))
OpenAIAPI(("OpenAI
API"))
PythonProc(("Python
ZeroMQ"))
ApifyMCP(("Apify Weather
MCP Server"))
VoyagerAPI(("VoyageAI
Embeddings"))
WhatsAppBridge(("WhatsApp
Node.js Bridge"))
ElevenLabsAPI(("ElevenLabs
TTS API"))
YouTubeAPI(("YouTube
Data API v3"))
GoogleWS(("Google Workspace
MCP Server"))
AgentMailAPI(("AgentMail
API"))
GoogleOIDC(("Google
OIDC"))
ClaudeCLI(("Claude Code
CLI"))
%% =========================================================================
%% HTTP REQUEST FLOW
%% =========================================================================
Browser -- "HTTPS :8443" --> HTTPS
ClaudeCLI -- "SSE :8443
Bearer token" --> HTTPS
ClaudeCLI -- "HTTP :4001
Tidewave MCP" --> Tidewave
subgraph RouterLogic["MCPServer.Router (Plug.Router)"]
direction TB
Auth["require_authentication
cookie decrypt / bearer token"]
CSRF["csrf_protection"]
Routes["Routes:
POST /login . POST /message . GET /sse
GET /chat . GET /blogs . GET /tasks
GET /nis . GET /monitor . GET /access-control
GET /summaries . GET /workflow . GET /workflows
GET /knowledge . GET /mcp-connections
POST /mcp . POST /a2a . /api/*"]
GetUser["get_user/1
Auth.AuthContext.for_user!"]
end
HTTPS --> Auth
Auth --> CSRF
CSRF --> Routes
Routes --> GetUser
%% =========================================================================
%% MCP SERVER LAYER
%% =========================================================================
subgraph MCPLayer["MCP Server Layer (~100+ tools)"]
direction TB
Manager
MCP["MCPServer
(Hermes.Server behaviour)"]
subgraph PermLayer["Permissions Layer (AccessControlled)"]
direction LR
PPlatform["Platform"]
PWhatsApp["WhatsApp"]
PNis["NIS"]
PSummaries["Summaries"]
PBlogs["Blogs"]
PAdmin["Admin"]
PMonitor["Monitor"]
PYouTube["YouTube"]
PWorkflow["Workflow"]
PKnowledge["Knowledge"]
PAgentMail["AgentMail"]
PChat["Chat"]
PMCPConn["MCPConnection"]
end
end
Routes -- "tools/call . tools/list
resources/list . resources/read
(user.id)" --> Manager
Manager -- "Auth.AuthContext.for_user!/1" --> UserMod
Manager -- "handle_tool_call/3
MCP.Telemetry.span_tool_call" --> MCP
MCP -- "permission-gated dispatch" --> PermLayer
MCP -- "fallback: proxy to
external MCP servers" --> MCPConnReg
%% =========================================================================
%% MCP CONNECTION REGISTRY (External MCP Proxy)
%% =========================================================================
subgraph MCPConnLayer["MCP Connection Registry"]
direction TB
MCPConnReg
MCPConnSup
MCPClient["MCPClient
(per-connection)"]
end
MCPConnReg -- "start_link per server" --> MCPClient
MCPClient -- "Streamable HTTP" --> GoogleWS
%% =========================================================================
%% MCP CLIENT LAYER
%% =========================================================================
subgraph ClientLayer["MCP Client Layer"]
direction TB
MCT
Client["MCPClient
(GenServer, per-user)"]
end
IEx -- "Example.run_demo/0" --> MCT
MCT -- "get_or_start(user_id)" --> Client
Client -- "call_tool/3 . list_tools/1
list_resources/1 . read_resource/2" --> Manager
%% =========================================================================
%% CHAT LAYER
%% =========================================================================
subgraph ChatLayer["Chat Layer (LLM Integration)"]
direction TB
SCT
SC["ServerChat
(GenServer, per-user
30-min idle timeout)"]
subgraph Providers["Pluggable Providers (ServerChat.Provider behaviour)"]
direction LR
ProvAnthropic["ServerChat.Anthropic"]
ProvOpenRouter["ServerChat.OpenRouter"]
ProvPerplexity["ServerChat.Perplexity"]
end
end
Routes -- "POST /chat . /api/chat/*" --> SCT
SCT -- "get_or_start(user_id)" --> SC
SC -- "list_tools . call_tool" --> Manager
SC -- "call_llm/4
(with MCP tools)" --> Providers
ProvAnthropic -- "HTTP POST
/v1/messages" --> AnthropicAPI
ProvOpenRouter -- "HTTP POST
/v1/chat/completions" --> OpenRouterAPI
ProvPerplexity -- "HTTP POST
/v1/responses" --> PerplexityAPI
SC -- "persist history" --> ChatDB
%% =========================================================================
%% USER & AUTH & ACCESS CONTROL
%% =========================================================================
subgraph UserAuth["User, Auth & Access Control"]
direction TB
UserMod["User
create . authenticate
sessions . delete"]
Argon["Argon2
password hashing"]
AccessCtrl["AccessControl
roles . grants . TTL keys
AES-256-CTR encryption
PubSub broadcast"]
GoogleAuth["GoogleAuth
OIDC Sign-In"]
end
GetUser --> UserMod
Routes -- "POST /login
authenticate" --> UserMod
Routes -- "GET /auth/google/*" --> GoogleAuth
GoogleAuth -- "OIDC verify" --> GoogleOIDC
UserMod --> Argon
UserMod -- "SQL queries" --> UsersDB
UserMod -- "grant/revoke" --> AccessCtrl
AccessCtrl -- "SQL queries (encrypted)" --> UsersDB
AccessCtrl -- "broadcast" --> PermPubSub
Manager -- "get_permissions" --> AccessCtrl
%% =========================================================================
%% WORKFLOW ENGINE
%% =========================================================================
subgraph WorkflowSystem["Workflow Engine"]
direction TB
WFExec
WF["Workflow
steps . branches . joins
templates . scheduling"]
WFWeb["WorkflowWeb
SPA (create + list)"]
WFDB["Sqler
:workflow_db"]
end
Routes -- "/workflow . /workflows
/api/workflow/*" --> WFWeb
WFExec -- "poll ready steps
watchdog stuck steps" --> WF
WFExec -- "call_tool" --> Manager
WFExec -- "schedule retries
scheduled start" --> AL
WF --> WFDB
%% =========================================================================
%% KNOWLEDGE BASE
%% =========================================================================
subgraph KnowledgeSystem["Knowledge Base"]
direction TB
Knowledge["Knowledge
vector + FTS search
tags . chunked docs"]
end
Routes -- "/knowledge . /api/knowledge/*" --> Knowledge
Knowledge -- "embeddings" --> VoyagerAPI
Knowledge --> KnowledgeDB
%% =========================================================================
%% WHATSAPP
%% =========================================================================
subgraph WhatsAppSystem["WhatsApp Integration"]
direction TB
WA["WhatsApp
(GenServer, singleton)"]
WAClaude["WhatsAppClaude
(AI auto-responder)"]
end
WA -- "ZeroMQ REQ/REP + SUB
JSON messages" --> WhatsAppBridge
WAClaude -- "incoming messages" --> WA
WAClaude -- "call_tool . list_tools" --> Manager
%% =========================================================================
%% NIS CRM
%% =========================================================================
subgraph NisSystem["NIS -- Personal CRM"]
direction TB
Nis["Nis
contacts . companies
websites . activities"]
NisDB["Sqler
:nis_db (per-user
30-min idle timeout)"]
end
Routes -- "/nis . /api/nis/*" --> Nis
Nis --> NisDB
%% =========================================================================
%% TASK MANAGEMENT
%% =========================================================================
subgraph TaskSystem["Task Management"]
direction TB
TaskMgr["TaskManager
60+ query functions
recurrence engine"]
TaskW["TaskWeb
HTML rendering"]
TaskCap["TaskCapture
NL parsing"]
end
Routes -- "/tasks . /api/tasks/*" --> TaskW
TaskW --> TaskMgr
TaskCap --> TaskMgr
TaskMgr --> TasksDB
%% =========================================================================
%% SUMMARIES
%% =========================================================================
subgraph SummarySystem["Article Summaries"]
direction TB
Summary["Summary
async LLM summarization
vector + FTS search"]
SummDB["Sqler
:summaries_db"]
end
Routes -- "/summaries . /api/summaries/*" --> Summary
Summary -- "LLM summarize" --> AnthropicAPI
Summary -- "embeddings" --> VoyagerAPI
Summary --> SummDB
%% =========================================================================
%% BLOG SYSTEM
%% =========================================================================
subgraph BlogSystem["Blog System"]
direction TB
Blog["Blog
file-based posts
Summernote editor"]
BlogStoreM["BlogStore
chunks . vector + FTS
semantic search"]
BlogsDB["Sqler
:blogs_store_db"]
BFW
end
Routes -- "/blog* . /blogs . /api/blogs/*" --> Blog
Blog -- "read/write" --> BlogFiles["asset/blogs/"]
BFW -- "file change" --> BlogStoreM
BlogStoreM -- "embeddings" --> VoyagerAPI
BlogStoreM --> BlogsDB
%% =========================================================================
%% AGENTMAIL
%% =========================================================================
subgraph AgentMailSystem["AgentMail"]
direction TB
AM["AgentMail
per-user inbox
send . reply . forward"]
end
MCP -- "agentmail_*" --> AM
AM -- "HTTP REST" --> AgentMailAPI
%% =========================================================================
%% LLM GATEWAY
%% =========================================================================
subgraph LLMGatewaySystem["LLM Gateway"]
direction TB
LLMGw["LLMGateway
reverse proxy
audit + security scanning"]
LLMFinch
end
Routes -- "/llm-gateway/*" --> LLMGw
LLMGw -- "proxy" --> AnthropicAPI
LLMGw -- "proxy" --> OpenAIAPI
LLMGw -- "audit log" --> LLMGwDB
%% =========================================================================
%% MONITOR
%% =========================================================================
subgraph MonitorSystem["System Monitor"]
direction TB
Monitor["Monitor
stateless metrics"]
MonSrv
end
Routes -- "/monitor . /api/monitor/*" --> MonSrv
MonSrv -- "periodic polling
anomaly detection" --> Monitor
%% =========================================================================
%% YOUTUBE
%% =========================================================================
YouTube["YouTube
OAuth2 refresh-token
list subscriptions"] -- "HTTP GET
subscriptions.list" --> YouTubeAPI
%% =========================================================================
%% TTS
%% =========================================================================
TTS["Tts
text-to-speech"] -- "HTTP POST
eleven_multilingual_v2" --> ElevenLabsAPI
%% =========================================================================
%% PAGE SCRAPER
%% =========================================================================
subgraph PageScraperSystem["PageScraper (Browser DOM Extraction)"]
direction TB
PS["PageScraper
URL patterns + DB"]
PSS["PageScraperServer
(per user+pattern)"]
PSH["Handler
(e.g. GithubPR)"]
end
Browser -- "WebSocket
page_visit . dom_result" --> WsH["WsHandler"]
WsH -- "match_url" --> PS
WsH -- "get_or_start" --> PSS
PSS -- "on_match . on_extraction" --> PSH
PSS -- "dom_command" --> WsH
PSS --> PSDB
%% =========================================================================
%% A2A PROTOCOL
%% =========================================================================
subgraph A2ALayer["A2A Protocol (Google Agent-to-Agent)"]
direction TB
A2AS["A2AServer
JSON-RPC 2.0"]
A2AC["A2AClient
stateless HTTP"]
end
Routes -- "POST /a2a
GET /.well-known/agent.json" --> A2AS
A2AS -- "call_tool_as" --> Manager
A2AS --> A2ADB
%% =========================================================================
%% DATABASE LAYER
%% =========================================================================
subgraph Database["Database Layer (SQLite via Sqler, 15+ instances)"]
direction LR
UsersDB
CompileLogDB
ChatDB
SchedDB
A2ADB
TasksDB
PSDB
SummDB
BlogsDB
NisDB
KnowledgeDB
ContactFormsDB
LLMGwDB
WFDB
AlarmDB["Sqler
(alarm, inline)"]
AppDB["Sqler
(app, inline)"]
end
%% =========================================================================
%% COMPILATION & LOGGING
%% =========================================================================
subgraph CompileFlow["Auto-Compilation"]
direction TB
AC
CL["CompileLog
log compilations
with git diff"]
end
FS -- "file changes" --> AC
AC -- "Code.compile_file/1" --> AC
AC -- "log compilation" --> CL
CL -- "SQL insert" --> CompileLogDB
%% =========================================================================
%% LOGGING PIPELINE
%% =========================================================================
subgraph LogPipeline["Logging Pipeline"]
direction LR
Logger["Logger"]
LN["LoggerNotifier
(gen_event backend)"]
Notifier["Notifier
(gproc pub/sub)"]
LS
SLW
end
Logger -- "log events" --> LN
LN -- "notify" --> Notifier
Notifier -- "cast" --> LS
LS -- "IO.puts
ANSI colors" --> IEx
SLW -- "write to disk" --> LogFiles["priv/logs/"]
%% =========================================================================
%% ALARM, TIMER & SCHEDULER
%% =========================================================================
subgraph AlarmSystem["Alarm, Timer & Scheduler"]
direction TB
AL
TI["Timer
(Process.send_after)"]
Sched["Scheduler
(callback orchestration)"]
PO
end
AL -- "set_timer" --> TI
TI -- "fire alarm" --> AL
AL --> AlarmDB
Sched -- "set_alarm/3
(stores {m,f,a})" --> AL
Sched -- "SQL persistence" --> SchedDB
PO -- "HTTP POST" --> PushAPI
AL -- "scheduled push" --> PO
%% =========================================================================
%% ZEROMQ BRIDGE
%% =========================================================================
subgraph ZmqLayer["ZeroMQ Bridge"]
direction TB
ZmqReg
ZMQ["ZmqCounter
(GenServer, per-instance
chumak or erlzmq backends)"]
end
ZMQ -- "MuonTrap + ZeroMQ
TCP/IPC . JSON messages" --> PythonProc
%% =========================================================================
%% STANDALONE UTILITIES
%% =========================================================================
subgraph Utilities["Standalone Utilities"]
direction TB
subgraph WeatherScripts["Weather Chat Scripts (demo/test)"]
direction LR
WC["WeatherChat
(Claude + MCP)"]
WCG["WeatherChatGemini"]
WCO["WeatherChatOpenAI"]
end
Voyager["VoyagerEmbeddings
voyage-3 . 1024-dim"]
SysTZ["SystemTimezone
cross-platform TZ"]
TxtChunk["TextChunker
sentence-aware splitting"]
end
WC -- "tool calling" --> AnthropicAPI
WCG -- "function calling" --> GeminiAPI
WCO -- "tool calling" --> OpenAIAPI
WC -- "MCP weather tool" --> ApifyMCP
Voyager -- "HTTP POST" --> VoyagerAPI
%% =========================================================================
%% APP MODULE
%% =========================================================================
APP -- "term storage" --> AppDB
%% =========================================================================
%% DOCS & MANUALS
%% =========================================================================
Routes -- "/docs/* . /manuals/*" --> DocsRouter["DocsRouter"]
DocsRouter -- "static files" --> DocsFiles["asset/docs/
asset/manuals/"]
%% =========================================================================
%% CONTACT FORM
%% =========================================================================
Routes -- "POST /contact" --> ContactForm["ContactForm"]
ContactForm --> ContactFormsDB
%% =========================================================================
%% TELEMETRY
%% =========================================================================
Manager -- ":telemetry events" --> ToolAudit
%% =========================================================================
%% STYLING
%% =========================================================================
classDef genserver fill:#4a9eff,stroke:#2d6cb4,color:#fff
classDef database fill:#50c878,stroke:#2d8b4e,color:#fff
classDef external fill:#ff9f43,stroke:#b36f2f,color:#fff
classDef router fill:#a55eea,stroke:#7b3fb5,color:#fff
classDef module fill:#778ca3,stroke:#4b6078,color:#fff
classDef provider fill:#e056a0,stroke:#a03d74,color:#fff
classDef utility fill:#45aaf2,stroke:#2d7abf,color:#fff
class Manager,Client,MCT,AC,LS,AL,TI,PO,APP,SC,SCT,Sched,ZMQ,WA,WAClaude,MonSrv,ToolAudit,PSS,WFExec,MCPConnReg,BFW,SLW genserver
class UsersDB,CompileLogDB,SchedDB,AlarmDB,AppDB,ChatDB,A2ADB,TasksDB,PSDB,SummDB,BlogsDB,NisDB,KnowledgeDB,ContactFormsDB,LLMGwDB,WFDB database
class Browser,IEx,FS,PushAPI,AnthropicAPI,OpenRouterAPI,PerplexityAPI,GeminiAPI,OpenAIAPI,PythonProc,ApifyMCP,VoyagerAPI,WhatsAppBridge,ElevenLabsAPI,YouTubeAPI,GoogleWS,AgentMailAPI,GoogleOIDC,ClaudeCLI external
class HTTPS,Routes,Auth,CSRF,DocsRouter router
class MCP,UserMod,CL,LN,Notifier,GetUser,Argon,Blog,BlogStoreM,TaskMgr,TaskW,TaskCap,A2AS,A2AC,PS,PSH,Summary,Nis,Monitor,YouTube,TTS,AccessCtrl,GoogleAuth,WF,WFWeb,Knowledge,AM,LLMGw,ContactForm module
class ProvAnthropic,ProvOpenRouter,ProvPerplexity provider
class WC,WCG,WCO,Voyager,SysTZ,TxtChunk utility
class PPlatform,PWhatsApp,PNis,PSummaries,PBlogs,PAdmin,PMonitor,PYouTube,PWorkflow,PKnowledge,PAgentMail,PChat,PMCPConn module
```