# ashutoshmishra52/bitforensics architecture

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

- Interactive diagram: https://gitdiagram.com/ashutoshmishra52/bitforensics
- Repository: https://github.com/ashutoshmishra52/bitforensics

## Overview

#### Purpose and Entry Points
BitForensics is an offline Bitcoin-forensics workstation: it ingests transaction/network datasets, enriches and correlates records, detects suspicious activity, persists alerts, and serves a browser dashboard. Runtime entry points are `run.py` and `backend/main.py`; the Node development launcher is `scripts/dev.js`. The static client is served from `frontend/dist/index.html`.

#### API and Application Orchestration
FastAPI in `backend/main.py` owns the operational workflow and public API: ingest, analysis, alert retrieval, graph retrieval, stats, GeoIP download, and exports. It is the boundary between the static browser client and all backend processing. The frontend calls these APIs from bundled browser assets such as `frontend/dist/assets/app.js` and visualizes relationship data with `frontend/dist/assets/graph.js`.

#### Ingestion and Normalization
`backend/ingest/parser.py` accepts CSV, JSON, and XML transaction/network feeds, maps common source-field aliases to a normalized transaction shape, and prepares records for storage and analysis. Shared typed/domain representations are defined in `backend/models/schemas.py`. Sample source feeds under `data/samples/` support offline demonstrations and local evaluation.

#### Persistence and Alert Archiving
SQLite is the primary local persistence layer, implemented through SQLAlchemy setup and data access in `backend/database/db.py`. Alert data can additionally be archived to an optional PostgreSQL instance via `backend/database/postgres_alerts.py`; `docker-compose.yml` supplies the local infrastructure path. This separates normal offline operation from optional cross-store archival.

#### Enrichment and Correlation
GeoIP enrichment resolves country and ASN context from IP data through `backend/geo/lookup.py`, with database acquisition handled by `backend/geo/download.py`. The bundled offline GeoIP source is `data/geoip.csv`. `backend/correlation/engine.py` joins network metadata, address/transaction behavior, and enrichment signals to produce evidence usable by detection and investigation.

#### Analysis and Alert Generation
The analysis stage in `backend/ml/analyzer.py` derives features and applies anomaly detection using packaged scikit-learn artifacts: `data/models/feature_scaler.joblib` and `data/models/isolation_forest.joblib`. Deterministic suspicious-pattern logic and explainable indicators are separated into `backend/ml/red_flags.py` and `backend/ml/typology.py`. Their combined output is ranked alert data rather than a definitive attribution decision.

#### Investigation Graph and Outputs
`backend/graph/builder.py` transforms transactions, addresses, and correlated entities into node/link graph data for the Link Graph interface. The API then exposes alerts and graph results to the static UI, while export endpoints generate retained investigation artifacts under the local data area. Packaging paths (`packaging/desktop_app.py`, `packaging/launch_bitforensics.py`) wrap the same local server/UI model for desktop distribution across supported operating systems.

