# draxkiller/uninotif-v2 architecture

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

- Interactive diagram: https://gitdiagram.com/draxkiller/uninotif-v2
- Repository: https://github.com/draxkiller/uninotif-v2

## Overview

1. **Overall shape**
   - This repo is a **single-script notification pipeline** run on a **GitHub Actions scheduler**, not a hosted service.
   - The core executable is `scraper.py`; the other JSON files are **persistent state** that the script updates and commits back to the repo.

2. **Execution environment**
   - The workflow in `.github/workflows/notify.yml` runs every 5 minutes on a GitHub Actions runner.
   - The runner is ephemeral, so persistence is achieved by **reading and writing files in the repository** and pushing them back with GitHub write permissions.

3. **Primary data source**
   - The bot monitors Pondicherry University notifications using the **WordPress REST API** as the preferred source.
   - If the API is unavailable, it falls back to **HTML scraping** of the notifications page.
   - The source content appears to be organized by **7 notification categories**, which the bot scans for new posts.

4. **Notification detection flow**
   - `scraper.py` fetches the current set of notifications, normalizes each entry into a stable identifier, and compares it against `seen.json`.
   - Anything not already recorded in `seen.json` is treated as a **new notification** and processed for delivery.

5. **Deduplication and seeding**
   - `seen.json` is the main idempotency boundary: it prevents resend across runs, including after a crash.
   - On the **first run**, the bot seeds `seen.json` with the existing notifications and does **not** send alerts.
   - The README indicates entries older than 180 days are pruned automatically, while baseline seeded entries are retained.

6. **Message delivery boundary**
   - New notifications are sent to **Telegram** using a bot token and one or more chat IDs from secrets.
   - The **first chat ID is special**: it receives admin-only messages such as errors and the daily heartbeat.
   - Additional chat IDs receive notification broadcasts only.

7. **Attachment handling**
   - The bot attempts to fetch the notification’s **PDF attachment** and include it in the Telegram message.
   - If PDF download fails, or if the file is too large for Telegram’s limit, it falls back to sending **text plus the notification link**.
   - The README notes the bot only attaches the PDF associated with the notification content area, avoiding unrelated site PDFs.

8. **Optional AI summarization subsystem**
   - If `GEMINI_API_KEY` is configured and AI summaries are enabled, the bot sends notification text through **Google Gemini Flash** for a short summary.
   - `pdfplumber` is used to extract text from PDFs when summarization needs document content.
   - This is an optional side path; the bot still functions without it.

9. **Heartbeat and operational observability**
   - `heartbeat.json` tracks when the bot last sent its daily “I’m alive” message.
   - Roughly once per day, the first run after a long enough gap sends a **heartbeat alert** to the admin chat ID.
   - This gives the operator a simple liveness signal without external monitoring.

10. **Error handling and admin alerts**
   - Failures are reported to the **first Telegram chat ID only**, keeping operational noise away from regular recipients.
   - The README suggests the workflow retries repo push operations, which matters because state files must be committed successfully to preserve deduplication.

11. **Persistence and self-updating state**
   - `seen.json` and `heartbeat.json` are both part of the repo and are updated by the bot after each run.
   - That makes the repository itself the state store, and GitHub Actions plus git push is the persistence mechanism.

12. **Dependencies and runtime profile**
   - The script uses `requests`, `beautifulsoup4`, and `lxml` for source retrieval/parsing.
   - `google-generativeai` and `pdfplumber` are optional, only relevant when AI summaries are enabled.
   - This is a lightweight Python automation project whose architecture is centered on **scheduled fetch → compare → notify → persist**.

