# chengpeng-cp/nexus-agent architecture

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

- Interactive diagram: https://gitdiagram.com/chengpeng-cp/nexus-agent
- Repository: https://github.com/chengpeng-cp/nexus-agent

## Overview

NexusAgent is a Go agent platform with a React console. Users sign in, configure models or agents, and send chat requests that return streamed answers, tool activity, and references. The backend also supports document indexing and retrieval, workflow execution with approval pauses, persistent memory, MCP tools, and remote A2A agents. The graph combines sampled call sites with README-documented capabilities; several subsystem links are documented rather than verified from sampled implementation.

Main entry points: [`backend/internal/service`](https://github.com/chengpeng-cp/nexus-agent/tree/main/backend/internal/service) (Service orchestration), [`backend/internal/service/chatsvc.go`](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/service/chatsvc.go) (Chat service), [`backend/internal/rag/engine/engine.go`](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/rag/engine/engine.go) (RAG engine), [`frontend/src/App.tsx`](https://github.com/chengpeng-cp/nexus-agent/blob/main/frontend/src/App.tsx) (React console)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Web console"]
  node_console["React console<br/>[App.tsx]"]
  node_pages["Feature pages"]
  node_api_client["Typed API clients"]
  node_sse["SSE client<br/>[sse.ts]"]
end

subgraph group_http["API and services"]
  node_api_router["HTTP router<br/>[router.go]"]
  node_api_handlers["REST and SSE handlers"]
  node_services["Service orchestration"]
end

subgraph group_agent["Agent runtime"]
  node_chat["Chat service<br/>[chatsvc.go]"]
  node_agent_runtime["ReAct runtime<br/>[runner.go]"]
  node_host["Host and experts<br/>[host.go]"]
  node_tools["Tool execution<br/>[executor_impl.go]"]
  node_llm["LLM gateway<br/>[gateway.go]"]
  node_memory["Long-term memory<br/>[long_term.go]"]
end

subgraph group_knowledge["Knowledge and workflows"]
  node_rag_service["Knowledge service<br/>[kbsvc.go]"]
  node_rag_engine["RAG engine<br/>[engine.go]"]
  node_rag_storage[("Chunk and vector stores<br/>[store.go]")]
  node_worker["ETL worker<br/>[worker.go]"]
  node_workflow["Workflow engine<br/>[engine.go]"]
end

subgraph group_platform["Platform services"]
  node_auth["Authentication<br/>[auth.go]"]
  node_task_stream["Redis Streams"]
  node_mcp["MCP client<br/>[client.go]"]
  node_a2a_server["A2A endpoint<br/>[server.go]"]
  node_observability["Tracing and metrics"]
  node_repositories[("Data repositories")]
end

node_user(("Platform user"))
node_provider["Model provider"]
node_external_tools(("MCP tool ecosystem"))
node_remote_agent(("Remote agent"))

node_user -->|"uses"| node_console
node_console -->|"routes to"| node_pages
node_console -->|"requests"| node_api_client
node_pages -.->|"streams chat"| node_sse
node_api_client -->|"calls API"| node_api_router
node_api_router -->|"routes requests"| node_api_handlers
node_api_handlers -->|"delegates"| node_services
node_services -->|"accesses data"| node_repositories
node_services -->|"authenticates"| node_auth
node_services -.->|"orchestrates chat"| node_chat
node_chat -.->|"runs agent"| node_agent_runtime
node_agent_runtime -->|"requests completion"| node_llm
node_agent_runtime -->|"invokes tools"| node_tools
node_chat -->|"uses collaboration"| node_host
node_llm -->|"calls model"| node_provider
node_services -.->|"orchestrates knowledge"| node_rag_service
node_rag_service -->|"indexes and retrieves"| node_rag_engine
node_rag_engine -->|"reads and writes vectors"| node_rag_storage
node_worker -->|"indexes documents"| node_rag_engine
node_worker -->|"consumes tasks"| node_task_stream
node_rag_service -.->|"publishes ETL task"| node_task_stream
node_services -->|"runs workflows"| node_workflow
node_workflow -->|"invokes tool nodes"| node_tools
node_workflow -->|"retrieves KB context"| node_rag_engine
node_chat -->|"persists memories"| node_memory
node_services -->|"manages integration"| node_mcp
node_mcp -->|"connects"| node_external_tools
node_remote_agent -->|"sends A2A request"| node_a2a_server
node_a2a_server -->|"delegates locally"| node_services
node_api_router -->|"exposes monitoring"| node_observability

click node_console "https://github.com/chengpeng-cp/nexus-agent/blob/main/frontend/src/App.tsx"
click node_pages "https://github.com/chengpeng-cp/nexus-agent/tree/main/frontend/src/pages"
click node_api_client "https://github.com/chengpeng-cp/nexus-agent/tree/main/frontend/src/api"
click node_sse "https://github.com/chengpeng-cp/nexus-agent/blob/main/frontend/src/lib/sse.ts"
click node_api_router "https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/api/router.go"
click node_api_handlers "https://github.com/chengpeng-cp/nexus-agent/tree/main/backend/internal/api"
click node_services "https://github.com/chengpeng-cp/nexus-agent/tree/main/backend/internal/service"
click node_auth "https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/service/auth.go"
click node_chat "https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/service/chatsvc.go"
click node_agent_runtime "https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/agent/runtime/runner.go"
click node_host "https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/agent/host/host.go"
click node_tools "https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/tool/executor_impl.go"
click node_llm "https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/llm/gateway.go"
click node_rag_service "https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/service/kbsvc.go"
click node_rag_engine "https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/rag/engine/engine.go"
click node_rag_storage "https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/vector/store.go"
click node_worker "https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/worker/worker.go"
click node_workflow "https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/workflow/engine.go"
click node_memory "https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/memory/long_term/long_term.go"
click node_mcp "https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/mcp/client.go"
click node_a2a_server "https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/a2a/server.go"
click node_observability "https://github.com/chengpeng-cp/nexus-agent/tree/main/backend/internal/observability"
click node_repositories "https://github.com/chengpeng-cp/nexus-agent/tree/main/backend/internal/repo"

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_console,node_pages,node_api_client,node_sse,node_user toneBlue
class node_api_router,node_api_handlers,node_services toneAmber
class node_chat,node_agent_runtime,node_host,node_tools,node_llm,node_memory toneMint
class node_rag_service,node_rag_engine,node_rag_storage,node_worker,node_workflow toneRose
class node_auth,node_task_stream,node_mcp,node_a2a_server,node_observability,node_repositories,node_provider,node_external_tools,node_remote_agent toneIndigo
```

## Components

### Web console

- [React console](https://github.com/chengpeng-cp/nexus-agent/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Feature pages](https://github.com/chengpeng-cp/nexus-agent/tree/main/frontend/src/pages): `frontend/src/pages`
- [Typed API clients](https://github.com/chengpeng-cp/nexus-agent/tree/main/frontend/src/api): `frontend/src/api`
- [SSE client](https://github.com/chengpeng-cp/nexus-agent/blob/main/frontend/src/lib/sse.ts): `frontend/src/lib/sse.ts`

### API and services

- [HTTP router](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/api/router.go): `backend/internal/api/router.go`
- [REST and SSE handlers](https://github.com/chengpeng-cp/nexus-agent/tree/main/backend/internal/api): `backend/internal/api`
- [Service orchestration](https://github.com/chengpeng-cp/nexus-agent/tree/main/backend/internal/service): `backend/internal/service`

### Agent runtime

- [Chat service](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/service/chatsvc.go): `backend/internal/service/chatsvc.go`
- [ReAct runtime](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/agent/runtime/runner.go): `backend/internal/agent/runtime/runner.go`
- [Host and experts](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/agent/host/host.go): `backend/internal/agent/host/host.go`
- [Tool execution](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/tool/executor_impl.go): `backend/internal/tool/executor_impl.go`
- [LLM gateway](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/llm/gateway.go): `backend/internal/llm/gateway.go`
- [Long-term memory](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/memory/long_term/long_term.go): `backend/internal/memory/long_term/long_term.go`

### Knowledge and workflows

- [Knowledge service](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/service/kbsvc.go): `backend/internal/service/kbsvc.go`
- [RAG engine](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/rag/engine/engine.go): `backend/internal/rag/engine/engine.go`
- [Chunk and vector stores](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/vector/store.go): `backend/internal/vector/store.go`
- [ETL worker](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/worker/worker.go): `backend/internal/worker/worker.go`
- [Workflow engine](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/workflow/engine.go): `backend/internal/workflow/engine.go`

### Platform services

- [Authentication](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/service/auth.go): `backend/internal/service/auth.go`
- **Redis Streams**
- [MCP client](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/mcp/client.go): `backend/internal/mcp/client.go`
- [A2A endpoint](https://github.com/chengpeng-cp/nexus-agent/blob/main/backend/internal/a2a/server.go): `backend/internal/a2a/server.go`
- [Tracing and metrics](https://github.com/chengpeng-cp/nexus-agent/tree/main/backend/internal/observability): `backend/internal/observability`
- [Data repositories](https://github.com/chengpeng-cp/nexus-agent/tree/main/backend/internal/repo): `backend/internal/repo`

### Other components

- **Platform user**
- **Model provider**
- **MCP tool ecosystem**
- **Remote agent**

## Connections

- Platform user → React console: uses (evidence: `README.md`)
- React console → Feature pages: routes to (evidence: `README.md`)
- React console → Typed API clients: requests (evidence: `README.md`)
- Feature pages → SSE client: streams chat
- Typed API clients → HTTP router: calls API (evidence: `README.md`)
- HTTP router → REST and SSE handlers: routes requests (evidence: `README.md`)
- REST and SSE handlers → Service orchestration: delegates (evidence: `backend/internal/api/handler_auth.go`)
- Service orchestration → Data repositories: accesses data (evidence: `README.md`)
- Service orchestration → Authentication: authenticates
- Service orchestration → Chat service: orchestrates chat
- Chat service → ReAct runtime: runs agent
- ReAct runtime → LLM gateway: requests completion (evidence: `README.md`)
- ReAct runtime → Tool execution: invokes tools (evidence: `README.md`)
- Chat service → Host and experts: uses collaboration (evidence: `README.md`)
- LLM gateway → Model provider: calls model (evidence: `README.md`)
- Service orchestration → Knowledge service: orchestrates knowledge
- Knowledge service → RAG engine: indexes and retrieves (evidence: `README.md`)
- RAG engine → Chunk and vector stores: reads and writes vectors (evidence: `backend/internal/rag/engine/engine.go`)
- ETL worker → RAG engine: indexes documents (evidence: `backend/internal/worker/worker.go`)
- ETL worker → Redis Streams: consumes tasks (evidence: `backend/internal/worker/worker.go`)
- Knowledge service → Redis Streams: publishes ETL task
- Service orchestration → Workflow engine: runs workflows (evidence: `README.md`)
- Workflow engine → Tool execution: invokes tool nodes (evidence: `backend/internal/workflow/engine.go`)
- Workflow engine → RAG engine: retrieves KB context (evidence: `backend/internal/workflow/engine.go`)
- Chat service → Long-term memory: persists memories (evidence: `README.md`)
- Service orchestration → MCP client: manages integration (evidence: `README.md`)
- MCP client → MCP tool ecosystem: connects (evidence: `README.md`)
- Remote agent → A2A endpoint: sends A2A request (evidence: `README.md`)
- A2A endpoint → Service orchestration: delegates locally
- HTTP router → Tracing and metrics: exposes monitoring
