# caals666/rag-cyber-defense architecture

> Architecture diagram of the GitHub repository caals666/rag-cyber-defense, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/caals666/rag-cyber-defense
- Repository: https://github.com/caals666/rag-cyber-defense

## Overview

Cyber Defense RAG answers cybersecurity questions from a Neo4j graph of CVE, CWE, CAPEC, and ATT&CK records. The main flow accepts a question, routes it through ID lookup or semantic/keyword retrieval, asks Groq to answer from retrieved facts, verifies IDs and scores, then streams the response to the web UI. The product also includes attack-path visualization, saved answer history, research evaluation, and fix-first analytics. Some auxiliary pages and backend subsystems are represented from README descriptions; their implementation details were not sampled.

Main entry points: [`backend/rag/pipeline.py`](https://github.com/caals666/rag-cyber-defense/blob/main/backend/rag/pipeline.py) (Answer pipeline), [`frontend/app/page.jsx`](https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/page.jsx) (Ask page), [`backend/api/routes.py`](https://github.com/caals666/rag-cyber-defense/blob/main/backend/api/routes.py) (HTTP API), [`backend/retrieval/hybrid.py`](https://github.com/caals666/rag-cyber-defense/blob/main/backend/retrieval/hybrid.py) (Semantic retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_home["Ask page<br/>[page.jsx]"]
  node_answer_view["Answer view<br/>[Answer.jsx]"]
  node_attack_map["Attack path map<br/>[AttackGraph.jsx]"]
  node_history["Saved history<br/>[history.js]"]
  node_history_page["History page<br/>[page.jsx]"]
  node_web_api["Web API client<br/>[api.js]"]
end

subgraph group_answer["Grounded answers"]
  node_api["HTTP API<br/>[routes.py]"]
  node_pipeline["Answer pipeline<br/>[pipeline.py]"]
  node_prompts["Answer prompts<br/>[prompts.py]"]
  node_grounding["Answer verification<br/>[grounding.py]"]
end

subgraph group_knowledge["Knowledge retrieval"]
  node_lookup["ID lookup<br/>[lookup.py]"]
  node_hybrid["Semantic retrieval<br/>[hybrid.py]"]
  node_embeddings["Text embeddings<br/>[embeddings.py]"]
  node_queries["Cypher queries<br/>[queries.py]"]
  node_connection["Graph connection<br/>[connection.py]"]
end

subgraph group_insights["Product insights"]
  node_analytics["Fix-first analytics<br/>[build.py]"]
  node_eval["Answer evaluation"]
  node_insights_page["Insights page<br/>[page.jsx]"]
  node_research_page["Research page<br/>[page.jsx]"]
end

node_visitor(("Question asker"))
node_groq{{"Groq LLM"}}
node_neo4j[("Neo4j graph")]

node_visitor -->|"asks"| node_home
node_home -->|"requests stream"| node_web_api
node_home -->|"loads and saves"| node_history
node_web_api -->|"calls stream API"| node_api
node_api -->|"routes questions"| node_pipeline
node_pipeline -->|"looks up IDs"| node_lookup
node_pipeline -->|"searches by meaning"| node_hybrid
node_pipeline -->|"runs keyword query"| node_queries
node_hybrid -->|"embeds question"| node_embeddings
node_hybrid -->|"expands graph hits"| node_lookup
node_lookup -->|"selects query"| node_queries
node_pipeline -->|"builds prompts"| node_prompts
node_pipeline -->|"requests generation"| node_groq
node_pipeline -->|"verifies answer"| node_grounding
node_queries -->|"runs through"| node_connection
node_connection -->|"reads graph"| node_neo4j
node_api -->|"checks graph health"| node_connection
node_pipeline -->|"streams answer data"| node_answer_view
node_answer_view -->|"renders attack paths"| node_attack_map
node_insights_page -->|"presents rankings"| node_analytics
node_research_page -->|"presents results"| node_eval

click node_home "https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/page.jsx"
click node_answer_view "https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/Answer.jsx"
click node_attack_map "https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/AttackGraph.jsx"
click node_history "https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/history.js"
click node_history_page "https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/history/page.jsx"
click node_web_api "https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/api.js"
click node_api "https://github.com/caals666/rag-cyber-defense/blob/main/backend/api/routes.py"
click node_pipeline "https://github.com/caals666/rag-cyber-defense/blob/main/backend/rag/pipeline.py"
click node_prompts "https://github.com/caals666/rag-cyber-defense/blob/main/backend/rag/prompts.py"
click node_grounding "https://github.com/caals666/rag-cyber-defense/blob/main/backend/rag/grounding.py"
click node_lookup "https://github.com/caals666/rag-cyber-defense/blob/main/backend/retrieval/lookup.py"
click node_hybrid "https://github.com/caals666/rag-cyber-defense/blob/main/backend/retrieval/hybrid.py"
click node_embeddings "https://github.com/caals666/rag-cyber-defense/blob/main/backend/rag/embeddings.py"
click node_queries "https://github.com/caals666/rag-cyber-defense/blob/main/backend/graph/queries.py"
click node_connection "https://github.com/caals666/rag-cyber-defense/blob/main/backend/graph/connection.py"
click node_analytics "https://github.com/caals666/rag-cyber-defense/blob/main/backend/analytics/build.py"
click node_eval "https://github.com/caals666/rag-cyber-defense/tree/main/backend/eval"
click node_insights_page "https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/insights/page.jsx"
click node_research_page "https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/research/page.jsx"

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_home,node_answer_view,node_attack_map,node_history,node_history_page,node_web_api toneBlue
class node_api,node_pipeline,node_prompts,node_grounding,node_neo4j toneAmber
class node_lookup,node_hybrid,node_embeddings,node_queries,node_connection toneMint
class node_analytics,node_eval,node_insights_page,node_research_page toneRose
class node_visitor,node_groq toneIndigo
```

## Components

### Web experience

- [Ask page](https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/page.jsx): `frontend/app/page.jsx`
- [Answer view](https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/Answer.jsx): `frontend/app/Answer.jsx`
- [Attack path map](https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/AttackGraph.jsx): `frontend/app/AttackGraph.jsx`
- [Saved history](https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/history.js): `frontend/app/history.js`
- [History page](https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/history/page.jsx): `frontend/app/history/page.jsx`
- [Web API client](https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/api.js): `frontend/app/api.js`

### Grounded answers

- [HTTP API](https://github.com/caals666/rag-cyber-defense/blob/main/backend/api/routes.py): `backend/api/routes.py`
- [Answer pipeline](https://github.com/caals666/rag-cyber-defense/blob/main/backend/rag/pipeline.py): `backend/rag/pipeline.py`
- [Answer prompts](https://github.com/caals666/rag-cyber-defense/blob/main/backend/rag/prompts.py): `backend/rag/prompts.py`
- [Answer verification](https://github.com/caals666/rag-cyber-defense/blob/main/backend/rag/grounding.py): `backend/rag/grounding.py`

### Knowledge retrieval

- [ID lookup](https://github.com/caals666/rag-cyber-defense/blob/main/backend/retrieval/lookup.py): `backend/retrieval/lookup.py`
- [Semantic retrieval](https://github.com/caals666/rag-cyber-defense/blob/main/backend/retrieval/hybrid.py): `backend/retrieval/hybrid.py`
- [Text embeddings](https://github.com/caals666/rag-cyber-defense/blob/main/backend/rag/embeddings.py): `backend/rag/embeddings.py`
- [Cypher queries](https://github.com/caals666/rag-cyber-defense/blob/main/backend/graph/queries.py): `backend/graph/queries.py`
- [Graph connection](https://github.com/caals666/rag-cyber-defense/blob/main/backend/graph/connection.py): `backend/graph/connection.py`

### Product insights

- [Fix-first analytics](https://github.com/caals666/rag-cyber-defense/blob/main/backend/analytics/build.py): `backend/analytics/build.py`
- [Answer evaluation](https://github.com/caals666/rag-cyber-defense/tree/main/backend/eval): `backend/eval`
- [Insights page](https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/insights/page.jsx): `frontend/app/insights/page.jsx`
- [Research page](https://github.com/caals666/rag-cyber-defense/blob/main/frontend/app/research/page.jsx): `frontend/app/research/page.jsx`

### Other components

- **Question asker**
- **Groq LLM**
- **Neo4j graph**

## Connections

- Question asker → Ask page: asks (evidence: `frontend/app/page.jsx`)
- Ask page → Web API client: requests stream (evidence: `frontend/app/page.jsx`)
- Ask page → Saved history: loads and saves (evidence: `frontend/app/page.jsx`)
- Web API client → HTTP API: calls stream API
- HTTP API → Answer pipeline: routes questions (evidence: `backend/api/routes.py`)
- Answer pipeline → ID lookup: looks up IDs (evidence: `backend/rag/pipeline.py`)
- Answer pipeline → Semantic retrieval: searches by meaning (evidence: `backend/rag/pipeline.py`)
- Answer pipeline → Cypher queries: runs keyword query (evidence: `backend/rag/pipeline.py`)
- Semantic retrieval → Text embeddings: embeds question (evidence: `backend/retrieval/hybrid.py`)
- Semantic retrieval → ID lookup: expands graph hits (evidence: `backend/retrieval/hybrid.py`)
- ID lookup → Cypher queries: selects query (evidence: `backend/retrieval/lookup.py`)
- Answer pipeline → Answer prompts: builds prompts (evidence: `backend/rag/pipeline.py`)
- Answer pipeline → Groq LLM: requests generation (evidence: `backend/rag/pipeline.py`)
- Answer pipeline → Answer verification: verifies answer (evidence: `backend/rag/pipeline.py`)
- Cypher queries → Graph connection: runs through (evidence: `backend/retrieval/lookup.py`)
- Graph connection → Neo4j graph: reads graph (evidence: `backend/graph/connection.py`)
- HTTP API → Graph connection: checks graph health (evidence: `backend/api/routes.py`)
- Answer pipeline → Answer view: streams answer data
- Answer view → Attack path map: renders attack paths (evidence: `frontend/app/Answer.jsx`)
- Insights page → Fix-first analytics: presents rankings
- Research page → Answer evaluation: presents results
