# sothunly-alt/inbound_news_bot architecture

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

- Interactive diagram: https://gitdiagram.com/sothunly-alt/inbound_news_bot
- Repository: https://github.com/sothunly-alt/inbound_news_bot

## Overview

Inbound Reports has two deliberately separate news pipelines: a curated RSS-to-Telegram digest bot and an API/RSS ingestion pipeline that populates the website’s Supabase story feed. Telegram readers receive scheduled, urgent, or requested posts; website readers browse and use story discovery and analysis features. The site also exposes accounts and paid membership flows. The graph preserves those documented product branches, but source excerpts do not establish most web-client/API call paths, so those links are omitted. Several web capabilities are represented from the repository tree rather than inspected implementation.

Main entry points: [`newsbot/bot.py`](https://github.com/sothunly-alt/inbound_news_bot/blob/main/newsbot/bot.py) (Bot handlers), [`news_bot.py`](https://github.com/sothunly-alt/inbound_news_bot/blob/main/news_bot.py) (Bot scheduler), [`workers/ingest_apis.py`](https://github.com/sothunly-alt/inbound_news_bot/blob/main/workers/ingest_apis.py) (API and RSS collectors), [`supabase/functions/create-payway-transaction/index.ts`](https://github.com/sothunly-alt/inbound_news_bot/blob/main/supabase/functions/create-payway-transaction/index.ts) (PayWay transactions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_telegram["Telegram publishing"]
  node_news_bot_entry["Bot scheduler<br/>[news_bot.py]"]
  node_bot_handlers["Bot handlers<br/>[bot.py]"]
  node_bot_config["Bot configuration<br/>[config.py]"]
  node_rss_fetch["Curated RSS fetch<br/>[feeds.py]"]
  node_story_rewrite["Story rewriting<br/>[ai.py]"]
  node_bot_state[("Subscriber and post state<br/>[state.py]")]
  node_mirror_queue["Cross-language mirror<br/>[mirror.py]"]
end

subgraph group_shared_ai["Shared AI services"]
  node_ai_router["Provider fallback router<br/>[ai_router.py]"]
  node_ai_providers{{"AI providers"}}
end

subgraph group_website_ingest["Website ingestion"]
  node_website_workers["API and RSS collectors<br/>[ingest_apis.py]"]
  node_article_store[("Staged articles")]
  node_dedup["Deduplication and matching<br/>[dedup.py]"]
  node_worker_db["Worker database client<br/>[db.py]"]
end

subgraph group_website_product["News website"]
  node_website["Next.js news site<br/>[page.tsx]"]
  node_story_experience["Story and topic pages<br/>[page.tsx]"]
  node_discovery["Search and comparison<br/>[route.ts]"]
  node_analysis_tools["Editorial analysis tools<br/>[route.ts]"]
  node_accounts["Account and authentication<br/>[page.tsx]"]
end

subgraph group_membership["Membership and payments"]
  node_membership_ui["Membership experience<br/>[PaymentModal.tsx]"]
  node_membership_api["Membership endpoints<br/>[route.ts]"]
  node_payway_functions["PayWay transactions<br/>[index.ts]"]
  node_payway_helpers["PayWay helpers<br/>[payway.ts]"]
  node_supabase_functions_db["Supabase function client<br/>[supabase.ts]"]
end

node_reader(("News readers"))
node_telegram_users(("Telegram subscribers"))
node_story_store[("Website stories")]
node_payway{{"ABA PayWay"}}
node_supabase[("Supabase")]

node_telegram_users -->|"command input"| node_news_bot_entry
node_news_bot_entry -->|"registers handlers"| node_bot_handlers
node_news_bot_entry -->|"loads settings"| node_bot_config
node_news_bot_entry -->|"schedules fetches"| node_rss_fetch
node_news_bot_entry -->|"schedules digests"| node_bot_handlers
node_bot_handlers -->|"fetches stories"| node_rss_fetch
node_rss_fetch -->|"clusters for rewrite"| node_story_rewrite
node_story_rewrite -->|"routes prompts"| node_ai_router
node_ai_router -->|"calls providers"| node_ai_providers
node_bot_handlers -->|"tracks posts"| node_bot_state
node_bot_handlers -->|"publishes mirror items"| node_mirror_queue
node_bot_handlers -->|"broadcasts posts"| node_telegram_users
node_website_workers -->|"upserts articles"| node_article_store
node_website_workers -->|"gets database client"| node_worker_db
node_website_workers -->|"passes articles"| node_dedup
node_dedup -->|"writes stories"| node_story_store
node_website -->|"reads story feed"| node_story_store
node_reader -->|"browses news"| node_website
node_reader -.->|"opens stories"| node_story_experience
node_reader -.->|"searches and compares"| node_discovery
node_reader -.->|"uses analysis"| node_analysis_tools
node_reader -.->|"manages account"| node_accounts
node_reader -.->|"purchases membership"| node_membership_ui
node_membership_ui -.->|"starts checkout"| node_membership_api
node_membership_api -.->|"initiates payment"| node_payway_functions
node_payway_functions -->|"uses payment helpers"| node_payway_helpers
node_payway_functions -->|"uses admin client"| node_supabase_functions_db
node_payway_helpers -.->|"requests transactions"| node_payway
node_supabase_functions_db -->|"connects client"| node_supabase

click node_news_bot_entry "https://github.com/sothunly-alt/inbound_news_bot/blob/main/news_bot.py"
click node_bot_handlers "https://github.com/sothunly-alt/inbound_news_bot/blob/main/newsbot/bot.py"
click node_bot_config "https://github.com/sothunly-alt/inbound_news_bot/blob/main/newsbot/config.py"
click node_rss_fetch "https://github.com/sothunly-alt/inbound_news_bot/blob/main/newsbot/feeds.py"
click node_story_rewrite "https://github.com/sothunly-alt/inbound_news_bot/blob/main/newsbot/ai.py"
click node_bot_state "https://github.com/sothunly-alt/inbound_news_bot/blob/main/newsbot/state.py"
click node_mirror_queue "https://github.com/sothunly-alt/inbound_news_bot/blob/main/newsbot/mirror.py"
click node_ai_router "https://github.com/sothunly-alt/inbound_news_bot/blob/main/shared/ai_router.py"
click node_website_workers "https://github.com/sothunly-alt/inbound_news_bot/blob/main/workers/ingest_apis.py"
click node_dedup "https://github.com/sothunly-alt/inbound_news_bot/blob/main/workers/dedup.py"
click node_worker_db "https://github.com/sothunly-alt/inbound_news_bot/blob/main/workers/db.py"
click node_website "https://github.com/sothunly-alt/inbound_news_bot/blob/main/inbound-news-web/src/app/page.tsx"
click node_story_experience "https://github.com/sothunly-alt/inbound_news_bot/blob/main/inbound-news-web/src/app/story/%5Bslug%5D/page.tsx"
click node_discovery "https://github.com/sothunly-alt/inbound_news_bot/blob/main/inbound-news-web/src/app/api/search/route.ts"
click node_analysis_tools "https://github.com/sothunly-alt/inbound_news_bot/blob/main/inbound-news-web/src/app/api/local-lens/route.ts"
click node_accounts "https://github.com/sothunly-alt/inbound_news_bot/blob/main/inbound-news-web/src/app/account/page.tsx"
click node_membership_ui "https://github.com/sothunly-alt/inbound_news_bot/blob/main/inbound-news-web/src/components/membership/PaymentModal.tsx"
click node_membership_api "https://github.com/sothunly-alt/inbound_news_bot/blob/main/inbound-news-web/src/app/api/membership/checkout/route.ts"
click node_payway_functions "https://github.com/sothunly-alt/inbound_news_bot/blob/main/supabase/functions/create-payway-transaction/index.ts"
click node_payway_helpers "https://github.com/sothunly-alt/inbound_news_bot/blob/main/supabase/functions/_shared/payway.ts"
click node_supabase_functions_db "https://github.com/sothunly-alt/inbound_news_bot/blob/main/supabase/functions/_shared/supabase.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_news_bot_entry,node_bot_handlers,node_bot_config,node_rss_fetch,node_story_rewrite,node_bot_state,node_mirror_queue toneBlue
class node_ai_router,node_ai_providers,node_story_store,node_supabase toneAmber
class node_website_workers,node_article_store,node_dedup,node_worker_db toneMint
class node_website,node_story_experience,node_discovery,node_analysis_tools,node_accounts toneRose
class node_membership_ui,node_membership_api,node_payway_functions,node_payway_helpers,node_supabase_functions_db,node_reader,node_telegram_users,node_payway toneIndigo
```

## Components

### Telegram publishing

- [Bot scheduler](https://github.com/sothunly-alt/inbound_news_bot/blob/main/news_bot.py): `news_bot.py`
- [Bot handlers](https://github.com/sothunly-alt/inbound_news_bot/blob/main/newsbot/bot.py): `newsbot/bot.py`
- [Bot configuration](https://github.com/sothunly-alt/inbound_news_bot/blob/main/newsbot/config.py): `newsbot/config.py`
- [Curated RSS fetch](https://github.com/sothunly-alt/inbound_news_bot/blob/main/newsbot/feeds.py): `newsbot/feeds.py`
- [Story rewriting](https://github.com/sothunly-alt/inbound_news_bot/blob/main/newsbot/ai.py): `newsbot/ai.py`
- [Subscriber and post state](https://github.com/sothunly-alt/inbound_news_bot/blob/main/newsbot/state.py): `newsbot/state.py`
- [Cross-language mirror](https://github.com/sothunly-alt/inbound_news_bot/blob/main/newsbot/mirror.py): `newsbot/mirror.py`

### Shared AI services

- [Provider fallback router](https://github.com/sothunly-alt/inbound_news_bot/blob/main/shared/ai_router.py): `shared/ai_router.py`
- **AI providers**

### Website ingestion

- [API and RSS collectors](https://github.com/sothunly-alt/inbound_news_bot/blob/main/workers/ingest_apis.py): `workers/ingest_apis.py`
- **Staged articles**
- [Deduplication and matching](https://github.com/sothunly-alt/inbound_news_bot/blob/main/workers/dedup.py): `workers/dedup.py`
- [Worker database client](https://github.com/sothunly-alt/inbound_news_bot/blob/main/workers/db.py): `workers/db.py`

### News website

- [Next.js news site](https://github.com/sothunly-alt/inbound_news_bot/blob/main/inbound-news-web/src/app/page.tsx): `inbound-news-web/src/app/page.tsx`
- [Story and topic pages](https://github.com/sothunly-alt/inbound_news_bot/blob/main/inbound-news-web/src/app/story/%5Bslug%5D/page.tsx): `inbound-news-web/src/app/story/[slug]/page.tsx`
- [Search and comparison](https://github.com/sothunly-alt/inbound_news_bot/blob/main/inbound-news-web/src/app/api/search/route.ts): `inbound-news-web/src/app/api/search/route.ts`
- [Editorial analysis tools](https://github.com/sothunly-alt/inbound_news_bot/blob/main/inbound-news-web/src/app/api/local-lens/route.ts): `inbound-news-web/src/app/api/local-lens/route.ts`
- [Account and authentication](https://github.com/sothunly-alt/inbound_news_bot/blob/main/inbound-news-web/src/app/account/page.tsx): `inbound-news-web/src/app/account/page.tsx`

### Membership and payments

- [Membership experience](https://github.com/sothunly-alt/inbound_news_bot/blob/main/inbound-news-web/src/components/membership/PaymentModal.tsx): `inbound-news-web/src/components/membership/PaymentModal.tsx`
- [Membership endpoints](https://github.com/sothunly-alt/inbound_news_bot/blob/main/inbound-news-web/src/app/api/membership/checkout/route.ts): `inbound-news-web/src/app/api/membership/checkout/route.ts`
- [PayWay transactions](https://github.com/sothunly-alt/inbound_news_bot/blob/main/supabase/functions/create-payway-transaction/index.ts): `supabase/functions/create-payway-transaction/index.ts`
- [PayWay helpers](https://github.com/sothunly-alt/inbound_news_bot/blob/main/supabase/functions/_shared/payway.ts): `supabase/functions/_shared/payway.ts`
- [Supabase function client](https://github.com/sothunly-alt/inbound_news_bot/blob/main/supabase/functions/_shared/supabase.ts): `supabase/functions/_shared/supabase.ts`

### Other components

- **News readers**
- **Telegram subscribers**
- **Website stories**
- **ABA PayWay**
- **Supabase**

## Connections

- Telegram subscribers → Bot scheduler: command input (evidence: `README.md`)
- Bot scheduler → Bot handlers: registers handlers (evidence: `news_bot.py`)
- Bot scheduler → Bot configuration: loads settings (evidence: `news_bot.py`)
- Bot scheduler → Curated RSS fetch: schedules fetches (evidence: `README.md`)
- Bot scheduler → Bot handlers: schedules digests (evidence: `README.md`)
- Bot handlers → Curated RSS fetch: fetches stories (evidence: `newsbot/bot.py`)
- Curated RSS fetch → Story rewriting: clusters for rewrite (evidence: `README.md`)
- Story rewriting → Provider fallback router: routes prompts (evidence: `newsbot/ai.py`)
- Provider fallback router → AI providers: calls providers (evidence: `shared/ai_router.py`)
- Bot handlers → Subscriber and post state: tracks posts (evidence: `newsbot/bot.py`)
- Bot handlers → Cross-language mirror: publishes mirror items (evidence: `newsbot/bot.py`)
- Bot handlers → Telegram subscribers: broadcasts posts (evidence: `README.md`)
- API and RSS collectors → Staged articles: upserts articles (evidence: `workers/ingest_apis.py`)
- API and RSS collectors → Worker database client: gets database client (evidence: `workers/ingest_apis.py`)
- API and RSS collectors → Deduplication and matching: passes articles (evidence: `README.md`)
- Deduplication and matching → Website stories: writes stories (evidence: `README.md`)
- Next.js news site → Website stories: reads story feed (evidence: `README.md`)
- News readers → Next.js news site: browses news (evidence: `README.md`)
- News readers → Story and topic pages: opens stories
- News readers → Search and comparison: searches and compares
- News readers → Editorial analysis tools: uses analysis
- News readers → Account and authentication: manages account
- News readers → Membership experience: purchases membership
- Membership experience → Membership endpoints: starts checkout
- Membership endpoints → PayWay transactions: initiates payment
- PayWay transactions → PayWay helpers: uses payment helpers (evidence: `supabase/functions/create-payway-transaction/index.ts`)
- PayWay transactions → Supabase function client: uses admin client (evidence: `supabase/functions/create-payway-transaction/index.ts`)
- PayWay helpers → ABA PayWay: requests transactions
- Supabase function client → Supabase: connects client (evidence: `supabase/functions/_shared/supabase.ts`)
