# kaifhoda1/cipherai architecture

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

- Interactive diagram: https://gitdiagram.com/kaifhoda1/cipherai
- Repository: https://github.com/kaifhoda1/cipherai

## Overview

1. **Repository shape**
   - This is a very small, single-service Python project.
   - The only application code in the tree is `src/app.py`, with `requirements.txt` and a `Dockerfile` supporting execution and packaging.
   - There is no separate backend/frontend split in the repo; the app is likely a single Python process with a local UI and local AI calls.

2. **Primary purpose**
   - CipherAI is designed as a **local-only AI security assistant**.
   - The architectural constraint is important: the README explicitly says **no data leaves the machine**.
   - That means the main boundary is between the user session and locally hosted AI/data components, not between the app and cloud services.

3. **User-facing interface**
   - The README says the UI is built with **Streamlit**.
   - So the top of the system is a browser-based chat interface served by the Python app.
   - This layer is responsible for capturing questions, presenting answers, and likely managing chat state.

4. **Application orchestrator**
   - `src/app.py` is the central entrypoint and probably coordinates the whole flow.
   - In architecture terms, it likely acts as the orchestrator that connects:
     - UI input
     - prompt construction
     - local model invocation
     - eventual retrieval pipeline
     - response rendering
   - Because there is only one source file in the tree, the current implementation is probably monolithic rather than heavily layered.

5. **Local model runtime**
   - The stack explicitly includes **Ollama + Mistral 7B**.
   - This is the core inference boundary: the Python app sends prompts to a local Ollama runtime, which hosts the model.
   - For a diagram, treat Ollama as an external local service/process that the app calls over a local interface, not as part of the Python app itself.

6. **Knowledge sources and future RAG layer**
   - The README identifies a planned/targeted **RAG pipeline** over:
     - **MITRE ATT&CK**
     - **NVD CVE** data
   - These datasets are the domain knowledge boundary for security answers and mitigation suggestions.
   - In the future architecture, queries should flow through retrieval before generation, so the model can answer from curated security context rather than only from parametric memory.

7. **Data flow: current state**
   - Current runtime flow is likely:
     - User asks a security question in Streamlit
     - `app.py` builds a prompt
     - Prompt is sent to local Ollama/Mistral
     - Model response is returned to the Streamlit UI
   - In the current repo state, there is no visible dedicated retrieval/indexing subsystem in the file tree.

8. **Data flow: planned state with RAG**
   - The intended future flow is:
     - User question
     - Query preprocessing
     - Retrieval from local MITRE/NVD corpus
     - Context injection into the prompt
     - Ollama/Mistral generation
     - Response displayed in Streamlit
   - The retrieval layer becomes the key architectural middle tier between the UI and the model.

9. **Storage and local assets**
   - The README mentions `data/`, `models/`, and `docs/`, but those folders are not present in the current tree.
   - Architecturally, those directories represent expected local artifacts:
     - datasets for security knowledge
     - downloaded model assets
     - supporting documentation
   - This reinforces that the system is meant to run offline with local assets rather than remote APIs.

10. **Deployment boundary**
   - The `Dockerfile` indicates the app is intended to be containerized for repeatable local deployment.
   - For architecture, this is a single deployable unit: the Python app plus its dependencies, with Ollama and local model/data dependencies likely running alongside or on the host.
   - `requirements.txt` defines the Python runtime surface area; no other runtime services are evident from the tree.

11. **Project maturity**
   - The README roadmap shows phases already completed for local model runtime and Streamlit UI, while the RAG and fine-tuning phases are still pending.
   - So the current architecture is best drawn as a **minimal local chat assistant** with **planned expansion** into a security-focused retrieval-augmented system.

12. **What to emphasize in a diagram**
   - Draw the main trust boundary as fully local.
   - Show Streamlit/UI, Python orchestration, Ollama/Mistral inference, and future MITRE/NVD retrieval as the key subsystems.
   - Avoid introducing cloud services, databases, or microservices; none are evidenced by the repo tree or README.

