# veershah1152/sunhacks- architecture

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

- Interactive diagram: https://gitdiagram.com/veershah1152/sunhacks-
- Repository: https://github.com/veershah1152/sunhacks-

## Overview

1. **System boundary**
   - This repo is a two-tier OSINT intelligence system: a **React/Vite frontend** and a **Python/FastAPI backend**.
   - The backend is the core of the architecture; it ingests conflict-related sources, stores them in a searchable corpus, runs multi-agent analysis, and returns a structured intelligence report.

2. **Frontend subsystem**
   - The frontend is a dashboard-style SPA built with **React** and **Vite**.
   - `App.jsx` is the root composition point, with `Dashboard.jsx` and `LoginPage.jsx` indicating a simple authenticated/unauthenticated split.
   - `AuthContext.jsx` and `IntelligenceContext.jsx` hold session/auth state and the latest analysis payload, which the UI renders into cards such as risk, signals, scenarios, sources, impact, and trend views.

3. **Backend API boundary**
   - `backend/main.py` is the FastAPI entrypoint and exposes the main contract to the frontend.
   - The documented endpoints are:
     - `GET /health` for service/store status
     - `POST /update` for ingesting new OSINT
     - `GET /analyze` for running the intelligence pipeline
     - `POST /clear` for wiping stored data
   - This creates a clear separation between the UI and all ingestion/analysis/storage logic.

4. **Ingestion subsystem**
   - External sources are pulled through `backend/ingestion/gnews_fetcher.py` and `backend/ingestion/rss_fetcher.py`.
   - The system combines a search-style news API source with RSS feeds from major publishers, giving it both query-driven retrieval and continuous feed coverage.
   - The `update` flow is the primary entry point for new evidence entering the system.

5. **Text preprocessing boundary**
   - `backend/processing/cleaner.py` strips noise/HTML and normalizes article text before storage.
   - `backend/processing/chunker.py` breaks longer text into smaller semantic chunks for embedding and retrieval.
   - This preprocessing layer sits between raw source ingestion and vector storage, ensuring the stored corpus is analysis-ready.

6. **Persistent data layer**
   - The main storage design is a **dual-store architecture**: `FAISS` for vector similarity search and `SQLite` for metadata/deduplication.
   - `StoreManager` coordinates both stores and handles incremental merges, so the index grows over time rather than being rebuilt on each update.
   - The README emphasizes two deduplication boundaries: **URL hash** and **content hash**, which prevents the same article from being embedded twice.
   - `mongo_store.py` exists as an alternate backend, but the documented primary architecture is FAISS + SQLite.

7. **Storage lifecycle and cache behavior**
   - The repo includes a `backend/cache/` directory and a `cache_manager.py`, indicating query/result caching for repeated analysis runs.
   - The store is persisted on disk, so startup can restore state rather than starting empty.
   - `POST /clear` is a reset path for development or operational cleanup.

8. **Analysis subsystem: multi-agent pipeline**
   - `backend/pipeline/crew_runner.py` orchestrates the analysis run as a sequential agent pipeline.
   - The agents directory contains multiple specialized roles: ingestion, detection, risk scoring, simulation, report generation, trend analysis, impact analysis, civilian impact, and briefing.
   - In architectural terms, the key pattern is: **retrieve evidence → assess risk → simulate scenarios → format final report**.

9. **LLM/runtime dependency**
   - The analysis layer depends on **Ollama with Llama 3.2**, which runs locally and is invoked by the agent pipeline.
   - This means the backend is not just a search service; it is an AI reasoning system that transforms stored OSINT into a structured intelligence product.

10. **End-to-end data flow**
    - The primary flow is:
      - frontend submits a query
      - FastAPI calls ingestion on `/update`
      - fetched articles are cleaned, chunked, deduplicated, and stored in FAISS/SQLite
      - `/analyze` retrieves relevant stored evidence
      - the agent pipeline generates a JSON intelligence report
      - the frontend renders that report into dashboard cards and charts
    - This makes the corpus store the main shared boundary between ingestion and analysis.

