# anesthesiaprovider/narrativelens-ai- architecture

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

- Interactive diagram: https://gitdiagram.com/anesthesiaprovider/narrativelens-ai-
- Repository: https://github.com/anesthesiaprovider/narrativelens-ai-

## Overview

NarrativeLens AI is a moderation and OSINT workbench for detecting harmful content, investigating narratives, and analyzing civil-unrest and coordination signals. The principal workflow is to submit or collect content, analyze it with classification and enrichment, then explore results in the dashboard. The README also documents scraping, multimodal OCR, explainability, and counter-narrative capabilities. Evidence is partial: unsampled APIs and services are represented where the README establishes a capability, but uncertain implementation links are omitted.

Main entry points: [`backend/app/main.py`](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/main.py) (API Gateway), [`backend/app/core/database.py`](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/core/database.py) (Relational Database), [`backend/app/api/ingestion.py`](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/api/ingestion.py) (Ingestion API), [`backend/app/ml/enrichment/enrichment_pipeline.py`](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/ml/enrichment/enrichment_pipeline.py) (Enrichment Orchestrator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workbench["Moderator Workbench"]
  node_dashboard["React Dashboard<br/>[App.tsx]"]
  node_analysis_pages["Analysis Views"]
  node_investigation_views["Investigation Views"]
end

subgraph group_collection["Content Collection"]
  node_ingestion_api["Ingestion API<br/>[ingestion.py]"]
  node_scraper_service["Narrative Scraper"]
  node_scraper_router["Platform Scraper Router<br/>[router.py]"]
  node_scraper_base["Scraped Content Model<br/>[base.py]"]
  node_ocr["Meme OCR<br/>[ocr_service.py]"]
end

subgraph group_analysis["Content Analysis"]
  node_analysis_api["Analysis API<br/>[analysis.py]"]
  node_detector["Hate Detection"]
  node_models["Classifier Models<br/>[model_manager.py]"]
  node_enrichment["Enrichment Orchestrator"]
  node_target_detector["Target Detection<br/>[target_detector.py]"]
  node_harm_classifier["Harm Classification<br/>[harm_classifier.py]"]
  node_severity_engine["Severity Scoring<br/>[severity_engine.py]"]
end

subgraph group_investigation["Investigation Intelligence"]
  node_investigation_api["Investigation API<br/>[investigations.py]"]
  node_narrative_api["Narrative API<br/>[narratives.py]"]
  node_civil_api["Civil Unrest API<br/>[civil_unrest.py]"]
  node_coordination_api["Coordination API<br/>[coordination.py]"]
  node_civil_service["Civil Unrest Analysis"]
  node_coordination["Coordination Detection<br/>[detector.py]"]
end

subgraph group_platform["Application Platform"]
  node_api["API Gateway<br/>[main.py]"]
  node_database[("Relational Database<br/>[database.py]")]
  node_db_models["Domain Records<br/>[models.py]"]
  node_security["Input Security<br/>[security.py]"]
end

node_moderator(("Moderator"))

node_moderator -->|"uses"| node_dashboard
node_dashboard -->|"routes to"| node_analysis_pages
node_dashboard -->|"routes to"| node_investigation_views
node_analysis_pages -.->|"requests analysis"| node_api
node_investigation_views -.->|"requests investigation"| node_api
node_api -->|"initializes"| node_database
node_api -->|"mounts routes"| node_analysis_api
node_api -->|"mounts routes"| node_ingestion_api
node_ingestion_api -->|"sanitizes input"| node_security
node_ingestion_api -->|"persists documents"| node_db_models
node_ingestion_api -->|"uses scraping"| node_scraper_service
node_scraper_router -->|"returns content"| node_scraper_base
node_analysis_api -.->|"runs detection"| node_detector
node_detector -->|"predicts content"| node_models
node_models -->|"enriches predictions"| node_enrichment
node_enrichment -->|"detects targets"| node_target_detector
node_enrichment -->|"classifies harm"| node_harm_classifier
node_enrichment -->|"scores severity"| node_severity_engine
node_investigation_api -.->|"uses sessions"| node_database
node_narrative_api -.->|"uses sessions"| node_database
node_civil_api -.->|"analyzes events"| node_civil_service
node_coordination_api -.->|"detects coordination"| node_coordination
node_civil_service -.->|"stores analysis"| node_database
node_ocr -.->|"supplies extracted text"| node_models
node_scraper_service -->|"classifies results"| node_models
node_database -->|"maps records"| node_db_models

click node_dashboard "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/frontend/src/App.tsx"
click node_analysis_pages "https://github.com/anesthesiaprovider/narrativelens-ai-/tree/master/frontend/src/pages"
click node_investigation_views "https://github.com/anesthesiaprovider/narrativelens-ai-/tree/master/frontend/src/pages"
click node_api "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/main.py"
click node_analysis_api "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/api/analysis.py"
click node_ingestion_api "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/api/ingestion.py"
click node_investigation_api "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/api/investigations.py"
click node_narrative_api "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/api/narratives.py"
click node_civil_api "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/api/civil_unrest.py"
click node_coordination_api "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/api/coordination.py"
click node_scraper_service "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/services/narrative_scraper_service.py"
click node_scraper_router "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/services/scrapers/router.py"
click node_scraper_base "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/services/scrapers/base.py"
click node_ocr "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/services/ocr_service.py"
click node_detector "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/services/comment_hate_detector_service.py"
click node_models "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/ml/model_manager.py"
click node_enrichment "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/ml/enrichment/enrichment_pipeline.py"
click node_target_detector "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/ml/enrichment/target_detector.py"
click node_harm_classifier "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/ml/enrichment/harm_classifier.py"
click node_severity_engine "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/ml/enrichment/severity_engine.py"
click node_civil_service "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/services/civil_unrest_service.py"
click node_coordination "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/coordination/detector.py"
click node_database "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/core/database.py"
click node_db_models "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/db/models.py"
click node_security "https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/core/security.py"

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_dashboard,node_analysis_pages,node_investigation_views toneBlue
class node_ingestion_api,node_scraper_service,node_scraper_router,node_scraper_base,node_ocr toneAmber
class node_analysis_api,node_detector,node_models,node_enrichment,node_target_detector,node_harm_classifier,node_severity_engine toneMint
class node_investigation_api,node_narrative_api,node_civil_api,node_coordination_api,node_civil_service,node_coordination toneRose
class node_api,node_database,node_db_models,node_security,node_moderator toneIndigo
```

## Components

### Moderator Workbench

- [React Dashboard](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Analysis Views](https://github.com/anesthesiaprovider/narrativelens-ai-/tree/master/frontend/src/pages): `frontend/src/pages`
- [Investigation Views](https://github.com/anesthesiaprovider/narrativelens-ai-/tree/master/frontend/src/pages): `frontend/src/pages`

### Content Collection

- [Ingestion API](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/api/ingestion.py): `backend/app/api/ingestion.py`
- [Narrative Scraper](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/services/narrative_scraper_service.py): `backend/app/services/narrative_scraper_service.py`
- [Platform Scraper Router](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/services/scrapers/router.py): `backend/app/services/scrapers/router.py`
- [Scraped Content Model](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/services/scrapers/base.py): `backend/app/services/scrapers/base.py`
- [Meme OCR](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/services/ocr_service.py): `backend/app/services/ocr_service.py`

### Content Analysis

- [Analysis API](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/api/analysis.py): `backend/app/api/analysis.py`
- [Hate Detection](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/services/comment_hate_detector_service.py): `backend/app/services/comment_hate_detector_service.py`
- [Classifier Models](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/ml/model_manager.py): `backend/app/ml/model_manager.py`
- [Enrichment Orchestrator](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/ml/enrichment/enrichment_pipeline.py): `backend/app/ml/enrichment/enrichment_pipeline.py`
- [Target Detection](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/ml/enrichment/target_detector.py): `backend/app/ml/enrichment/target_detector.py`
- [Harm Classification](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/ml/enrichment/harm_classifier.py): `backend/app/ml/enrichment/harm_classifier.py`
- [Severity Scoring](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/ml/enrichment/severity_engine.py): `backend/app/ml/enrichment/severity_engine.py`

### Investigation Intelligence

- [Investigation API](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/api/investigations.py): `backend/app/api/investigations.py`
- [Narrative API](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/api/narratives.py): `backend/app/api/narratives.py`
- [Civil Unrest API](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/api/civil_unrest.py): `backend/app/api/civil_unrest.py`
- [Coordination API](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/api/coordination.py): `backend/app/api/coordination.py`
- [Civil Unrest Analysis](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/services/civil_unrest_service.py): `backend/app/services/civil_unrest_service.py`
- [Coordination Detection](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/coordination/detector.py): `backend/app/coordination/detector.py`

### Application Platform

- [API Gateway](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/main.py): `backend/app/main.py`
- [Relational Database](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/core/database.py): `backend/app/core/database.py`
- [Domain Records](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/db/models.py): `backend/app/db/models.py`
- [Input Security](https://github.com/anesthesiaprovider/narrativelens-ai-/blob/master/backend/app/core/security.py): `backend/app/core/security.py`

### Other components

- **Moderator**

## Connections

- Moderator → React Dashboard: uses (evidence: `README.md`)
- React Dashboard → Analysis Views: routes to (evidence: `frontend/src/App.tsx`)
- React Dashboard → Investigation Views: routes to (evidence: `frontend/src/App.tsx`)
- Analysis Views → API Gateway: requests analysis
- Investigation Views → API Gateway: requests investigation
- API Gateway → Relational Database: initializes (evidence: `backend/app/main.py`)
- API Gateway → Analysis API: mounts routes (evidence: `backend/app/main.py`)
- API Gateway → Ingestion API: mounts routes
- Ingestion API → Input Security: sanitizes input (evidence: `backend/app/api/ingestion.py`)
- Ingestion API → Domain Records: persists documents (evidence: `backend/app/api/ingestion.py`)
- Ingestion API → Narrative Scraper: uses scraping (evidence: `backend/app/api/ingestion.py`)
- Platform Scraper Router → Scraped Content Model: returns content (evidence: `backend/app/services/scrapers/router.py`)
- Analysis API → Hate Detection: runs detection
- Hate Detection → Classifier Models: predicts content (evidence: `backend/app/services/comment_hate_detector_service.py`)
- Classifier Models → Enrichment Orchestrator: enriches predictions (evidence: `backend/app/ml/model_manager.py`)
- Enrichment Orchestrator → Target Detection: detects targets (evidence: `backend/app/ml/enrichment/enrichment_pipeline.py`)
- Enrichment Orchestrator → Harm Classification: classifies harm (evidence: `backend/app/ml/enrichment/enrichment_pipeline.py`)
- Enrichment Orchestrator → Severity Scoring: scores severity (evidence: `backend/app/ml/enrichment/enrichment_pipeline.py`)
- Investigation API → Relational Database: uses sessions
- Narrative API → Relational Database: uses sessions
- Civil Unrest API → Civil Unrest Analysis: analyzes events
- Coordination API → Coordination Detection: detects coordination
- Civil Unrest Analysis → Relational Database: stores analysis
- Meme OCR → Classifier Models: supplies extracted text
- Narrative Scraper → Classifier Models: classifies results (evidence: `backend/app/services/narrative_scraper_service.py`)
- Relational Database → Domain Records: maps records (evidence: `backend/app/db/models.py`)