Main entry points: [`src/app.py`](https://github.com/kaifhoda1/cipherai/blob/main/src/app.py) (App Core), [`Dockerfile`](https://github.com/kaifhoda1/cipherai/tree/main/Dockerfile) (Docker Image), [`requirements.txt`](https://github.com/kaifhoda1/cipherai/blob/main/requirements.txt) (Python Deps)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Interface"]
  node_n1["Streamlit UI<br/>web UI"]
end

subgraph group_g2["Python App"]
  node_n2["App Core<br/>orchestrator<br/>[app.py]"]
  node_n3["Prompt Builder<br/>prompting"]
  node_n4["Chat State<br/>session state"]
  node_n5["Response Renderer<br/>output"]
end

subgraph group_g3["Local Runtime"]
  node_n6[("Ollama<br/>local LLM runtime")]
  node_n7{{"Mistral 7B<br/>LLM"}}
end

subgraph group_g4["Security Knowledge"]
  node_n8["RAG Layer<br/>retrieval pipeline"]
  node_n9["MITRE ATT&CK<br/>security corpus"]
  node_n10["NVD CVEs<br/>security corpus"]
  node_n11[("Local Assets<br/>offline storage")]
end

subgraph group_g5["Packaging"]
  node_n12["Docker Image<br/>container build"]
  node_n13["Python Deps<br/>runtime deps<br/>[requirements.txt]"]
end

node_n1 -->|"chat input"| node_n2
node_n2 -->|"track state"| node_n4
node_n2 -->|"build prompt"| node_n3
node_n3 -->|"send prompt"| node_n6
node_n6 -->|"host model"| node_n7
node_n7 -->|"answer text"| node_n5
node_n2 -->|"render output"| node_n5
node_n2 -->|"package"| node_n12
node_n2 -->|"install deps"| node_n13
node_n8 -.->|"retrieve ATT&CK"| node_n9
node_n8 -.->|"retrieve CVEs"| node_n10
node_n8 -.->|"load corpus"| node_n11
node_n2 -.->|"query retrieval"| node_n8
node_n8 -.->|"inject context"| node_n3

click node_n2 "https://github.com/kaifhoda1/cipherai/blob/main/src/app.py"
click node_n12 "https://github.com/kaifhoda1/cipherai/tree/main/Dockerfile"
click node_n13 "https://github.com/kaifhoda1/cipherai/blob/main/requirements.txt"

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_n1 toneBlue
class node_n2,node_n3,node_n4,node_n5 toneAmber
class node_n6,node_n7 toneMint
class node_n8,node_n9,node_n10,node_n11 toneRose
class node_n12,node_n13 toneIndigo
```

## Components

### Interface

User-facing local chat experience

- **Streamlit UI**: web UI · Browser-based chat interface for asking questions and viewing answers

### Python App

Single-process application and prompt orchestration

- [App Core](https://github.com/kaifhoda1/cipherai/blob/main/src/app.py): orchestrator · Central Python entrypoint that coordinates the end-to-end request flow · `src/app.py`
- **Prompt Builder**: prompting · Constructs the instruction and context sent to the model
- **Chat State**: session state · Maintains conversation context for the interactive session
- **Response Renderer**: output · Formats model output back into the Streamlit interface

### Local Runtime

On-machine model inference boundary

- **Ollama**: local LLM runtime · Local inference service used to execute the model offline
- **Mistral 7B**: LLM · Primary local language model for security assistance

### Security Knowledge

Planned local retrieval sources and corpus

- **RAG Layer**: retrieval pipeline · Planned retrieval and context injection stage before generation
- **MITRE ATT&CK**: security corpus · Planned local knowledge source for tactics and techniques
- **NVD CVEs**: security corpus · Planned local vulnerability knowledge source
- **Local Assets**: offline storage · Expected local data, model, and docs artifacts for offline operation

### Packaging

Repeatable local deployment surface

- [Docker Image](https://github.com/kaifhoda1/cipherai/tree/main/Dockerfile): container build · Containerized packaging for repeatable local deployment · `Dockerfile`
- [Python Deps](https://github.com/kaifhoda1/cipherai/blob/main/requirements.txt): runtime deps · Pinned Python dependency surface for the single-service app · `requirements.txt`

## Connections

- Streamlit UI → App Core: chat input · User requests are passed from the Streamlit interface into the Python app
- App Core → Chat State: track state · The app preserves conversation context during the session
- App Core → Prompt Builder: build prompt · Core logic assembles the instruction payload for inference
- Prompt Builder → Ollama: send prompt · Prompt text is forwarded to the local Ollama runtime
- Ollama → Mistral 7B: host model · Ollama serves the Mistral model locally for inference
- Mistral 7B → Response Renderer: answer text · Generated text is returned for presentation in the UI
- App Core → Response Renderer: render output · The app hands the final answer back to the interface layer
- App Core → Docker Image: package · The service is containerized for local deployment
- App Core → Python Deps: install deps · Runtime dependencies define the Python execution surface
- RAG Layer → MITRE ATT&CK: retrieve ATT&CK · Planned retrieval over MITRE ATT&CK content
- RAG Layer → NVD CVEs: retrieve CVEs · Planned retrieval over NVD vulnerability content
- RAG Layer → Local Assets: load corpus · Retrieval operates over local offline artifacts
- App Core → RAG Layer: query retrieval · Future flow inserts retrieval before generation
- RAG Layer → Prompt Builder: inject context · Retrieved evidence is appended into the prompt
