# hliran207/distress-detector architecture

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

- Interactive diagram: https://gitdiagram.com/hliran207/distress-detector
- Repository: https://github.com/hliran207/distress-detector

## Overview

Distress-Detector collects and labels Reddit posts, stores them in MongoDB, serves browsing, search, statistics and prediction through a FastAPI API, and presents these capabilities in a React dashboard. The principal workflow runs from Reddit collection through post parsing and persistence to API-backed browsing or distress classification. The repository also includes PullPush collection, Telegram scanning, analytics and Kafka/WebSocket result broadcasting. Some subsystem links are based on README or SOURCE INDEX references; unsampled implementations are not assumed to have specific call paths.

Main entry points: [`frontend/src/lib/api.ts`](https://github.com/hliran207/distress-detector/blob/main/frontend/src/lib/api.ts) (API client), [`frontend/src/main.tsx`](https://github.com/hliran207/distress-detector/blob/main/frontend/src/main.tsx) (Dashboard routes), [`app/controllers/reddit_scraper_controller.py`](https://github.com/hliran207/distress-detector/blob/main/app/controllers/reddit_scraper_controller.py) (Reddit scraper), [`services/api/main.py`](https://github.com/hliran207/distress-detector/blob/main/services/api/main.py) (FastAPI app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_collect["Post collection"]
  node_reddit_scraper["Reddit scraper"]
  node_chrome["Chrome driver<br/>[chrome_driver.py]"]
  node_parser["Post parser<br/>[shreddit_parser.py]"]
  node_pullpush_collector["PullPush collector"]
end

subgraph group_store["Persistence"]
  node_post_model["Post model<br/>[post.py]"]
  node_mongo_repo["Mongo repository<br/>[mongo_posts.py]"]
  node_mongo[("MongoDB posts<br/>[mongo_config.py]")]
end

subgraph group_backend["API and inference"]
  node_api_app["FastAPI app<br/>[main.py]"]
  node_api_deps["API dependencies<br/>[deps.py]"]
  node_posts_api["Posts API<br/>[posts.py]"]
  node_stats_api["Stats API<br/>[stats.py]"]
  node_predict_api["Prediction API<br/>[predict.py]"]
  node_ensemble["Distress ensemble<br/>[ensemble.py]"]
  node_preprocess["Text preprocessing<br/>[preprocess.py]"]
  node_model_service["Model service<br/>[main.py]"]
  node_preprocess_service["Preprocessing service<br/>[main.py]"]
end

subgraph group_frontend["Dashboard"]
  node_frontend_routes["Dashboard routes<br/>[main.tsx]"]
  node_posts_page["Post browsing<br/>[PostsPage.tsx]"]
  node_search_page["Post search<br/>[SearchPage.tsx]"]
  node_detect_page["Distress detection<br/>[DetectPage.tsx]"]
  node_telegram_page["Telegram scanning<br/>[TelegramPage.tsx]"]
  node_dashboard_page["Analytics dashboard<br/>[DashboardPage.tsx]"]
  node_charts["EDA charts<br/>[EdaCharts.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_integrations["External integrations"]
  node_pullpush_client["PullPush client<br/>[pullpush_client.py]"]
  node_telegram_bot["Telegram bot<br/>[main.py]"]
  node_telegram_service["Telegram service"]
  node_reddit(("Reddit"))
  node_pullpush(("PullPush service"))
  node_telegram(("Telegram"))
  node_kafka["Kafka results"]
end

node_operator(("Operator"))
node_browser_user(("Dashboard user"))

node_operator -->|"starts scrape"| node_reddit_scraper
node_reddit_scraper -->|"creates driver"| node_chrome
node_reddit_scraper -->|"parses elements"| node_parser
node_reddit_scraper -->|"inserts posts"| node_mongo_repo
node_parser -->|"creates posts"| node_post_model
node_pullpush_collector -->|"fetches submissions"| node_pullpush_client
node_pullpush_client -->|"requests submissions"| node_pullpush
node_pullpush_collector -->|"bulk inserts"| node_mongo_repo
node_mongo_repo -->|"serializes posts"| node_post_model
node_mongo_repo -->|"reads and writes"| node_mongo
node_api_app -->|"registers router"| node_posts_api
node_api_app -->|"registers router"| node_stats_api
node_api_app -->|"registers router"| node_predict_api
node_posts_api -->|"uses dependencies"| node_api_deps
node_stats_api -->|"uses dependencies"| node_api_deps
node_predict_api -->|"uses dependencies"| node_api_deps
node_api_deps -->|"provides collections"| node_mongo
node_predict_api -->|"runs prediction"| node_ensemble
node_ensemble -->|"preprocesses text"| node_preprocess
node_model_service -->|"uses model"| node_ensemble
node_preprocess_service -->|"uses preprocessing"| node_preprocess
node_telegram_bot -->|"delegates service"| node_telegram_service
node_telegram_service -.->|"connects to"| node_telegram
node_browser_user -->|"opens dashboard"| node_frontend_routes
node_frontend_routes -->|"routes to"| node_posts_page
node_frontend_routes -->|"routes to"| node_search_page
node_frontend_routes -->|"routes to"| node_detect_page
node_frontend_routes -->|"routes to"| node_telegram_page
node_frontend_routes -->|"routes to"| node_dashboard_page
node_posts_page -->|"requests post data"| node_api_client
node_search_page -->|"requests search"| node_api_client
node_detect_page -->|"requests prediction"| node_api_client
node_telegram_page -->|"requests Telegram scan"| node_api_client
node_dashboard_page -->|"renders charts"| node_charts
node_api_client -->|"calls posts routes"| node_posts_api
node_api_client -->|"calls stats routes"| node_stats_api
node_api_client -->|"calls prediction route"| node_predict_api
node_reddit_scraper -->|"scrapes posts"| node_reddit
node_api_app -->|"consumes results"| node_kafka

click node_reddit_scraper "https://github.com/hliran207/distress-detector/blob/main/app/controllers/reddit_scraper_controller.py"
click node_chrome "https://github.com/hliran207/distress-detector/blob/main/app/services/chrome_driver.py"
click node_parser "https://github.com/hliran207/distress-detector/blob/main/app/services/shreddit_parser.py"
click node_pullpush_collector "https://github.com/hliran207/distress-detector/blob/main/app/controllers/pullpush_final_stretch_controller.py"
click node_pullpush_client "https://github.com/hliran207/distress-detector/blob/main/app/services/pullpush_client.py"
click node_post_model "https://github.com/hliran207/distress-detector/blob/main/app/models/post.py"
click node_mongo_repo "https://github.com/hliran207/distress-detector/blob/main/app/repositories/mongo_posts.py"
click node_mongo "https://github.com/hliran207/distress-detector/blob/main/app/mongo_config.py"
click node_api_app "https://github.com/hliran207/distress-detector/blob/main/services/api/main.py"
click node_api_deps "https://github.com/hliran207/distress-detector/blob/main/services/api/deps.py"
click node_posts_api "https://github.com/hliran207/distress-detector/blob/main/services/api/routers/posts.py"
click node_stats_api "https://github.com/hliran207/distress-detector/blob/main/services/api/routers/stats.py"
click node_predict_api "https://github.com/hliran207/distress-detector/blob/main/services/api/routers/predict.py"
click node_ensemble "https://github.com/hliran207/distress-detector/blob/main/packages/distress_ml/distress_ml/ensemble.py"
click node_preprocess "https://github.com/hliran207/distress-detector/blob/main/packages/distress_ml/distress_ml/preprocess.py"
click node_model_service "https://github.com/hliran207/distress-detector/blob/main/services/model/main.py"
click node_preprocess_service "https://github.com/hliran207/distress-detector/blob/main/services/preprocessing/main.py"
click node_telegram_bot "https://github.com/hliran207/distress-detector/blob/main/services/telegram-bot/main.py"
click node_telegram_service "https://github.com/hliran207/distress-detector/blob/main/services/telegram-bot/telegram_service.py"
click node_frontend_routes "https://github.com/hliran207/distress-detector/blob/main/frontend/src/main.tsx"
click node_posts_page "https://github.com/hliran207/distress-detector/blob/main/frontend/src/pages/PostsPage.tsx"
click node_search_page "https://github.com/hliran207/distress-detector/blob/main/frontend/src/pages/SearchPage.tsx"
click node_detect_page "https://github.com/hliran207/distress-detector/blob/main/frontend/src/pages/DetectPage.tsx"
click node_telegram_page "https://github.com/hliran207/distress-detector/blob/main/frontend/src/pages/TelegramPage.tsx"
click node_dashboard_page "https://github.com/hliran207/distress-detector/blob/main/frontend/src/pages/DashboardPage.tsx"
click node_charts "https://github.com/hliran207/distress-detector/blob/main/frontend/src/components/EdaCharts.tsx"
click node_api_client "https://github.com/hliran207/distress-detector/blob/main/frontend/src/lib/api.ts"

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_reddit_scraper,node_chrome,node_parser,node_pullpush_collector,node_browser_user toneBlue
class node_post_model,node_mongo_repo,node_mongo toneAmber
class node_api_app,node_api_deps,node_posts_api,node_stats_api,node_predict_api,node_ensemble,node_preprocess,node_model_service,node_preprocess_service toneMint
class node_frontend_routes,node_posts_page,node_search_page,node_detect_page,node_telegram_page,node_dashboard_page,node_charts,node_api_client toneRose
class node_pullpush_client,node_telegram_bot,node_telegram_service,node_reddit,node_pullpush,node_telegram,node_kafka,node_operator toneIndigo
```

## Components

### Post collection

- [Reddit scraper](https://github.com/hliran207/distress-detector/blob/main/app/controllers/reddit_scraper_controller.py): `app/controllers/reddit_scraper_controller.py`
- [Chrome driver](https://github.com/hliran207/distress-detector/blob/main/app/services/chrome_driver.py): `app/services/chrome_driver.py`
- [Post parser](https://github.com/hliran207/distress-detector/blob/main/app/services/shreddit_parser.py): `app/services/shreddit_parser.py`
- [PullPush collector](https://github.com/hliran207/distress-detector/blob/main/app/controllers/pullpush_final_stretch_controller.py): `app/controllers/pullpush_final_stretch_controller.py`

### Persistence

- [Post model](https://github.com/hliran207/distress-detector/blob/main/app/models/post.py): `app/models/post.py`
- [Mongo repository](https://github.com/hliran207/distress-detector/blob/main/app/repositories/mongo_posts.py): `app/repositories/mongo_posts.py`
- [MongoDB posts](https://github.com/hliran207/distress-detector/blob/main/app/mongo_config.py): `app/mongo_config.py`

### API and inference

- [FastAPI app](https://github.com/hliran207/distress-detector/blob/main/services/api/main.py): `services/api/main.py`
- [API dependencies](https://github.com/hliran207/distress-detector/blob/main/services/api/deps.py): `services/api/deps.py`
- [Posts API](https://github.com/hliran207/distress-detector/blob/main/services/api/routers/posts.py): `services/api/routers/posts.py`
- [Stats API](https://github.com/hliran207/distress-detector/blob/main/services/api/routers/stats.py): `services/api/routers/stats.py`
- [Prediction API](https://github.com/hliran207/distress-detector/blob/main/services/api/routers/predict.py): `services/api/routers/predict.py`
- [Distress ensemble](https://github.com/hliran207/distress-detector/blob/main/packages/distress_ml/distress_ml/ensemble.py): `packages/distress_ml/distress_ml/ensemble.py`
- [Text preprocessing](https://github.com/hliran207/distress-detector/blob/main/packages/distress_ml/distress_ml/preprocess.py): `packages/distress_ml/distress_ml/preprocess.py`
- [Model service](https://github.com/hliran207/distress-detector/blob/main/services/model/main.py): `services/model/main.py`
- [Preprocessing service](https://github.com/hliran207/distress-detector/blob/main/services/preprocessing/main.py): `services/preprocessing/main.py`

### Dashboard

- [Dashboard routes](https://github.com/hliran207/distress-detector/blob/main/frontend/src/main.tsx): `frontend/src/main.tsx`
- [Post browsing](https://github.com/hliran207/distress-detector/blob/main/frontend/src/pages/PostsPage.tsx): `frontend/src/pages/PostsPage.tsx`
- [Post search](https://github.com/hliran207/distress-detector/blob/main/frontend/src/pages/SearchPage.tsx): `frontend/src/pages/SearchPage.tsx`
- [Distress detection](https://github.com/hliran207/distress-detector/blob/main/frontend/src/pages/DetectPage.tsx): `frontend/src/pages/DetectPage.tsx`
- [Telegram scanning](https://github.com/hliran207/distress-detector/blob/main/frontend/src/pages/TelegramPage.tsx): `frontend/src/pages/TelegramPage.tsx`
- [Analytics dashboard](https://github.com/hliran207/distress-detector/blob/main/frontend/src/pages/DashboardPage.tsx): `frontend/src/pages/DashboardPage.tsx`
- [EDA charts](https://github.com/hliran207/distress-detector/blob/main/frontend/src/components/EdaCharts.tsx): `frontend/src/components/EdaCharts.tsx`
- [API client](https://github.com/hliran207/distress-detector/blob/main/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`

### External integrations

- [PullPush client](https://github.com/hliran207/distress-detector/blob/main/app/services/pullpush_client.py): `app/services/pullpush_client.py`
- [Telegram bot](https://github.com/hliran207/distress-detector/blob/main/services/telegram-bot/main.py): `services/telegram-bot/main.py`
- [Telegram service](https://github.com/hliran207/distress-detector/blob/main/services/telegram-bot/telegram_service.py): `services/telegram-bot/telegram_service.py`
- **Reddit**
- **PullPush service**
- **Telegram**
- **Kafka results**

### Other components

- **Operator**
- **Dashboard user**

## Connections

- Operator → Reddit scraper: starts scrape
- Reddit scraper → Chrome driver: creates driver (evidence: `app/controllers/reddit_scraper_controller.py`)
- Reddit scraper → Post parser: parses elements (evidence: `app/controllers/reddit_scraper_controller.py`)
- Reddit scraper → Mongo repository: inserts posts (evidence: `app/controllers/reddit_scraper_controller.py`)
- Post parser → Post model: creates posts (evidence: `app/services/shreddit_parser.py`)
- PullPush collector → PullPush client: fetches submissions (evidence: `app/controllers/pullpush_final_stretch_controller.py`)
- PullPush client → PullPush service: requests submissions (evidence: `app/services/pullpush_client.py`)
- PullPush collector → Mongo repository: bulk inserts (evidence: `app/controllers/pullpush_final_stretch_controller.py`)
- Mongo repository → Post model: serializes posts (evidence: `app/repositories/mongo_posts.py`)
- Mongo repository → MongoDB posts: reads and writes
- FastAPI app → Posts API: registers router (evidence: `services/api/main.py`)
- FastAPI app → Stats API: registers router (evidence: `services/api/main.py`)
- FastAPI app → Prediction API: registers router (evidence: `services/api/main.py`)
- Posts API → API dependencies: uses dependencies (evidence: `services/api/routers/posts.py`)
- Stats API → API dependencies: uses dependencies (evidence: `services/api/routers/stats.py`)
- Prediction API → API dependencies: uses dependencies (evidence: `services/api/routers/predict.py`)
- API dependencies → MongoDB posts: provides collections (evidence: `services/api/deps.py`)
- Prediction API → Distress ensemble: runs prediction (evidence: `services/api/routers/predict.py`)
- Distress ensemble → Text preprocessing: preprocesses text (evidence: `packages/distress_ml/distress_ml/ensemble.py`)
- Model service → Distress ensemble: uses model (evidence: `services/model/main.py`)
- Preprocessing service → Text preprocessing: uses preprocessing (evidence: `services/preprocessing/main.py`)
- Telegram bot → Telegram service: delegates service (evidence: `services/telegram-bot/main.py`)
- Telegram service → Telegram: connects to
- Dashboard user → Dashboard routes: opens dashboard (evidence: `frontend/src/main.tsx`)
- Dashboard routes → Post browsing: routes to (evidence: `frontend/src/main.tsx`)
- Dashboard routes → Post search: routes to (evidence: `frontend/src/main.tsx`)
- Dashboard routes → Distress detection: routes to (evidence: `frontend/src/main.tsx`)
- Dashboard routes → Telegram scanning: routes to (evidence: `frontend/src/main.tsx`)
- Dashboard routes → Analytics dashboard: routes to (evidence: `frontend/src/main.tsx`)
- Post browsing → API client: requests post data (evidence: `frontend/src/pages/PostsPage.tsx`)
- Post search → API client: requests search (evidence: `frontend/src/pages/SearchPage.tsx`)
- Distress detection → API client: requests prediction (evidence: `frontend/src/pages/DetectPage.tsx`)
- Telegram scanning → API client: requests Telegram scan (evidence: `frontend/src/pages/TelegramPage.tsx`)
- Analytics dashboard → EDA charts: renders charts (evidence: `frontend/src/pages/DashboardPage.tsx`)
- API client → Posts API: calls posts routes (evidence: `frontend/src/lib/api.ts`)
- API client → Stats API: calls stats routes (evidence: `frontend/src/lib/api.ts`)
- API client → Prediction API: calls prediction route (evidence: `frontend/src/lib/api.ts`)
- Reddit scraper → Reddit: scrapes posts
- FastAPI app → Kafka results: consumes results (evidence: `services/api/main.py`)
