# nxtsoft/cgraph architecture

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

- Interactive diagram: https://gitdiagram.com/nxtsoft/cgraph
- Repository: https://github.com/nxtsoft/cgraph

## Overview

CGraph scans source trees into deterministic code graphs, then exposes navigation and change-impact answers through a one-shot CLI or a resident per-project daemon. The main build path detects files, extracts structural fragments, resolves relationships, analyzes the graph, and exports graph and report formats. Clients and the MCP server route queries to the daemon; documented capabilities also include live updates, workspace federation, and optional semantic enrichment. The core pipeline and client routing are supported by sampled source; daemon operations and several feature branches are represented from the README and tree, since their implementations were not sampled.

Main entry points: [`src/engine/pipeline.cpp`](https://github.com/nxtsoft/cgraph/blob/main/src/engine/pipeline.cpp) (Build pipeline), [`src/cli/main.cpp`](https://github.com/nxtsoft/cgraph/blob/main/src/cli/main.cpp) (One-shot CLI), [`src/client/client_runtime.cpp`](https://github.com/nxtsoft/cgraph/blob/main/src/client/client_runtime.cpp) (Thin client), [`src/engine/daemon_server.cpp`](https://github.com/nxtsoft/cgraph/blob/main/src/engine/daemon_server.cpp) (Daemon server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Graph construction"]
  node_pipeline["Build pipeline<br/>[pipeline.cpp]"]
  node_detect["File detection<br/>[detect.cpp]"]
  node_extract["Language extraction"]
  node_graph["Graph assembly<br/>[graph_builder.cpp]"]
  node_analysis["Graph analysis<br/>[analysis.cpp]"]
  node_exports["Graph exports<br/>[pipeline.cpp]"]
end

subgraph group_serve["Daemon service"]
  node_daemon["Resident daemon<br/>[main.cpp]"]
  node_daemon_server["Daemon server<br/>[daemon_server.cpp]"]
  node_daemon_ops["Query operations<br/>[daemon_ops.cpp]"]
  node_watcher["Live file updates<br/>[file_watcher.cpp]"]
  node_update["Incremental graph update"]
  node_persistence[("Graph persistence")]
end

subgraph group_access["Client access"]
  node_cli["One-shot CLI<br/>[main.cpp]"]
  node_client["Thin client<br/>[client_runtime.cpp]"]
  node_mcp["MCP server<br/>[mcp_server.cpp]"]
end

subgraph group_enrichment["Enrichment and federation"]
  node_semantic["Semantic enrichment"]
  node_ingest["Fragment ingestion"]
  node_workspace["Workspace federation<br/>[workspace.cpp]"]
end

node_developer(("Engineer or agent"))

node_developer -->|"runs build"| node_cli
node_cli -->|"runs scan"| node_pipeline
node_pipeline -->|"detects files"| node_detect
node_pipeline -->|"extracts files"| node_extract
node_pipeline -->|"merges fragments"| node_graph
node_pipeline -->|"resolves relations"| node_graph
node_pipeline -->|"analyzes graph"| node_analysis
node_cli -->|"writes exports"| node_exports
node_developer -->|"queries graph"| node_client
node_client -->|"connects or spawns"| node_daemon
node_daemon -->|"starts service"| node_daemon_server
node_daemon_server -->|"dispatches requests"| node_daemon_ops
node_daemon_server -->|"watches files"| node_watcher
node_watcher -->|"triggers updates"| node_update
node_update -->|"persists graph"| node_persistence
node_daemon_ops -->|"loads graph"| node_persistence
node_developer -->|"sends MCP requests"| node_mcp
node_mcp -->|"forwards operations"| node_client
node_cli -->|"plans enrichment"| node_semantic
node_cli -->|"ingests fragments"| node_ingest
node_semantic -.->|"produces fragments"| node_ingest
node_client -->|"federates requests"| node_workspace

click node_cli "https://github.com/nxtsoft/cgraph/blob/main/src/cli/main.cpp"
click node_pipeline "https://github.com/nxtsoft/cgraph/blob/main/src/engine/pipeline.cpp"
click node_detect "https://github.com/nxtsoft/cgraph/blob/main/src/engine/detect.cpp"
click node_extract "https://github.com/nxtsoft/cgraph/blob/main/src/engine/file_extraction.cpp"
click node_graph "https://github.com/nxtsoft/cgraph/blob/main/src/engine/graph_builder.cpp"
click node_analysis "https://github.com/nxtsoft/cgraph/blob/main/src/engine/analysis.cpp"
click node_exports "https://github.com/nxtsoft/cgraph/blob/main/src/engine/pipeline.cpp"
click node_daemon "https://github.com/nxtsoft/cgraph/blob/main/src/daemon/main.cpp"
click node_daemon_server "https://github.com/nxtsoft/cgraph/blob/main/src/engine/daemon_server.cpp"
click node_daemon_ops "https://github.com/nxtsoft/cgraph/blob/main/src/engine/daemon_ops.cpp"
click node_watcher "https://github.com/nxtsoft/cgraph/blob/main/src/engine/file_watcher.cpp"
click node_update "https://github.com/nxtsoft/cgraph/blob/main/src/engine/incremental_update.cpp"
click node_persistence "https://github.com/nxtsoft/cgraph/blob/main/src/engine/index_persistence.cpp"
click node_client "https://github.com/nxtsoft/cgraph/blob/main/src/client/client_runtime.cpp"
click node_mcp "https://github.com/nxtsoft/cgraph/blob/main/src/mcp/mcp_server.cpp"
click node_semantic "https://github.com/nxtsoft/cgraph/blob/main/src/engine/semantic_orchestration.cpp"
click node_ingest "https://github.com/nxtsoft/cgraph/blob/main/src/engine/semantic_ingest.cpp"
click node_workspace "https://github.com/nxtsoft/cgraph/blob/main/src/engine/workspace.cpp"

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_pipeline,node_detect,node_extract,node_graph,node_analysis,node_exports toneBlue
class node_daemon,node_daemon_server,node_daemon_ops,node_watcher,node_update,node_persistence toneAmber
class node_cli,node_client,node_mcp toneMint
class node_semantic,node_ingest,node_workspace toneRose
class node_developer toneIndigo
```

## Components

### Graph construction

- [Build pipeline](https://github.com/nxtsoft/cgraph/blob/main/src/engine/pipeline.cpp): `src/engine/pipeline.cpp`
- [File detection](https://github.com/nxtsoft/cgraph/blob/main/src/engine/detect.cpp): `src/engine/detect.cpp`
- [Language extraction](https://github.com/nxtsoft/cgraph/blob/main/src/engine/file_extraction.cpp): `src/engine/file_extraction.cpp`
- [Graph assembly](https://github.com/nxtsoft/cgraph/blob/main/src/engine/graph_builder.cpp): `src/engine/graph_builder.cpp`
- [Graph analysis](https://github.com/nxtsoft/cgraph/blob/main/src/engine/analysis.cpp): `src/engine/analysis.cpp`
- [Graph exports](https://github.com/nxtsoft/cgraph/blob/main/src/engine/pipeline.cpp): `src/engine/pipeline.cpp`

### Daemon service

- [Resident daemon](https://github.com/nxtsoft/cgraph/blob/main/src/daemon/main.cpp): `src/daemon/main.cpp`
- [Daemon server](https://github.com/nxtsoft/cgraph/blob/main/src/engine/daemon_server.cpp): `src/engine/daemon_server.cpp`
- [Query operations](https://github.com/nxtsoft/cgraph/blob/main/src/engine/daemon_ops.cpp): `src/engine/daemon_ops.cpp`
- [Live file updates](https://github.com/nxtsoft/cgraph/blob/main/src/engine/file_watcher.cpp): `src/engine/file_watcher.cpp`
- [Incremental graph update](https://github.com/nxtsoft/cgraph/blob/main/src/engine/incremental_update.cpp): `src/engine/incremental_update.cpp`
- [Graph persistence](https://github.com/nxtsoft/cgraph/blob/main/src/engine/index_persistence.cpp): `src/engine/index_persistence.cpp`

### Client access

- [One-shot CLI](https://github.com/nxtsoft/cgraph/blob/main/src/cli/main.cpp): `src/cli/main.cpp`
- [Thin client](https://github.com/nxtsoft/cgraph/blob/main/src/client/client_runtime.cpp): `src/client/client_runtime.cpp`
- [MCP server](https://github.com/nxtsoft/cgraph/blob/main/src/mcp/mcp_server.cpp): `src/mcp/mcp_server.cpp`

### Enrichment and federation

- [Semantic enrichment](https://github.com/nxtsoft/cgraph/blob/main/src/engine/semantic_orchestration.cpp): `src/engine/semantic_orchestration.cpp`
- [Fragment ingestion](https://github.com/nxtsoft/cgraph/blob/main/src/engine/semantic_ingest.cpp): `src/engine/semantic_ingest.cpp`
- [Workspace federation](https://github.com/nxtsoft/cgraph/blob/main/src/engine/workspace.cpp): `src/engine/workspace.cpp`

### Other components

- **Engineer or agent**

## Connections

- Engineer or agent → One-shot CLI: runs build
- One-shot CLI → Build pipeline: runs scan
- Build pipeline → File detection: detects files
- Build pipeline → Language extraction: extracts files
- Build pipeline → Graph assembly: merges fragments
- Build pipeline → Graph assembly: resolves relations
- Build pipeline → Graph analysis: analyzes graph
- One-shot CLI → Graph exports: writes exports
- Engineer or agent → Thin client: queries graph
- Thin client → Resident daemon: connects or spawns
- Resident daemon → Daemon server: starts service
- Daemon server → Query operations: dispatches requests
- Daemon server → Live file updates: watches files
- Live file updates → Incremental graph update: triggers updates
- Incremental graph update → Graph persistence: persists graph
- Query operations → Graph persistence: loads graph
- Engineer or agent → MCP server: sends MCP requests
- MCP server → Thin client: forwards operations
- One-shot CLI → Semantic enrichment: plans enrichment
- One-shot CLI → Fragment ingestion: ingests fragments
- Semantic enrichment → Fragment ingestion: produces fragments
- Thin client → Workspace federation: federates requests
