# devathmaj/voucherbot architecture

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

- Interactive diagram: https://gitdiagram.com/devathmaj/voucherbot
- Repository: https://github.com/devathmaj/voucherbot

## Overview

VoucherBot continuously collects certification-promotion posts, filters and deduplicates them, extracts voucher details with AI, matches posts to canonical events, then sends alerts. The scheduled dispatcher owns per-source polling; the ingestion pipeline coordinates the processing stages. Separate scheduled work consolidates events and retries notification delivery. The README also describes Discord and Telegram notifications as a separate repository, so that capability is external to this codebase. The source excerpts show the central flow and selected persistence and delivery behavior; unsampled integrations are represented only where documented or indexed.

Main entry points: [`voucherbot/services/ingestion/pipeline.py`](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/ingestion/pipeline.py) (Ingestion pipeline), [`voucherbot/services/scheduler.py`](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/scheduler.py) (Scheduled jobs), [`voucherbot/services/email/notifications.py`](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/email/notifications.py) (Email outbox), [`voucherbot/main.py`](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/main.py) (Application startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime and Scheduling"]
  node_main["Application startup<br/>[main.py]"]
  node_scheduler["Scheduled jobs<br/>[scheduler.py]"]
  node_dispatcher["Source dispatcher<br/>[dispatcher.py]"]
  node_health["Health endpoint<br/>[health.py]"]
  node_settings["Application settings<br/>[settings.py]"]
end

subgraph group_collection["Source Collection"]
  node_reddit["Reddit collector<br/>[collector.py]"]
  node_rss["RSS collector<br/>[collector.py]"]
  node_webcollectors["Website and exam collectors"]
  node_http_policy["Polite HTTP policy<br/>[http_policy.py]"]
  node_provider_model["Normalized post interface<br/>[base.py]"]
end

subgraph group_processing["Ingestion and Matching"]
  node_pipeline["Ingestion pipeline<br/>[pipeline.py]"]
  node_dedup["Post deduplication<br/>[dedup.py]"]
  node_analyzer["AI extraction<br/>[analyzer.py]"]
  node_schema["Extracted event schema<br/>[schema.py]"]
  node_matcher["Event matching<br/>[event_matcher.py]"]
  node_ai_matcher["AI event matching"]
  node_consolidation["Event consolidation"]
end

subgraph group_persistence["Data and State"]
  node_db[("Database<br/>[connection.py]")]
  node_source_model["Source records<br/>[source.py]"]
  node_post_model["Post records<br/>[post.py]"]
  node_event_model["Canonical events<br/>[event.py]"]
  node_other_models["Supporting records"]
  node_retention["Data retention<br/>[retention.py]"]
end

subgraph group_alerts["Notifications"]
  node_email_notifications["Email outbox<br/>[notifications.py]"]
  node_email_sender["Email sender<br/>[sender.py]"]
  node_bot_notifier["Bot notifications<br/>[notifier.py]"]
end

node_operator(("VoucherBot operator"))
node_email_service{{"Resend"}}
node_chat_bots{{"Discord and Telegram bots"}}

node_operator -->|"starts"| node_main
node_main -->|"starts jobs"| node_scheduler
node_main -->|"registers"| node_health
node_scheduler -->|"ticks"| node_dispatcher
node_scheduler -->|"schedules"| node_consolidation
node_scheduler -->|"schedules"| node_retention
node_scheduler -->|"retries delivery"| node_email_notifications
node_dispatcher -->|"runs source"| node_pipeline
node_scheduler -->|"configures"| node_reddit
node_scheduler -->|"configures"| node_rss
node_scheduler -->|"configures"| node_webcollectors
node_pipeline -->|"consumes posts"| node_provider_model
node_pipeline -->|"deduplicates"| node_dedup
node_pipeline -->|"extracts details"| node_analyzer
node_analyzer -->|"returns structure"| node_schema
node_pipeline -->|"matches events"| node_matcher
node_matcher -->|"checks candidates"| node_ai_matcher
node_consolidation -->|"checks event pairs"| node_ai_matcher
node_pipeline -->|"stages alerts"| node_email_notifications
node_pipeline -->|"notifies"| node_bot_notifier
node_email_notifications -->|"sends email"| node_email_sender
node_email_sender -->|"delivers"| node_email_service
node_bot_notifier -.->|"alerts via"| node_chat_bots
node_http_policy -->|"reads policy settings"| node_settings
node_reddit -->|"uses requests"| node_http_policy
node_rss -->|"uses requests"| node_http_policy
node_webcollectors -.->|"uses requests"| node_http_policy
node_dispatcher -->|"selects sources"| node_source_model
node_pipeline -->|"reads source config"| node_source_model
node_pipeline -->|"writes posts"| node_post_model
node_pipeline -->|"links events"| node_event_model
node_pipeline -->|"reads keywords"| node_other_models
node_consolidation -->|"merges events"| node_event_model
node_retention -.->|"cleans records"| node_db
node_dispatcher -->|"uses sessions"| node_db
node_health -->|"checks connection"| node_db
node_email_notifications -->|"updates notified state"| node_post_model
node_email_notifications -->|"stores outbox"| node_other_models
node_main -->|"loads settings"| node_settings

click node_main "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/main.py"
click node_scheduler "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/scheduler.py"
click node_dispatcher "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/dispatcher.py"
click node_health "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/api/routers/health.py"
click node_settings "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/config/settings.py"
click node_reddit "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/providers/reddit/collector.py"
click node_rss "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/providers/rss/collector.py"
click node_webcollectors "https://github.com/devathmaj/voucherbot/tree/main/voucherbot/providers"
click node_http_policy "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/providers/http_policy.py"
click node_provider_model "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/providers/base.py"
click node_pipeline "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/ingestion/pipeline.py"
click node_dedup "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/ingestion/dedup.py"
click node_analyzer "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/ai/analyzer.py"
click node_schema "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/ai/schema.py"
click node_matcher "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/ingestion/event_matcher.py"
click node_ai_matcher "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/ai/event_matcher_ai.py"
click node_consolidation "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/event_consolidation.py"
click node_db "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/database/connection.py"
click node_source_model "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/models/source.py"
click node_post_model "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/models/post.py"
click node_event_model "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/models/event.py"
click node_other_models "https://github.com/devathmaj/voucherbot/tree/main/voucherbot/models"
click node_retention "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/retention.py"
click node_email_notifications "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/email/notifications.py"
click node_email_sender "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/email/sender.py"
click node_bot_notifier "https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/bot_notification/notifier.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_main,node_scheduler,node_dispatcher,node_health,node_settings toneBlue
class node_reddit,node_rss,node_webcollectors,node_http_policy,node_provider_model toneAmber
class node_pipeline,node_dedup,node_analyzer,node_schema,node_matcher,node_ai_matcher,node_consolidation toneMint
class node_db,node_source_model,node_post_model,node_event_model,node_other_models,node_retention toneRose
class node_email_notifications,node_email_sender,node_bot_notifier,node_operator,node_email_service,node_chat_bots toneIndigo
```

## Components

### Runtime and Scheduling

- [Application startup](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/main.py): `voucherbot/main.py`
- [Scheduled jobs](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/scheduler.py): `voucherbot/services/scheduler.py`
- [Source dispatcher](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/dispatcher.py): `voucherbot/services/dispatcher.py`
- [Health endpoint](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/api/routers/health.py): `voucherbot/api/routers/health.py`
- [Application settings](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/config/settings.py): `voucherbot/config/settings.py`

### Source Collection

- [Reddit collector](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/providers/reddit/collector.py): `voucherbot/providers/reddit/collector.py`
- [RSS collector](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/providers/rss/collector.py): `voucherbot/providers/rss/collector.py`
- [Website and exam collectors](https://github.com/devathmaj/voucherbot/tree/main/voucherbot/providers): `voucherbot/providers`
- [Polite HTTP policy](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/providers/http_policy.py): `voucherbot/providers/http_policy.py`
- [Normalized post interface](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/providers/base.py): `voucherbot/providers/base.py`

### Ingestion and Matching

- [Ingestion pipeline](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/ingestion/pipeline.py): `voucherbot/services/ingestion/pipeline.py`
- [Post deduplication](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/ingestion/dedup.py): `voucherbot/services/ingestion/dedup.py`
- [AI extraction](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/ai/analyzer.py): `voucherbot/services/ai/analyzer.py`
- [Extracted event schema](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/ai/schema.py): `voucherbot/services/ai/schema.py`
- [Event matching](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/ingestion/event_matcher.py): `voucherbot/services/ingestion/event_matcher.py`
- [AI event matching](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/ai/event_matcher_ai.py): `voucherbot/services/ai/event_matcher_ai.py`
- [Event consolidation](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/event_consolidation.py): `voucherbot/services/event_consolidation.py`

### Data and State

- [Database](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/database/connection.py): `voucherbot/database/connection.py`
- [Source records](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/models/source.py): `voucherbot/models/source.py`
- [Post records](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/models/post.py): `voucherbot/models/post.py`
- [Canonical events](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/models/event.py): `voucherbot/models/event.py`
- [Supporting records](https://github.com/devathmaj/voucherbot/tree/main/voucherbot/models): `voucherbot/models`
- [Data retention](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/retention.py): `voucherbot/services/retention.py`

### Notifications

- [Email outbox](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/email/notifications.py): `voucherbot/services/email/notifications.py`
- [Email sender](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/email/sender.py): `voucherbot/services/email/sender.py`
- [Bot notifications](https://github.com/devathmaj/voucherbot/blob/main/voucherbot/services/bot_notification/notifier.py): `voucherbot/services/bot_notification/notifier.py`

### Other components

- **VoucherBot operator**
- **Resend**
- **Discord and Telegram bots**

## Connections

- VoucherBot operator → Application startup: starts
- Application startup → Scheduled jobs: starts jobs (evidence: `voucherbot/main.py`)
- Application startup → Health endpoint: registers (evidence: `voucherbot/main.py`)
- Scheduled jobs → Source dispatcher: ticks (evidence: `voucherbot/services/scheduler.py`)
- Scheduled jobs → Event consolidation: schedules (evidence: `voucherbot/services/scheduler.py`)
- Scheduled jobs → Data retention: schedules (evidence: `voucherbot/services/scheduler.py`)
- Scheduled jobs → Email outbox: retries delivery (evidence: `voucherbot/services/scheduler.py`)
- Source dispatcher → Ingestion pipeline: runs source (evidence: `voucherbot/services/dispatcher.py`)
- Scheduled jobs → Reddit collector: configures (evidence: `voucherbot/services/scheduler.py`)
- Scheduled jobs → RSS collector: configures (evidence: `voucherbot/services/scheduler.py`)
- Scheduled jobs → Website and exam collectors: configures (evidence: `voucherbot/services/scheduler.py`)
- Ingestion pipeline → Normalized post interface: consumes posts (evidence: `voucherbot/services/ingestion/pipeline.py`)
- Ingestion pipeline → Post deduplication: deduplicates (evidence: `voucherbot/services/ingestion/pipeline.py`)
- Ingestion pipeline → AI extraction: extracts details (evidence: `voucherbot/services/ingestion/pipeline.py`)
- AI extraction → Extracted event schema: returns structure (evidence: `voucherbot/services/ai/analyzer.py`)
- Ingestion pipeline → Event matching: matches events (evidence: `voucherbot/services/ingestion/pipeline.py`)
- Event matching → AI event matching: checks candidates (evidence: `voucherbot/services/ingestion/event_matcher.py`)
- Event consolidation → AI event matching: checks event pairs (evidence: `voucherbot/services/event_consolidation.py`)
- Ingestion pipeline → Email outbox: stages alerts (evidence: `voucherbot/services/ingestion/pipeline.py`)
- Ingestion pipeline → Bot notifications: notifies (evidence: `voucherbot/services/ingestion/pipeline.py`)
- Email outbox → Email sender: sends email (evidence: `voucherbot/services/email/notifications.py`)
- Email sender → Resend: delivers (evidence: `voucherbot/services/email/sender.py`)
- Bot notifications → Discord and Telegram bots: alerts via
- Polite HTTP policy → Application settings: reads policy settings (evidence: `voucherbot/providers/http_policy.py`)
- Reddit collector → Polite HTTP policy: uses requests (evidence: `voucherbot/providers/reddit/collector.py`)
- RSS collector → Polite HTTP policy: uses requests (evidence: `voucherbot/providers/rss/collector.py`)
- Website and exam collectors → Polite HTTP policy: uses requests (evidence: `voucherbot/providers/pearsonvue/collector.py`)
- Source dispatcher → Source records: selects sources (evidence: `voucherbot/services/dispatcher.py`)
- Ingestion pipeline → Source records: reads source config (evidence: `voucherbot/services/ingestion/pipeline.py`)
- Ingestion pipeline → Post records: writes posts (evidence: `voucherbot/services/ingestion/pipeline.py`)
- Ingestion pipeline → Canonical events: links events (evidence: `voucherbot/services/ingestion/pipeline.py`)
- Ingestion pipeline → Supporting records: reads keywords (evidence: `voucherbot/services/ingestion/pipeline.py`)
- Event consolidation → Canonical events: merges events (evidence: `voucherbot/services/event_consolidation.py`)
- Data retention → Database: cleans records
- Source dispatcher → Database: uses sessions (evidence: `voucherbot/services/dispatcher.py`)
- Health endpoint → Database: checks connection (evidence: `voucherbot/api/routers/health.py`)
- Email outbox → Post records: updates notified state (evidence: `voucherbot/services/email/notifications.py`)
- Email outbox → Supporting records: stores outbox (evidence: `voucherbot/services/email/notifications.py`)
- Application startup → Application settings: loads settings (evidence: `voucherbot/main.py`)