Main entry points: [`scraper.py`](https://github.com/draxkiller/uninotif-v2/blob/main/scraper.py) (Scraper bot), [`seen.json`](https://github.com/draxkiller/uninotif-v2/blob/main/seen.json) (Seen state), [`heartbeat.json`](https://github.com/draxkiller/uninotif-v2/blob/main/heartbeat.json) (Heartbeat state), [`.github/workflows/notify.yml`](https://github.com/draxkiller/uninotif-v2/blob/main/.github/workflows/notify.yml) (Notify workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["GitHub Actions runtime"]
  node_workflow["Notify workflow<br/>github-actions schedule<br/>[notify.yml]"]
  node_scraper["Scraper bot<br/>python automation<br/>[scraper.py]"]
  node_fetch_parse["Fetch parse<br/>ingest stage<br/>[scraper.py]"]
  node_dedupe["Dedup check<br/>state compare<br/>[scraper.py]"]
  node_deliver["Deliver alerts<br/>telegram dispatch<br/>[scraper.py]"]
  node_summarize["Summaries<br/>optional ai path<br/>[scraper.py]"]
  node_persist["Persist state<br/>repo writeback<br/>[scraper.py]"]
  node_admin_alerts["Admin alerts<br/>ops channel<br/>[scraper.py]"]
end

subgraph group_state["Repository state"]
  node_seen[("Seen state<br/>dedupe ledger<br/>[seen.json]")]
  node_heartbeat[("Heartbeat state<br/>liveness marker<br/>[heartbeat.json]")]
  node_requirements["Dependencies<br/>python deps<br/>[requirements.txt]"]
  node_readme["README<br/>project docs<br/>[README.md]"]
end

subgraph group_external["External services"]
  node_source_api[("WordPress API<br/>notifications source")]
  node_source_html["HTML fallback<br/>web scrape source"]
  node_telegram["Telegram<br/>delivery channel"]
  node_gemini(("Gemini Flash<br/>optional ai summarizer"))
end

node_workflow -->|"runs"| node_scraper
node_scraper -->|"starts"| node_fetch_parse
node_fetch_parse -->|"prefers"| node_source_api
node_fetch_parse -.->|"falls back"| node_source_html
node_fetch_parse -->|"normalizes"| node_dedupe
node_dedupe -->|"compares against"| node_seen
node_dedupe -->|"forwards new items"| node_deliver
node_dedupe -->|"seeds/prunes"| node_persist
node_deliver -->|"broadcasts"| node_telegram
node_deliver -.->|"optional summarize"| node_summarize
node_summarize -.->|"calls"| node_gemini
node_summarize -.->|"enriches message"| node_deliver
node_deliver -->|"errors/heartbeat"| node_admin_alerts
node_admin_alerts -->|"sends to admin chat"| node_telegram
node_scraper -->|"checks/updates"| node_heartbeat
node_scraper -->|"writes"| node_persist
node_persist -->|"commits"| node_seen
node_persist -->|"commits"| node_heartbeat
node_scraper -.->|"depends on"| node_requirements
node_readme -.->|"documents"| node_scraper

click node_workflow "https://github.com/draxkiller/uninotif-v2/blob/main/.github/workflows/notify.yml"
click node_scraper "https://github.com/draxkiller/uninotif-v2/blob/main/scraper.py"
click node_seen "https://github.com/draxkiller/uninotif-v2/blob/main/seen.json"
click node_heartbeat "https://github.com/draxkiller/uninotif-v2/blob/main/heartbeat.json"
click node_requirements "https://github.com/draxkiller/uninotif-v2/blob/main/requirements.txt"
click node_readme "https://github.com/draxkiller/uninotif-v2/blob/main/README.md"
click node_fetch_parse "https://github.com/draxkiller/uninotif-v2/blob/main/scraper.py"
click node_dedupe "https://github.com/draxkiller/uninotif-v2/blob/main/scraper.py"
click node_deliver "https://github.com/draxkiller/uninotif-v2/blob/main/scraper.py"
click node_summarize "https://github.com/draxkiller/uninotif-v2/blob/main/scraper.py"
click node_persist "https://github.com/draxkiller/uninotif-v2/blob/main/scraper.py"
click node_admin_alerts "https://github.com/draxkiller/uninotif-v2/blob/main/scraper.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_workflow,node_scraper,node_fetch_parse,node_dedupe,node_deliver,node_summarize,node_persist,node_admin_alerts toneBlue
class node_seen,node_heartbeat,node_requirements,node_readme toneAmber
class node_source_api,node_source_html,node_telegram,node_gemini toneMint
```

## Components

### GitHub Actions runtime

Scheduled execution and orchestration inside GitHub Actions.

- [Notify workflow](https://github.com/draxkiller/uninotif-v2/blob/main/.github/workflows/notify.yml): github-actions schedule · Runs the bot every few minutes on an ephemeral runner. · `.github/workflows/notify.yml`
- [Scraper bot](https://github.com/draxkiller/uninotif-v2/blob/main/scraper.py): python automation · Main executable that fetches notifications, deduplicates, sends alerts, and persists state. · `scraper.py`
- [Fetch parse](https://github.com/draxkiller/uninotif-v2/blob/main/scraper.py): ingest stage · Retrieves notification listings and normalizes entries into stable identifiers. · `scraper.py`
- [Dedup check](https://github.com/draxkiller/uninotif-v2/blob/main/scraper.py): state compare · Compares normalized notifications against seen.json and seeds on first run. · `scraper.py`
- [Deliver alerts](https://github.com/draxkiller/uninotif-v2/blob/main/scraper.py): telegram dispatch · Sends new notifications, attaches PDFs when possible, otherwise sends text and link. · `scraper.py`
- [Summaries](https://github.com/draxkiller/uninotif-v2/blob/main/scraper.py): optional ai path · Extracts text from PDFs and produces short summaries when enabled. · `scraper.py`
- [Persist state](https://github.com/draxkiller/uninotif-v2/blob/main/scraper.py): repo writeback · Updates repository state files and relies on git push for durability. · `scraper.py`
- [Admin alerts](https://github.com/draxkiller/uninotif-v2/blob/main/scraper.py): ops channel · Routes errors and heartbeat messages to the first Telegram chat ID only. · `scraper.py`

### Repository state

Persistent files updated and committed by the bot.

- [Seen state](https://github.com/draxkiller/uninotif-v2/blob/main/seen.json): dedupe ledger · Persistent idempotency boundary for already-processed notifications. · `seen.json`
- [Heartbeat state](https://github.com/draxkiller/uninotif-v2/blob/main/heartbeat.json): liveness marker · Tracks when the last daily heartbeat was sent. · `heartbeat.json`
- [Dependencies](https://github.com/draxkiller/uninotif-v2/blob/main/requirements.txt): python deps · Pinned runtime libraries used by the scraper and optional features. · `requirements.txt`
- [README](https://github.com/draxkiller/uninotif-v2/blob/main/README.md): project docs · Describes behavior, seeding, pruning, fallback flow, and operational notes. · `README.md`

### External services

Upstream source, delivery target, and optional AI services.

- **WordPress API**: notifications source · Preferred upstream source for Pondicherry University notifications.
- **HTML fallback**: web scrape source · Fallback notifications page scraping when the API is unavailable.
- **Telegram**: delivery channel · Receives notification broadcasts, admin errors, and heartbeat messages.
- **Gemini Flash**: optional ai summarizer · Optional summarization service used when AI summaries are enabled.

## Connections

- Notify workflow → Scraper bot: runs · Scheduled GitHub Actions execution starts the Python script.
- Scraper bot → Fetch parse: starts · Main script begins by collecting current notifications.
- Fetch parse → WordPress API: prefers · Uses the WordPress REST API when available.
- Fetch parse → HTML fallback: falls back · Scrapes HTML when the API cannot be used.
- Fetch parse → Dedup check: normalizes · Transforms source entries into stable identifiers for comparison.
- Dedup check → Seen state: compares against · Checks whether each notification has already been processed.
- Dedup check → Deliver alerts: forwards new items · Only unseen notifications move on to delivery.
- Dedup check → Persist state: seeds/prunes · Initializes the ledger on first run and removes old entries over time.
- Deliver alerts → Telegram: broadcasts · Sends new notification alerts to one or more chats.
- Deliver alerts → Summaries: optional summarize · Invokes AI summary generation when configured.
- Summaries → Gemini Flash: calls · Uses Gemini Flash for short summaries.
- Summaries → Deliver alerts: enriches message · Summary output is included in the notification payload.
- Deliver alerts → Admin alerts: errors/heartbeat · Operational messages are routed only to the first chat ID.
- Admin alerts → Telegram: sends to admin chat · Admin-only Telegram channel receives liveness and failure notices.
- Scraper bot → Heartbeat state: checks/updates · Tracks when the daily heartbeat was last emitted.
- Scraper bot → Persist state: writes · Updates repo-backed state after processing completes.
- Persist state → Seen state: commits · Writes dedupe ledger back into the repository.
- Persist state → Heartbeat state: commits · Writes liveness state back into the repository.
- Scraper bot → Dependencies: depends on · Runtime libraries for HTTP, parsing, and optional AI/PDF features.
- README → Scraper bot: documents · Explains the pipeline, seeding, pruning, and delivery behavior.
