# prat-nath/civil-unrest-detection architecture

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

- Interactive diagram: https://gitdiagram.com/prat-nath/civil-unrest-detection
- Repository: https://github.com/prat-nath/civil-unrest-detection

## Overview

This project combines three social-media unrest experiments with a browser dashboard for exploring model scores and event signals. The main research workflow is the #FarmersProtest pipeline: prepare tweet and ACLED daily data, create weak labels, train and evaluate classifiers, extract event/place mentions, and forecast surges. The dashboard routes users to analysis, batch scoring, timeline exploration, threshold evaluation, and evidence views through a Python backend. Pipeline stages and capabilities are documented in the README; backend route details were not excerpted, so the browser-to-server link is unverified.

Main entry points: [`scripts/farmers_train_tweets.py`](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_train_tweets.py) (Tweet Classifiers), [`app/frontend/src/main.ts`](https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/main.ts) (View Router), [`app/frontend/src/api.ts`](https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/api.ts) (API Client), [`scripts/common.py`](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/common.py) (Shared Utilities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Dashboard"]
  node_router["View Router<br/>[main.ts]"]
  node_api_client["API Client<br/>[api.ts]"]
  node_analysis_view["Post Analysis<br/>[analyzer.ts]"]
  node_batch_view["Feed Scanner<br/>[batch.ts]"]
  node_explorer_view["Timeline Explorer<br/>[explorer.ts]"]
  node_lab_view["Threshold Lab<br/>[lab.ts]"]
  node_evidence_view["Evidence View<br/>[evidence.ts]"]
  node_home_view["Overview<br/>[home.ts]"]
  node_charting["Charts<br/>[charts.ts]"]
  node_terrain["3D Terrain<br/>[terrain.ts]"]
end

subgraph group_api["Serving"]
  node_backend["HTTP Backend<br/>[server.py]"]
end

subgraph group_farmers["FarmersProtest"]
  node_shared["Shared Utilities<br/>[common.py]"]
  node_farm_prepare["Data Preparation<br/>[farmers_prepare.py]"]
  node_farm_labels["Weak Labeling"]
  node_farm_train["Tweet Classifiers"]
  node_farm_extract["Event Extraction<br/>[farmers_extract.py]"]
  node_farm_transfer["Model Transfer"]
  node_farm_forecast["Surge Forecasting"]
  node_farm_threshold["Gold Thresholding"]
  node_farm_eval["Unseen Evaluation"]
  node_farm_report["Run Summary<br/>[farmers_summary.py]"]
end

subgraph group_acled["ACLED Text"]
  node_acled_preprocess["ACLED Preprocessing<br/>[preprocess.py]"]
  node_acled_baseline["Baseline Training<br/>[train_baseline.py]"]
  node_acled_transformer["Transformer Training"]
  node_acled_evaluate["Model Evaluation<br/>[evaluate.py]"]
end

subgraph group_gcut["G-CUT Signals"]
  node_social_aggregate["Tweet Aggregation"]
  node_social_panel["Daily Panel<br/>[social_panel.py]"]
  node_social_baseline["Signal Baselines"]
  node_social_sequence["Sequence Models"]
  node_social_report["Signal Summary<br/>[social_summary.py]"]
end

node_user(("Analyst"))

node_user -->|"navigates"| node_router
node_router -->|"routes to"| node_analysis_view
node_router -->|"routes to"| node_batch_view
node_router -->|"routes to"| node_explorer_view
node_router -->|"routes to"| node_lab_view
node_router -->|"routes to"| node_evidence_view
node_router -->|"routes to"| node_home_view
node_analysis_view -->|"requests analysis"| node_api_client
node_batch_view -->|"requests scoring"| node_api_client
node_explorer_view -->|"loads day data"| node_api_client
node_lab_view -->|"loads lab data"| node_api_client
node_evidence_view -->|"loads evidence"| node_api_client
node_home_view -->|"loads overview"| node_api_client
node_explorer_view -->|"renders terrain"| node_terrain
node_analysis_view -->|"renders charts"| node_charting
node_batch_view -->|"renders charts"| node_charting
node_api_client -.->|"HTTP requests"| node_backend
node_farm_prepare -->|"uses helpers"| node_shared
node_farm_labels -->|"uses helpers"| node_shared
node_farm_train -->|"uses helpers"| node_shared
node_farm_extract -->|"uses helpers"| node_shared
node_farm_prepare -->|"prepares inputs"| node_farm_labels
node_farm_labels -->|"provides labels"| node_farm_train
node_farm_train -->|"precedes extraction"| node_farm_extract
node_farm_train -->|"precedes transfer"| node_farm_transfer
node_farm_train -->|"provides signals"| node_farm_forecast
node_farm_train -->|"thresholds evaluated models"| node_farm_threshold
node_farm_transfer -->|"scores gold sample"| node_farm_eval
node_farm_train -->|"evaluates unseen tweets"| node_farm_eval
node_farm_train -->|"summarizes runs"| node_farm_report
node_acled_preprocess -->|"provides processed data"| node_acled_baseline
node_acled_preprocess -->|"provides processed data"| node_acled_transformer
node_acled_baseline -->|"evaluates model"| node_acled_evaluate
node_acled_transformer -->|"evaluates model"| node_acled_evaluate
node_social_aggregate -->|"builds panel"| node_social_panel
node_social_panel -->|"provides panel"| node_social_baseline
node_social_panel -->|"provides panel"| node_social_sequence
node_social_baseline -->|"summarized by"| node_social_report
node_social_sequence -->|"summarized by"| node_social_report

click node_router "https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/main.ts"
click node_api_client "https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/api.ts"
click node_analysis_view "https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/views/analyzer.ts"
click node_batch_view "https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/views/batch.ts"
click node_explorer_view "https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/views/explorer.ts"
click node_lab_view "https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/views/lab.ts"
click node_evidence_view "https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/views/evidence.ts"
click node_home_view "https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/views/home.ts"
click node_charting "https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/charts.ts"
click node_terrain "https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/terrain.ts"
click node_backend "https://github.com/prat-nath/civil-unrest-detection/blob/main/app/backend/server.py"
click node_shared "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/common.py"
click node_farm_prepare "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_prepare.py"
click node_farm_labels "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_label_weak.py"
click node_farm_train "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_train_tweets.py"
click node_farm_extract "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_extract.py"
click node_farm_transfer "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_transfer.py"
click node_farm_forecast "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_forecast.py"
click node_farm_threshold "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_gold_threshold.py"
click node_farm_eval "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_eval_unseen.py"
click node_farm_report "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_summary.py"
click node_acled_preprocess "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/preprocess.py"
click node_acled_baseline "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/train_baseline.py"
click node_acled_transformer "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/train_transformer.py"
click node_acled_evaluate "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/evaluate.py"
click node_social_aggregate "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/social_aggregate.py"
click node_social_panel "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/social_panel.py"
click node_social_baseline "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/social_train_baselines.py"
click node_social_sequence "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/social_train_sequence.py"
click node_social_report "https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/social_summary.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_router,node_api_client,node_analysis_view,node_batch_view,node_explorer_view,node_lab_view,node_evidence_view,node_home_view,node_charting,node_terrain toneBlue
class node_backend toneAmber
class node_shared,node_farm_prepare,node_farm_labels,node_farm_train,node_farm_extract,node_farm_transfer,node_farm_forecast,node_farm_threshold,node_farm_eval,node_farm_report toneMint
class node_acled_preprocess,node_acled_baseline,node_acled_transformer,node_acled_evaluate toneRose
class node_social_aggregate,node_social_panel,node_social_baseline,node_social_sequence,node_social_report,node_user toneIndigo
```

## Components

### Dashboard

- [View Router](https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/main.ts): `app/frontend/src/main.ts`
- [API Client](https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/api.ts): `app/frontend/src/api.ts`
- [Post Analysis](https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/views/analyzer.ts): `app/frontend/src/views/analyzer.ts`
- [Feed Scanner](https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/views/batch.ts): `app/frontend/src/views/batch.ts`
- [Timeline Explorer](https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/views/explorer.ts): `app/frontend/src/views/explorer.ts`
- [Threshold Lab](https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/views/lab.ts): `app/frontend/src/views/lab.ts`
- [Evidence View](https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/views/evidence.ts): `app/frontend/src/views/evidence.ts`
- [Overview](https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/views/home.ts): `app/frontend/src/views/home.ts`
- [Charts](https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/charts.ts): `app/frontend/src/charts.ts`
- [3D Terrain](https://github.com/prat-nath/civil-unrest-detection/blob/main/app/frontend/src/terrain.ts): `app/frontend/src/terrain.ts`

### Serving

- [HTTP Backend](https://github.com/prat-nath/civil-unrest-detection/blob/main/app/backend/server.py): `app/backend/server.py`

### FarmersProtest

- [Shared Utilities](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/common.py): `scripts/common.py`
- [Data Preparation](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_prepare.py): `scripts/farmers_prepare.py`
- [Weak Labeling](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_label_weak.py): `scripts/farmers_label_weak.py`
- [Tweet Classifiers](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_train_tweets.py): `scripts/farmers_train_tweets.py`
- [Event Extraction](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_extract.py): `scripts/farmers_extract.py`
- [Model Transfer](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_transfer.py): `scripts/farmers_transfer.py`
- [Surge Forecasting](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_forecast.py): `scripts/farmers_forecast.py`
- [Gold Thresholding](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_gold_threshold.py): `scripts/farmers_gold_threshold.py`
- [Unseen Evaluation](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_eval_unseen.py): `scripts/farmers_eval_unseen.py`
- [Run Summary](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/farmers_summary.py): `scripts/farmers_summary.py`

### ACLED Text

- [ACLED Preprocessing](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/preprocess.py): `scripts/preprocess.py`
- [Baseline Training](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/train_baseline.py): `scripts/train_baseline.py`
- [Transformer Training](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/train_transformer.py): `scripts/train_transformer.py`
- [Model Evaluation](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/evaluate.py): `scripts/evaluate.py`

### G-CUT Signals

- [Tweet Aggregation](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/social_aggregate.py): `scripts/social_aggregate.py`
- [Daily Panel](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/social_panel.py): `scripts/social_panel.py`
- [Signal Baselines](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/social_train_baselines.py): `scripts/social_train_baselines.py`
- [Sequence Models](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/social_train_sequence.py): `scripts/social_train_sequence.py`
- [Signal Summary](https://github.com/prat-nath/civil-unrest-detection/blob/main/scripts/social_summary.py): `scripts/social_summary.py`

### Other components

- **Analyst**

## Connections

- Analyst → View Router: navigates (evidence: `app/frontend/src/main.ts`)
- View Router → Post Analysis: routes to (evidence: `app/frontend/src/main.ts`)
- View Router → Feed Scanner: routes to (evidence: `app/frontend/src/main.ts`)
- View Router → Timeline Explorer: routes to (evidence: `app/frontend/src/main.ts`)
- View Router → Threshold Lab: routes to (evidence: `app/frontend/src/main.ts`)
- View Router → Evidence View: routes to (evidence: `app/frontend/src/main.ts`)
- View Router → Overview: routes to (evidence: `app/frontend/src/main.ts`)
- Post Analysis → API Client: requests analysis (evidence: `app/frontend/src/views/analyzer.ts`)
- Feed Scanner → API Client: requests scoring (evidence: `app/frontend/src/views/batch.ts`)
- Timeline Explorer → API Client: loads day data (evidence: `app/frontend/src/views/explorer.ts`)
- Threshold Lab → API Client: loads lab data (evidence: `app/frontend/src/views/lab.ts`)
- Evidence View → API Client: loads evidence (evidence: `app/frontend/src/views/evidence.ts`)
- Overview → API Client: loads overview (evidence: `app/frontend/src/views/home.ts`)
- Timeline Explorer → 3D Terrain: renders terrain (evidence: `app/frontend/src/views/explorer.ts`)
- Post Analysis → Charts: renders charts (evidence: `app/frontend/src/views/analyzer.ts`)
- Feed Scanner → Charts: renders charts (evidence: `app/frontend/src/views/batch.ts`)
- API Client → HTTP Backend: HTTP requests
- Data Preparation → Shared Utilities: uses helpers (evidence: `scripts/farmers_prepare.py`)
- Weak Labeling → Shared Utilities: uses helpers (evidence: `scripts/farmers_label_weak.py`)
- Tweet Classifiers → Shared Utilities: uses helpers (evidence: `scripts/farmers_train_tweets.py`)
- Event Extraction → Shared Utilities: uses helpers (evidence: `scripts/farmers_extract.py`)
- Data Preparation → Weak Labeling: prepares inputs (evidence: `README.md`)
- Weak Labeling → Tweet Classifiers: provides labels (evidence: `README.md`)
- Tweet Classifiers → Event Extraction: precedes extraction (evidence: `README.md`)
- Tweet Classifiers → Model Transfer: precedes transfer (evidence: `README.md`)
- Tweet Classifiers → Surge Forecasting: provides signals (evidence: `README.md`)
- Tweet Classifiers → Gold Thresholding: thresholds evaluated models (evidence: `README.md`)
- Model Transfer → Unseen Evaluation: scores gold sample (evidence: `README.md`)
- Tweet Classifiers → Unseen Evaluation: evaluates unseen tweets (evidence: `README.md`)
- Tweet Classifiers → Run Summary: summarizes runs (evidence: `README.md`)
- ACLED Preprocessing → Baseline Training: provides processed data (evidence: `README.md`)
- ACLED Preprocessing → Transformer Training: provides processed data (evidence: `README.md`)
- Baseline Training → Model Evaluation: evaluates model (evidence: `README.md`)
- Transformer Training → Model Evaluation: evaluates model (evidence: `README.md`)
- Tweet Aggregation → Daily Panel: builds panel (evidence: `README.md`)
- Daily Panel → Signal Baselines: provides panel (evidence: `README.md`)
- Daily Panel → Sequence Models: provides panel (evidence: `README.md`)
- Signal Baselines → Signal Summary: summarized by (evidence: `README.md`)
- Sequence Models → Signal Summary: summarized by (evidence: `README.md`)
