# google-developers-group-iit-mandi/brain architecture

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

- Interactive diagram: https://gitdiagram.com/google-developers-group-iit-mandi/brain
- Repository: https://github.com/google-developers-group-iit-mandi/brain

## Overview

Brain is a local-first codebase intelligence daemon. The main workflow is project initialization or scanning, followed by source parsing and graph updates; change events also feed temporal and memory features. Users inspect results through CLI queries, the dashboard, or local MCP tools, and can optionally use Groq for chat and AI summaries. The graph shows relationships confirmed by the excerpts, SOURCE INDEX references, or README; unsampled subsystem links are omitted rather than inferred.

Main entry points: [`src/ingestion/pipeline.ts`](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/ingestion/pipeline.ts) (Change pipeline), [`src/mcp/server.ts`](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/mcp/server.ts) (MCP tools), [`src/query/context-builder.ts`](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/query/context-builder.ts) (Code context), [`src/cli/index.ts`](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/cli/index.ts) (Brain CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_cli["Brain CLI<br/>[index.ts]"]
  node_scan["Repository scan<br/>[scan.ts]"]
  node_config["Project config<br/>[loader.ts]"]
end

subgraph group_indexing["Indexing and graph"]
  node_pipeline["Change pipeline<br/>[pipeline.ts]"]
  node_parser["Symbol extraction<br/>[tree-sitter.ts]"]
  node_diff["Diff parsing<br/>[diff-parser.ts]"]
  node_graphwriter["Graph updates<br/>[writer.ts]"]
  node_graphdb[("Local graph store<br/>[client.ts]")]
  node_graphinsights["Graph insights<br/>[insights.ts]"]
end

subgraph group_memory["Memory and temporal analysis"]
  node_memorydb[("Memory database<br/>[db.ts]")]
  node_tier1["Event memory<br/>[tier1.ts]"]
  node_decay["Memory decay<br/>[decay.ts]"]
  node_hotzones["Hot zones<br/>[hotzone.ts]"]
  node_diffimpact["Change impact<br/>[diff-impact.ts]"]
end

subgraph group_access["User access"]
  node_dashboard["Dashboard and API<br/>[dashboard.ts]"]
  node_ingestpage["Prompt ingestion<br/>[ingest.ts]"]
  node_mcp["MCP tools<br/>[server.ts]"]
  node_context["Code context<br/>[context-builder.ts]"]
end

subgraph group_automation["Automation and AI"]
  node_agentsmd["AGENTS generator<br/>[generator.ts]"]
  node_groq["Groq query engine<br/>[engine.ts]"]
  node_reviewer["AI code review<br/>[code-reviewer.ts]"]
  node_prcommenter["PR comments<br/>[pr-commenter.ts]"]
end

node_developer(("Project user"))

node_developer -->|"runs commands"| node_cli
node_cli -->|"dispatches scan"| node_scan
node_scan -.->|"indexes changes"| node_pipeline
node_pipeline -->|"loads config"| node_config
node_pipeline -->|"parses changes"| node_diff
node_pipeline -->|"extracts symbols"| node_parser
node_pipeline -->|"applies deltas"| node_graphwriter
node_pipeline -->|"writes events"| node_tier1
node_pipeline -->|"recomputes zones"| node_hotzones
node_pipeline -->|"generates guidance"| node_agentsmd
node_pipeline -->|"requests review"| node_reviewer
node_pipeline -->|"requests comments"| node_prcommenter
node_agentsmd -->|"queries graph"| node_graphdb
node_cli -.->|"starts daemon"| node_dashboard
node_developer -->|"selects files"| node_ingestpage
node_developer -->|"uses tools"| node_mcp
node_mcp -->|"builds context"| node_context
node_mcp -->|"reads zones"| node_hotzones
node_mcp -->|"computes ripple"| node_diffimpact
node_context -->|"reads memory"| node_memorydb
node_context -->|"loads overview"| node_graphinsights
node_mcp -->|"streams answers"| node_groq
node_reviewer -->|"builds review context"| node_context
node_reviewer -->|"requests review"| node_groq
node_developer -.->|"asks optional chat"| node_groq

click node_cli "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/cli/index.ts"
click node_scan "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/cli/scan.ts"
click node_config "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/config/loader.ts"
click node_pipeline "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/ingestion/pipeline.ts"
click node_parser "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/ingestion/tree-sitter.ts"
click node_diff "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/ingestion/diff-parser.ts"
click node_graphwriter "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/graph/writer.ts"
click node_graphdb "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/graph/client.ts"
click node_graphinsights "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/graph/insights.ts"
click node_memorydb "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/memory/db.ts"
click node_tier1 "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/memory/tier1.ts"
click node_decay "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/memory/decay.ts"
click node_hotzones "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/temporal/hotzone.ts"
click node_diffimpact "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/query/diff-impact.ts"
click node_dashboard "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/ingestion/routes/dashboard.ts"
click node_ingestpage "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/ingestion/routes/ingest.ts"
click node_mcp "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/mcp/server.ts"
click node_context "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/query/context-builder.ts"
click node_agentsmd "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/agents/generator.ts"
click node_groq "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/query/engine.ts"
click node_reviewer "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/automation/code-reviewer.ts"
click node_prcommenter "https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/automation/pr-commenter.ts"

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_cli,node_scan,node_config,node_developer toneBlue
class node_pipeline,node_parser,node_diff,node_graphwriter,node_graphdb,node_graphinsights toneAmber
class node_memorydb,node_tier1,node_decay,node_hotzones,node_diffimpact toneMint
class node_dashboard,node_ingestpage,node_mcp,node_context toneRose
class node_agentsmd,node_groq,node_reviewer,node_prcommenter toneIndigo
```

## Components

### Entry points

- [Brain CLI](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/cli/index.ts): `src/cli/index.ts`
- [Repository scan](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/cli/scan.ts): `src/cli/scan.ts`
- [Project config](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/config/loader.ts): `src/config/loader.ts`

### Indexing and graph

- [Change pipeline](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/ingestion/pipeline.ts): `src/ingestion/pipeline.ts`
- [Symbol extraction](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/ingestion/tree-sitter.ts): `src/ingestion/tree-sitter.ts`
- [Diff parsing](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/ingestion/diff-parser.ts): `src/ingestion/diff-parser.ts`
- [Graph updates](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/graph/writer.ts): `src/graph/writer.ts`
- [Local graph store](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/graph/client.ts): `src/graph/client.ts`
- [Graph insights](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/graph/insights.ts): `src/graph/insights.ts`

### Memory and temporal analysis

- [Memory database](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/memory/db.ts): `src/memory/db.ts`
- [Event memory](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/memory/tier1.ts): `src/memory/tier1.ts`
- [Memory decay](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/memory/decay.ts): `src/memory/decay.ts`
- [Hot zones](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/temporal/hotzone.ts): `src/temporal/hotzone.ts`
- [Change impact](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/query/diff-impact.ts): `src/query/diff-impact.ts`

### User access

- [Dashboard and API](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/ingestion/routes/dashboard.ts): `src/ingestion/routes/dashboard.ts`
- [Prompt ingestion](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/ingestion/routes/ingest.ts): `src/ingestion/routes/ingest.ts`
- [MCP tools](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/mcp/server.ts): `src/mcp/server.ts`
- [Code context](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/query/context-builder.ts): `src/query/context-builder.ts`

### Automation and AI

- [AGENTS generator](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/agents/generator.ts): `src/agents/generator.ts`
- [Groq query engine](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/query/engine.ts): `src/query/engine.ts`
- [AI code review](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/automation/code-reviewer.ts): `src/automation/code-reviewer.ts`
- [PR comments](https://github.com/google-developers-group-iit-mandi/brain/blob/main/src/automation/pr-commenter.ts): `src/automation/pr-commenter.ts`

### Other components

- **Project user**

## Connections

- Project user → Brain CLI: runs commands
- Brain CLI → Repository scan: dispatches scan (evidence: `src/cli/index.ts`)
- Repository scan → Change pipeline: indexes changes
- Change pipeline → Project config: loads config (evidence: `src/ingestion/pipeline.ts`)
- Change pipeline → Diff parsing: parses changes (evidence: `src/ingestion/pipeline.ts`)
- Change pipeline → Symbol extraction: extracts symbols (evidence: `src/ingestion/pipeline.ts`)
- Change pipeline → Graph updates: applies deltas (evidence: `src/ingestion/pipeline.ts`)
- Change pipeline → Event memory: writes events (evidence: `src/ingestion/pipeline.ts`)
- Change pipeline → Hot zones: recomputes zones (evidence: `src/ingestion/pipeline.ts`)
- Change pipeline → AGENTS generator: generates guidance (evidence: `src/ingestion/pipeline.ts`)
- Change pipeline → AI code review: requests review (evidence: `src/ingestion/pipeline.ts`)
- Change pipeline → PR comments: requests comments (evidence: `src/ingestion/pipeline.ts`)
- AGENTS generator → Local graph store: queries graph (evidence: `src/agents/generator.ts`)
- Brain CLI → Dashboard and API: starts daemon
- Project user → Prompt ingestion: selects files (evidence: `src/ingestion/routes/ingest.ts`)
- Project user → MCP tools: uses tools
- MCP tools → Code context: builds context (evidence: `src/mcp/server.ts`)
- MCP tools → Hot zones: reads zones (evidence: `src/mcp/server.ts`)
- MCP tools → Change impact: computes ripple (evidence: `src/mcp/server.ts`)
- Code context → Memory database: reads memory (evidence: `src/query/context-builder.ts`)
- Code context → Graph insights: loads overview (evidence: `src/query/context-builder.ts`)
- MCP tools → Groq query engine: streams answers (evidence: `src/mcp/server.ts`)
- AI code review → Code context: builds review context (evidence: `src/automation/code-reviewer.ts`)
- AI code review → Groq query engine: requests review (evidence: `src/automation/code-reviewer.ts`)
- Project user → Groq query engine: asks optional chat
