# vishalmalik-code/major_project architecture

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

- Interactive diagram: https://gitdiagram.com/vishalmalik-code/major_project
- Repository: https://github.com/vishalmalik-code/major_project

## Overview

This is a local model-extraction detection firewall: users and attack simulators submit queries through the same chat path, which analyzes query history and structure, updates client risk, then allows, monitors, throttles, or blocks before any permitted query reaches Ollama. Separate branches provide admin visibility, authenticated conversation features, and repeatable fast/slow evaluations. The README and sampled source establish the main flow; some route and UI details are represented at subsystem level because their implementations were not sampled.

Main entry points: [`backend/app/services/chat_service.py`](https://github.com/vishalmalik-code/major_project/blob/main/backend/app/services/chat_service.py) (Chat orchestration), [`frontend/src/api/client.js`](https://github.com/vishalmalik-code/major_project/blob/main/frontend/src/api/client.js) (API client), [`backend/app/firewall/engine.py`](https://github.com/vishalmalik-code/major_project/blob/main/backend/app/firewall/engine.py) (Decision engine), [`backend/app/api/routes/admin.py`](https://github.com/vishalmalik-code/major_project/blob/main/backend/app/api/routes/admin.py) (Admin API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Clients and UI"]
  node_browser["React app<br/>[App.jsx]"]
  node_chatui["User chat<br/>[UserChat.jsx]"]
  node_webapi["API client<br/>[client.js]"]
  node_attacker["Attacker CLI<br/>[attacker.py]"]
  node_strategies["Attack strategies<br/>[registry.py]"]
  node_httpclient["HTTP client<br/>[http_client.py]"]
  node_personas["User personas<br/>[base.py]"]
  node_auth["Session auth<br/>[AuthContext.jsx]"]
end

subgraph group_firewall["Firewall analysis"]
  node_window["Query window<br/>[window.py]"]
  node_encoder["Query embeddings<br/>[encoder.py]"]
  node_engine["Decision engine<br/>[engine.py]"]
  node_signals["Detection signals"]
end

subgraph group_services["Backend services"]
  node_chatroute["Chat endpoint<br/>[chat.py]"]
  node_chatservice["Chat orchestration<br/>[chat_service.py]"]
  node_repository["Data repository<br/>[repository.py]"]
  node_database[("PostgreSQL")]
  node_llmservice["LLM adapter<br/>[llm.py]"]
  node_events["Live event buses"]
end

subgraph group_operations["Admin and evaluation"]
  node_adminui["Admin dashboard<br/>[AdminDashboard.jsx]"]
  node_adminroute["Admin API<br/>[admin.py]"]
  node_evaluation["Evaluation sessions<br/>[sessions.py]"]
  node_evalrunner["Evaluation runner<br/>[runner.py]"]
end

node_user(("Normal user"))
node_ollama["Ollama model"]

node_user -->|"submits query"| node_chatui
node_browser -->|"routes to"| node_chatui
node_chatui -->|"sends chat"| node_webapi
node_webapi -->|"POST chat"| node_chatroute
node_attacker -->|"selects patterns"| node_strategies
node_attacker -->|"runs via"| node_httpclient
node_httpclient -->|"POST chat"| node_chatroute
node_chatroute -->|"handles request"| node_chatservice
node_chatservice -->|"loads and saves"| node_repository
node_chatservice -->|"warms and commits"| node_window
node_chatservice -->|"embeds query"| node_encoder
node_chatservice -->|"requests decision"| node_engine
node_engine -->|"reads history"| node_window
node_engine -->|"evaluates"| node_signals
node_repository -->|"reads and writes"| node_database
node_chatservice -->|"generates if allowed"| node_llmservice
node_llmservice -->|"generates response"| node_ollama
node_chatservice -->|"publishes updates"| node_events
node_adminui -->|"requests admin data"| node_webapi
node_webapi -->|"calls admin API"| node_adminroute
node_adminroute -->|"reads records"| node_repository
node_adminroute -->|"streams updates"| node_events
node_auth -->|"authenticates"| node_webapi
node_evaluation -->|"generates attack cases"| node_strategies
node_evaluation -->|"generates user cases"| node_personas
node_evalrunner -->|"sends test queries"| node_httpclient

click node_browser "https://github.com/vishalmalik-code/major_project/blob/main/frontend/src/App.jsx"
click node_chatui "https://github.com/vishalmalik-code/major_project/blob/main/frontend/src/pages/UserChat.jsx"
click node_webapi "https://github.com/vishalmalik-code/major_project/blob/main/frontend/src/api/client.js"
click node_attacker "https://github.com/vishalmalik-code/major_project/blob/main/backend/attacker.py"
click node_strategies "https://github.com/vishalmalik-code/major_project/blob/main/backend/app/attacker/registry.py"
click node_httpclient "https://github.com/vishalmalik-code/major_project/blob/main/backend/attacker_cli/http_client.py"
click node_chatroute "https://github.com/vishalmalik-code/major_project/blob/main/backend/app/api/routes/chat.py"
click node_chatservice "https://github.com/vishalmalik-code/major_project/blob/main/backend/app/services/chat_service.py"
click node_window "https://github.com/vishalmalik-code/major_project/blob/main/backend/app/firewall/window.py"
click node_encoder "https://github.com/vishalmalik-code/major_project/blob/main/backend/app/embeddings/encoder.py"
click node_engine "https://github.com/vishalmalik-code/major_project/blob/main/backend/app/firewall/engine.py"
click node_signals "https://github.com/vishalmalik-code/major_project/tree/main/backend/app/firewall/signals"
click node_repository "https://github.com/vishalmalik-code/major_project/blob/main/backend/app/db/repository.py"
click node_llmservice "https://github.com/vishalmalik-code/major_project/blob/main/backend/app/services/llm.py"
click node_adminui "https://github.com/vishalmalik-code/major_project/blob/main/frontend/src/pages/AdminDashboard.jsx"
click node_adminroute "https://github.com/vishalmalik-code/major_project/blob/main/backend/app/api/routes/admin.py"
click node_events "https://github.com/vishalmalik-code/major_project/blob/main/backend/app/services/conversation_events.py"
click node_evaluation "https://github.com/vishalmalik-code/major_project/blob/main/backend/evaluation/sessions.py"
click node_evalrunner "https://github.com/vishalmalik-code/major_project/blob/main/backend/evaluation/runner.py"
click node_personas "https://github.com/vishalmalik-code/major_project/blob/main/backend/normal_user_cli/base.py"
click node_auth "https://github.com/vishalmalik-code/major_project/blob/main/frontend/src/AuthContext.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_browser,node_chatui,node_webapi,node_attacker,node_strategies,node_httpclient,node_personas,node_auth,node_user toneBlue
class node_window,node_encoder,node_engine,node_signals toneAmber
class node_chatroute,node_chatservice,node_repository,node_database,node_llmservice,node_events toneMint
class node_adminui,node_adminroute,node_evaluation,node_evalrunner toneRose
class node_ollama toneIndigo
```

## Components

### Clients and UI

- [React app](https://github.com/vishalmalik-code/major_project/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [User chat](https://github.com/vishalmalik-code/major_project/blob/main/frontend/src/pages/UserChat.jsx): `frontend/src/pages/UserChat.jsx`
- [API client](https://github.com/vishalmalik-code/major_project/blob/main/frontend/src/api/client.js): `frontend/src/api/client.js`
- [Attacker CLI](https://github.com/vishalmalik-code/major_project/blob/main/backend/attacker.py): `backend/attacker.py`
- [Attack strategies](https://github.com/vishalmalik-code/major_project/blob/main/backend/app/attacker/registry.py): `backend/app/attacker/registry.py`
- [HTTP client](https://github.com/vishalmalik-code/major_project/blob/main/backend/attacker_cli/http_client.py): `backend/attacker_cli/http_client.py`
- [User personas](https://github.com/vishalmalik-code/major_project/blob/main/backend/normal_user_cli/base.py): `backend/normal_user_cli/base.py`
- [Session auth](https://github.com/vishalmalik-code/major_project/blob/main/frontend/src/AuthContext.jsx): `frontend/src/AuthContext.jsx`

### Firewall analysis

- [Query window](https://github.com/vishalmalik-code/major_project/blob/main/backend/app/firewall/window.py): `backend/app/firewall/window.py`
- [Query embeddings](https://github.com/vishalmalik-code/major_project/blob/main/backend/app/embeddings/encoder.py): `backend/app/embeddings/encoder.py`
- [Decision engine](https://github.com/vishalmalik-code/major_project/blob/main/backend/app/firewall/engine.py): `backend/app/firewall/engine.py`
- [Detection signals](https://github.com/vishalmalik-code/major_project/tree/main/backend/app/firewall/signals): `backend/app/firewall/signals`

### Backend services

- [Chat endpoint](https://github.com/vishalmalik-code/major_project/blob/main/backend/app/api/routes/chat.py): `backend/app/api/routes/chat.py`
- [Chat orchestration](https://github.com/vishalmalik-code/major_project/blob/main/backend/app/services/chat_service.py): `backend/app/services/chat_service.py`
- [Data repository](https://github.com/vishalmalik-code/major_project/blob/main/backend/app/db/repository.py): `backend/app/db/repository.py`
- **PostgreSQL**
- [LLM adapter](https://github.com/vishalmalik-code/major_project/blob/main/backend/app/services/llm.py): `backend/app/services/llm.py`
- [Live event buses](https://github.com/vishalmalik-code/major_project/blob/main/backend/app/services/conversation_events.py): `backend/app/services/conversation_events.py`

### Admin and evaluation

- [Admin dashboard](https://github.com/vishalmalik-code/major_project/blob/main/frontend/src/pages/AdminDashboard.jsx): `frontend/src/pages/AdminDashboard.jsx`
- [Admin API](https://github.com/vishalmalik-code/major_project/blob/main/backend/app/api/routes/admin.py): `backend/app/api/routes/admin.py`
- [Evaluation sessions](https://github.com/vishalmalik-code/major_project/blob/main/backend/evaluation/sessions.py): `backend/evaluation/sessions.py`
- [Evaluation runner](https://github.com/vishalmalik-code/major_project/blob/main/backend/evaluation/runner.py): `backend/evaluation/runner.py`

### Other components

- **Normal user**
- **Ollama model**

## Connections

- Normal user → User chat: submits query (evidence: `README.md`)
- React app → User chat: routes to (evidence: `frontend/src/App.jsx`)
- User chat → API client: sends chat (evidence: `frontend/src/api/client.js`)
- API client → Chat endpoint: POST chat (evidence: `README.md`)
- Attacker CLI → Attack strategies: selects patterns (evidence: `backend/attacker.py`)
- Attacker CLI → HTTP client: runs via
- HTTP client → Chat endpoint: POST chat (evidence: `backend/attacker_cli/http_client.py`)
- Chat endpoint → Chat orchestration: handles request (evidence: `backend/app/main.py`)
- Chat orchestration → Data repository: loads and saves (evidence: `backend/app/services/chat_service.py`)
- Chat orchestration → Query window: warms and commits
- Chat orchestration → Query embeddings: embeds query (evidence: `backend/app/services/chat_service.py`)
- Chat orchestration → Decision engine: requests decision (evidence: `backend/app/services/chat_service.py`)
- Decision engine → Query window: reads history (evidence: `backend/app/firewall/engine.py`)
- Decision engine → Detection signals: evaluates (evidence: `backend/app/firewall/engine.py`)
- Data repository → PostgreSQL: reads and writes (evidence: `backend/app/db/repository.py`)
- Chat orchestration → LLM adapter: generates if allowed (evidence: `README.md`)
- LLM adapter → Ollama model: generates response (evidence: `README.md`)
- Chat orchestration → Live event buses: publishes updates (evidence: `backend/app/services/chat_service.py`)
- Admin dashboard → API client: requests admin data (evidence: `frontend/src/pages/AdminDashboard.jsx`)
- API client → Admin API: calls admin API (evidence: `frontend/src/api/client.js`)
- Admin API → Data repository: reads records (evidence: `backend/app/api/routes/admin.py`)
- Admin API → Live event buses: streams updates (evidence: `backend/app/api/routes/admin.py`)
- Session auth → API client: authenticates (evidence: `frontend/src/AuthContext.jsx`)
- Evaluation sessions → Attack strategies: generates attack cases (evidence: `backend/evaluation/sessions.py`)
- Evaluation sessions → User personas: generates user cases (evidence: `backend/evaluation/sessions.py`)
- Evaluation runner → HTTP client: sends test queries (evidence: `backend/evaluation/runner.py`)