11. **Operational and product shape**
    - The repo is designed for local/dev deployment rather than cloud-native scaling: Python backend, Node frontend, local Ollama model, disk-persistent vector store.
    - The UI components are focused on analyst workflow, not generic CRUD: risk, signals, scenarios, sources, impact, and trends.
    - For an architecture diagram, the most important boxes are: **React dashboard**, **FastAPI orchestration**, **OSINT ingestion**, **preprocessing**, **FAISS/SQLite persistence**, **agent pipeline**, and **local LLM runtime**.

Main entry points: [`backend/main.py`](https://github.com/veershah1152/sunhacks-/blob/main/backend/main.py) (API), [`frontend/src/App.jsx`](https://github.com/veershah1152/sunhacks-/blob/main/frontend/src/App.jsx) (App), [`backend/pipeline/crew_runner.py`](https://github.com/veershah1152/sunhacks-/blob/main/backend/pipeline/crew_runner.py) (Crew runner), [`backend/database/store_manager.py`](https://github.com/veershah1152/sunhacks-/blob/main/backend/database/store_manager.py) (Store manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_ui_app["App<br/>react shell<br/>[App.jsx]"]
  node_ui_auth(("Auth<br/>context<br/>[AuthContext.jsx]"))
  node_ui_intel(("Intel state<br/>context"))
  node_ui_dashboard["Dashboard<br/>view<br/>[Dashboard.jsx]"]
  node_ui_login["Login<br/>view<br/>[LoginPage.jsx]"]
  node_ui_cards["Analysis cards<br/>ui components"]
end

subgraph group_backend["Backend"]
  node_api_main["API<br/>[main.py]"]
  node_ingest_news["News fetcher<br/>ingestion<br/>[gnews_fetcher.py]"]
  node_ingest_rss["RSS fetcher<br/>ingestion<br/>[rss_fetcher.py]"]
  node_cleaner["Cleaner<br/>preprocessing<br/>[cleaner.py]"]
  node_chunker["Chunker<br/>preprocessing<br/>[chunker.py]"]
  node_store_mgr["Store manager<br/>storage coordinator<br/>[store_manager.py]"]
  node_faiss_store[("FAISS<br/>vector store<br/>[faiss_store.py]")]
  node_sqlite_store[("SQLite<br/>metadata store<br/>[sqlite_store.py]")]
  node_cache_mgr[("Cache<br/>[cache_manager.py]")]
  node_crew_runner["Crew runner<br/>analysis pipeline<br/>[crew_runner.py]"]
  node_agents{{"Agents<br/>multi-agent set"}}
end

subgraph group_runtime["Runtime"]
  node_ollama(("Ollama Llama 3.2<br/>local LLM"))
end

node_ui_app -->|"uses"| node_ui_auth
node_ui_app -->|"uses"| node_ui_intel
node_ui_app -->|"routes to"| node_ui_dashboard
node_ui_app -->|"routes to"| node_ui_login
node_ui_dashboard -->|"renders"| node_ui_cards
node_ui_intel -->|"feeds"| node_ui_cards
node_ui_login -.->|"auth flow"| node_api_main
node_api_main -->|"update"| node_ingest_news
node_api_main -->|"update"| node_ingest_rss
node_ingest_news -->|"preprocess"| node_cleaner
node_ingest_rss -->|"preprocess"| node_cleaner
node_cleaner -->|"prepare"| node_chunker
node_chunker -->|"store"| node_store_mgr
node_store_mgr -->|"vectorize"| node_faiss_store
node_store_mgr -->|"metadata"| node_sqlite_store
node_sqlite_store -.->|"supports"| node_cache_mgr
node_api_main -->|"analyze"| node_crew_runner
node_crew_runner -->|"orchestrates"| node_agents
node_crew_runner -->|"retrieve"| node_faiss_store
node_crew_runner -->|"reasoning"| node_ollama
node_agents -.->|"uses"| node_ollama
node_api_main -->|"clear/update"| node_store_mgr

click node_ui_app "https://github.com/veershah1152/sunhacks-/blob/main/frontend/src/App.jsx"
click node_ui_auth "https://github.com/veershah1152/sunhacks-/blob/main/frontend/src/context/AuthContext.jsx"
click node_ui_intel "https://github.com/veershah1152/sunhacks-/blob/main/frontend/src/context/IntelligenceContext.jsx"
click node_ui_dashboard "https://github.com/veershah1152/sunhacks-/blob/main/frontend/src/Dashboard.jsx"
click node_ui_login "https://github.com/veershah1152/sunhacks-/blob/main/frontend/src/LoginPage.jsx"
click node_ui_cards "https://github.com/veershah1152/sunhacks-/tree/main/frontend/src/components"
click node_api_main "https://github.com/veershah1152/sunhacks-/blob/main/backend/main.py"
click node_ingest_news "https://github.com/veershah1152/sunhacks-/blob/main/backend/ingestion/gnews_fetcher.py"
click node_ingest_rss "https://github.com/veershah1152/sunhacks-/blob/main/backend/ingestion/rss_fetcher.py"
click node_cleaner "https://github.com/veershah1152/sunhacks-/blob/main/backend/processing/cleaner.py"
click node_chunker "https://github.com/veershah1152/sunhacks-/blob/main/backend/processing/chunker.py"
click node_store_mgr "https://github.com/veershah1152/sunhacks-/blob/main/backend/database/store_manager.py"
click node_faiss_store "https://github.com/veershah1152/sunhacks-/blob/main/backend/database/faiss_store.py"
click node_sqlite_store "https://github.com/veershah1152/sunhacks-/blob/main/backend/database/sqlite_store.py"
click node_cache_mgr "https://github.com/veershah1152/sunhacks-/blob/main/backend/pipeline/cache_manager.py"
click node_crew_runner "https://github.com/veershah1152/sunhacks-/blob/main/backend/pipeline/crew_runner.py"
click node_agents "https://github.com/veershah1152/sunhacks-/tree/main/backend/agents"

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_ui_app,node_ui_auth,node_ui_intel,node_ui_dashboard,node_ui_login,node_ui_cards toneBlue
class node_api_main,node_ingest_news,node_ingest_rss,node_cleaner,node_chunker,node_store_mgr,node_faiss_store,node_sqlite_store,node_cache_mgr,node_crew_runner,node_agents toneAmber
class node_ollama toneMint
```

## Components

### Frontend

React/Vite analyst dashboard and session state

- [App](https://github.com/veershah1152/sunhacks-/blob/main/frontend/src/App.jsx): react shell · Root composition and authenticated dashboard/login split · `frontend/src/App.jsx`
- [Auth](https://github.com/veershah1152/sunhacks-/blob/main/frontend/src/context/AuthContext.jsx): context · Session and login state · `frontend/src/context/AuthContext.jsx`
- [Intel state](https://github.com/veershah1152/sunhacks-/blob/main/frontend/src/context/IntelligenceContext.jsx): context · Latest intelligence payload for the dashboard · `frontend/src/context/IntelligenceContext.jsx`
- [Dashboard](https://github.com/veershah1152/sunhacks-/blob/main/frontend/src/Dashboard.jsx): view · Main analyst workspace · `frontend/src/Dashboard.jsx`
- [Login](https://github.com/veershah1152/sunhacks-/blob/main/frontend/src/LoginPage.jsx): view · Unauthenticated entry screen · `frontend/src/LoginPage.jsx`
- [Analysis cards](https://github.com/veershah1152/sunhacks-/tree/main/frontend/src/components): ui components · Risk, signals, scenarios, sources, impact, trends, briefings · `frontend/src/components`

### Backend

FastAPI orchestration, ingestion, storage, and analysis

- [API](https://github.com/veershah1152/sunhacks-/blob/main/backend/main.py): FastAPI app · HTTP boundary for health, update, analyze, and clear · `backend/main.py`
- [News fetcher](https://github.com/veershah1152/sunhacks-/blob/main/backend/ingestion/gnews_fetcher.py): ingestion · Search-style external news retrieval · `backend/ingestion/gnews_fetcher.py`
- [RSS fetcher](https://github.com/veershah1152/sunhacks-/blob/main/backend/ingestion/rss_fetcher.py): ingestion · Publisher feed collection · `backend/ingestion/rss_fetcher.py`
- [Cleaner](https://github.com/veershah1152/sunhacks-/blob/main/backend/processing/cleaner.py): preprocessing · Noise and HTML normalization · `backend/processing/cleaner.py`
- [Chunker](https://github.com/veershah1152/sunhacks-/blob/main/backend/processing/chunker.py): preprocessing · Splits articles into retrievable text chunks · `backend/processing/chunker.py`
- [Store manager](https://github.com/veershah1152/sunhacks-/blob/main/backend/database/store_manager.py): storage coordinator · Coordinates incremental writes and merges across stores · `backend/database/store_manager.py`
- [FAISS](https://github.com/veershah1152/sunhacks-/blob/main/backend/database/faiss_store.py): vector store · Similarity search index for chunk embeddings · `backend/database/faiss_store.py`
- [SQLite](https://github.com/veershah1152/sunhacks-/blob/main/backend/database/sqlite_store.py): metadata store · Persistent metadata, hashes, and deduplication · `backend/database/sqlite_store.py`
- [Cache](https://github.com/veershah1152/sunhacks-/blob/main/backend/pipeline/cache_manager.py): pipeline cache · Caches repeated analysis results · `backend/pipeline/cache_manager.py`
- [Crew runner](https://github.com/veershah1152/sunhacks-/blob/main/backend/pipeline/crew_runner.py): analysis pipeline · Orchestrates sequential multi-agent intelligence generation · `backend/pipeline/crew_runner.py`
- [Agents](https://github.com/veershah1152/sunhacks-/tree/main/backend/agents): multi-agent set · Ingestion, detection, risk, simulation, impact, trends, briefing, report · `backend/agents`

### Runtime

Local model dependency used by the analysis pipeline

- **Ollama Llama 3.2**: local LLM · Local model runtime used by the analysis agents

## Connections

- App → Auth: uses · App consumes session state
- App → Intel state: uses · App consumes current intelligence payload
- App → Dashboard: routes to · Authenticated analyst workspace
- App → Login: routes to · Unauthenticated entry screen
- Dashboard → Analysis cards: renders · Dashboard displays report sections and charts
- Intel state → Analysis cards: feeds · Context provides the structured report data
- Login → API: auth flow · Login initiates backend interaction
- API → News fetcher: update · Fetches search-driven news sources
- API → RSS fetcher: update · Fetches RSS sources
- News fetcher → Cleaner: preprocess · Raw articles are normalized
- RSS fetcher → Cleaner: preprocess · Raw feed items are normalized
- Cleaner → Chunker: prepare · Clean text is segmented for retrieval
- Chunker → Store manager: store · Chunks enter persistent corpus management
- Store manager → FAISS: vectorize · Embeddings stored for similarity search
- Store manager → SQLite: metadata · Hashes, source metadata, and deduplication stored
- SQLite → Cache: supports · Store-backed queries may be cached for reuse
- API → Crew runner: analyze · Analyze endpoint triggers the intelligence pipeline
- Crew runner → Agents: orchestrates · Pipeline coordinates specialized agent roles
- Crew runner → FAISS: retrieve · Pulls relevant evidence from the vector corpus
- Crew runner → Ollama Llama 3.2: reasoning · Agents invoke the local LLM runtime
- Agents → Ollama Llama 3.2: uses · Agent tasks rely on local model inference
- API → Store manager: clear/update · API controls persistence lifecycle