Main entry points: [`backend/main.py`](https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/main.py) (FastAPI Orchestrator), [`backend/database/db.py`](https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/database/db.py) (SQLite Store), [`backend/ingest/parser.py`](https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/ingest/parser.py) (Feed Parser), [`frontend/dist/index.html`](https://github.com/ashutoshmishra52/bitforensics/blob/main/frontend/dist/index.html) (Static Dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser Client"]
  node_ui["Static Dashboard<br/>browser UI<br/>[index.html]"]
  node_app_bundle["API Client Bundle<br/>browser assets<br/>[app.js]"]
  node_graph_view["Link Graph View<br/>browser visualization<br/>[graph.js]"]
end

subgraph group_backend["Backend Workflow"]
  node_api{{"FastAPI Orchestrator<br/>API server<br/>[main.py]"}}
  node_parser["Feed Parser<br/>normalization<br/>[parser.py]"]
  node_schemas["Domain Schemas<br/>typed models<br/>[schemas.py]"]
  node_geo_download["GeoIP Acquisition<br/>enrichment setup<br/>[download.py]"]
  node_geo_lookup["GeoIP Lookup<br/>enrichment<br/>[lookup.py]"]
  node_correlation["Correlation Engine<br/>evidence correlation<br/>[engine.py]"]
  node_analyzer["Anomaly Analyzer<br/>ML analysis<br/>[analyzer.py]"]
  node_red_flags["Red Flags &amp; Typologies<br/>rule detection<br/>[red_flags.py]"]
  node_graph_builder["Investigation Graph Builder<br/>graph projection<br/>[builder.py]"]
end

subgraph group_data["Local Data &amp; Stores"]
  node_sqlite[("SQLite Store<br/>primary persistence<br/>[db.py]")]
  node_postgres[("PostgreSQL Alert Archive<br/>optional archive<br/>[postgres_alerts.py]")]
  node_sample_feeds["Sample Feeds<br/>offline datasets"]
  node_geoip_data["Offline GeoIP Data<br/>GeoIP source<br/>[geoip.csv]"]
  node_ml_artifacts["ML Artifacts<br/>scikit-learn models"]
end

subgraph group_distribution["Launch &amp; Distribution"]
  node_desktop_packaging["Desktop Packaging<br/>desktop launcher<br/>[desktop_app.py]"]
  node_runtime_entry["Runtime Entry<br/>server launcher<br/>[run.py]"]
  node_dev_launcher["Node Dev Launcher<br/>development launcher<br/>[dev.js]"]
end

node_ui -->|"loads"| node_app_bundle
node_app_bundle -->|"calls APIs"| node_api
node_graph_view -->|"retrieves graph data"| node_api
node_api -->|"ingests feeds"| node_parser
node_sample_feeds -->|"source data"| node_parser
node_parser -->|"maps to"| node_schemas
node_parser -->|"stores normalized records"| node_sqlite
node_api -->|"downloads GeoIP"| node_geo_download
node_geo_download -->|"acquires"| node_geoip_data
node_sqlite -->|"supplies IP records"| node_geo_lookup
node_geoip_data -->|"lookup source"| node_geo_lookup
node_geo_lookup -->|"enrichment context"| node_correlation
node_sqlite -->|"transaction and network data"| node_correlation
node_correlation -->|"correlated evidence"| node_analyzer
node_ml_artifacts -->|"scores with"| node_analyzer
node_analyzer -->|"analysis signals"| node_red_flags
node_red_flags -->|"ranked alerts"| node_sqlite
node_sqlite -.->|"optional alert archive"| node_postgres
node_sqlite -->|"investigation entities"| node_graph_builder
node_graph_builder -->|"node/link results"| node_api
node_api -->|"alerts, stats, exports"| node_ui
node_runtime_entry -->|"starts"| node_api
node_dev_launcher -->|"starts development runtime"| node_api
node_desktop_packaging -->|"packages launcher"| node_runtime_entry
node_desktop_packaging -->|"bundles local UI"| node_ui

click node_ui "https://github.com/ashutoshmishra52/bitforensics/blob/main/frontend/dist/index.html"
click node_app_bundle "https://github.com/ashutoshmishra52/bitforensics/blob/main/frontend/dist/assets/app.js"
click node_graph_view "https://github.com/ashutoshmishra52/bitforensics/blob/main/frontend/dist/assets/graph.js"
click node_api "https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/main.py"
click node_parser "https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/ingest/parser.py"
click node_schemas "https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/models/schemas.py"
click node_geo_download "https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/geo/download.py"
click node_geo_lookup "https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/geo/lookup.py"
click node_correlation "https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/correlation/engine.py"
click node_analyzer "https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/ml/analyzer.py"
click node_red_flags "https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/ml/red_flags.py"
click node_graph_builder "https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/graph/builder.py"
click node_sqlite "https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/database/db.py"
click node_postgres "https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/database/postgres_alerts.py"
click node_geoip_data "https://github.com/ashutoshmishra52/bitforensics/blob/main/data/geoip.csv"
click node_ml_artifacts "https://github.com/ashutoshmishra52/bitforensics/blob/main/data/models/isolation_forest.joblib"
click node_desktop_packaging "https://github.com/ashutoshmishra52/bitforensics/blob/main/packaging/desktop_app.py"
click node_runtime_entry "https://github.com/ashutoshmishra52/bitforensics/blob/main/run.py"
click node_dev_launcher "https://github.com/ashutoshmishra52/bitforensics/blob/main/scripts/dev.js"

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,node_app_bundle,node_graph_view toneBlue
class node_api,node_parser,node_schemas,node_geo_download,node_geo_lookup,node_correlation,node_analyzer,node_red_flags,node_graph_builder toneAmber
class node_sqlite,node_postgres,node_sample_feeds,node_geoip_data,node_ml_artifacts toneMint
class node_desktop_packaging,node_runtime_entry,node_dev_launcher toneRose
```

## Components

### Browser Client

- [Static Dashboard](https://github.com/ashutoshmishra52/bitforensics/blob/main/frontend/dist/index.html): browser UI · `frontend/dist/index.html`
- [API Client Bundle](https://github.com/ashutoshmishra52/bitforensics/blob/main/frontend/dist/assets/app.js): browser assets · `frontend/dist/assets/app.js`
- [Link Graph View](https://github.com/ashutoshmishra52/bitforensics/blob/main/frontend/dist/assets/graph.js): browser visualization · `frontend/dist/assets/graph.js`

### Backend Workflow

- [FastAPI Orchestrator](https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/main.py): API server · Owns ingest, analysis, investigation, GeoIP, and export workflows. · `backend/main.py`
- [Feed Parser](https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/ingest/parser.py): normalization · Normalizes CSV, JSON, and XML feeds into transaction records. · `backend/ingest/parser.py`
- [Domain Schemas](https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/models/schemas.py): typed models · `backend/models/schemas.py`
- [GeoIP Acquisition](https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/geo/download.py): enrichment setup · `backend/geo/download.py`
- [GeoIP Lookup](https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/geo/lookup.py): enrichment · Adds country and ASN context from IP data. · `backend/geo/lookup.py`
- [Correlation Engine](https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/correlation/engine.py): evidence correlation · Joins transaction, address, network, and enrichment signals. · `backend/correlation/engine.py`
- [Anomaly Analyzer](https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/ml/analyzer.py): ML analysis · Derives features and scores records with packaged models. · `backend/ml/analyzer.py`
- [Red Flags & Typologies](https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/ml/red_flags.py): rule detection · Produces explainable suspicious-pattern indicators. · `backend/ml/red_flags.py`
- [Investigation Graph Builder](https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/graph/builder.py): graph projection · `backend/graph/builder.py`

### Local Data & Stores

- [SQLite Store](https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/database/db.py): primary persistence · Default offline store managed through SQLAlchemy. · `backend/database/db.py`
- [PostgreSQL Alert Archive](https://github.com/ashutoshmishra52/bitforensics/blob/main/backend/database/postgres_alerts.py): optional archive · `backend/database/postgres_alerts.py`
- **Sample Feeds**: offline datasets
- [Offline GeoIP Data](https://github.com/ashutoshmishra52/bitforensics/blob/main/data/geoip.csv): GeoIP source · `data/geoip.csv`
- [ML Artifacts](https://github.com/ashutoshmishra52/bitforensics/blob/main/data/models/isolation_forest.joblib): scikit-learn models · Feature scaler and isolation forest artifacts. · `data/models/isolation_forest.joblib`

### Launch & Distribution

- [Desktop Packaging](https://github.com/ashutoshmishra52/bitforensics/blob/main/packaging/desktop_app.py): desktop launcher · Wraps the local server and static UI for desktop distribution. · `packaging/desktop_app.py`
- [Runtime Entry](https://github.com/ashutoshmishra52/bitforensics/blob/main/run.py): server launcher · `run.py`
- [Node Dev Launcher](https://github.com/ashutoshmishra52/bitforensics/blob/main/scripts/dev.js): development launcher · `scripts/dev.js`

## Connections

- Static Dashboard → API Client Bundle: loads
- API Client Bundle → FastAPI Orchestrator: calls APIs
- Link Graph View → FastAPI Orchestrator: retrieves graph data
- FastAPI Orchestrator → Feed Parser: ingests feeds
- Sample Feeds → Feed Parser: source data
- Feed Parser → Domain Schemas: maps to
- Feed Parser → SQLite Store: stores normalized records
- FastAPI Orchestrator → GeoIP Acquisition: downloads GeoIP
- GeoIP Acquisition → Offline GeoIP Data: acquires
- SQLite Store → GeoIP Lookup: supplies IP records
- Offline GeoIP Data → GeoIP Lookup: lookup source
- GeoIP Lookup → Correlation Engine: enrichment context
- SQLite Store → Correlation Engine: transaction and network data
- Correlation Engine → Anomaly Analyzer: correlated evidence
- ML Artifacts → Anomaly Analyzer: scores with
- Anomaly Analyzer → Red Flags & Typologies: analysis signals
- Red Flags & Typologies → SQLite Store: ranked alerts
- SQLite Store → PostgreSQL Alert Archive: optional alert archive
- SQLite Store → Investigation Graph Builder: investigation entities
- Investigation Graph Builder → FastAPI Orchestrator: node/link results
- FastAPI Orchestrator → Static Dashboard: alerts, stats, exports
- Runtime Entry → FastAPI Orchestrator: starts
- Node Dev Launcher → FastAPI Orchestrator: starts development runtime
- Desktop Packaging → Runtime Entry: packages launcher
- Desktop Packaging → Static Dashboard: bundles local UI
