# chiragjaju13/ncs-whatsapp-bot architecture

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

- Interactive diagram: https://gitdiagram.com/chiragjaju13/ncs-whatsapp-bot
- Repository: https://github.com/chiragjaju13/ncs-whatsapp-bot

## Overview

This is a daily tender-monitoring and WhatsApp alert bot. Its main workflow fetches tenders from MSEDCL and Mahatenders, filters them by Maharashtra district/taluka, compares them with a local archive, then sends grouped new or updated alerts through Evolution API. The README also documents randomized message delays, dated run logs, and randomized daily scheduling. The sampled source is partial, so relationships not shown there are included only where the README explicitly describes them.

Main entry points: [`main.py`](https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py) (Bot run), [`run_random.sh`](https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/run_random.sh) (Randomized scheduler), [`tender_archive.json`](https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/tender_archive.json) (Tender archive), [`logs/Datewise.txt`](https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/logs/Datewise.txt) (Dated run logs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_collection["Tender collection"]
  node_job["Bot run<br/>[main.py]"]
  node_msedcl["MSEDCL scraper<br/>[main.py]"]
  node_mahatenders["Mahatenders scraper<br/>[main.py]"]
  node_msedcl_portal["MSEDCL tender API"]
  node_mahatenders_portal["Mahatenders portal"]
end

subgraph group_processing["Matching and tracking"]
  node_district_match["District matching<br/>[main.py]"]
  node_archive_check["Tender change detection<br/>[main.py]"]
  node_archive[("Tender archive")]
end

subgraph group_delivery["WhatsApp delivery"]
  node_message_format["Alert formatting<br/>[main.py]"]
  node_message_delay["Send delays<br/>[main.py]"]
  node_sender["WhatsApp sender<br/>[main.py]"]
  node_evolution["Evolution API"]
  node_postgres[("Evolution Postgres")]
end

subgraph group_operations["Runtime operations"]
  node_random_wrapper["Randomized scheduler<br/>[run_random.sh]"]
  node_run_logs["Dated run logs<br/>[Datewise.txt]"]
end

node_cron(("Daily cron"))
node_msedcl_group(("MSEDCL WhatsApp group"))
node_mahatenders_group(("Mahatenders WhatsApp group"))

node_cron -->|"triggers daily"| node_random_wrapper
node_random_wrapper -->|"runs after delay"| node_job
node_job -->|"runs scraper"| node_msedcl
node_job -->|"runs scraper"| node_mahatenders
node_msedcl -->|"requests tenders"| node_msedcl_portal
node_mahatenders -->|"searches tenders"| node_mahatenders_portal
node_msedcl -->|"matches location"| node_district_match
node_mahatenders -->|"matches location"| node_district_match
node_msedcl -->|"checks tenders"| node_archive_check
node_mahatenders -->|"checks tenders"| node_archive_check
node_archive_check -->|"reads and updates"| node_archive
node_msedcl -->|"formats alerts"| node_message_format
node_mahatenders -->|"formats alerts"| node_message_format
node_job -->|"dispatches alerts"| node_sender
node_sender -->|"posts messages"| node_evolution
node_sender -->|"sends MSEDCL batch"| node_msedcl_group
node_sender -->|"sends Mahatenders batch"| node_mahatenders_group
node_sender -->|"waits between sends"| node_message_delay
node_job -->|"writes run log"| node_run_logs
node_evolution -->|"uses backing store"| node_postgres

click node_random_wrapper "https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/run_random.sh"
click node_job "https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py"
click node_msedcl "https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py"
click node_mahatenders "https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py"
click node_district_match "https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py"
click node_archive_check "https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py"
click node_archive "https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/tender_archive.json"
click node_message_format "https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py"
click node_message_delay "https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py"
click node_sender "https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py"
click node_run_logs "https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/logs/Datewise.txt"

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_job,node_msedcl,node_mahatenders,node_msedcl_portal,node_mahatenders_portal toneBlue
class node_district_match,node_archive_check,node_archive toneAmber
class node_message_format,node_message_delay,node_sender,node_evolution,node_postgres toneMint
class node_random_wrapper,node_run_logs toneRose
class node_cron,node_msedcl_group,node_mahatenders_group toneIndigo
```

## Components

### Tender collection

- [Bot run](https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py): `main.py`
- [MSEDCL scraper](https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py): `main.py`
- [Mahatenders scraper](https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py): `main.py`
- **MSEDCL tender API**
- **Mahatenders portal**

### Matching and tracking

- [District matching](https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py): `main.py`
- [Tender change detection](https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py): `main.py`
- [Tender archive](https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/tender_archive.json): `tender_archive.json`

### WhatsApp delivery

- [Alert formatting](https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py): `main.py`
- [Send delays](https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py): `main.py`
- [WhatsApp sender](https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/main.py): `main.py`
- **Evolution API**
- **Evolution Postgres**

### Runtime operations

- [Randomized scheduler](https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/run_random.sh): `run_random.sh`
- [Dated run logs](https://github.com/chiragjaju13/ncs-whatsapp-bot/blob/main/logs/Datewise.txt): `logs/Datewise.txt`

### Other components

- **Daily cron**
- **MSEDCL WhatsApp group**
- **Mahatenders WhatsApp group**

## Connections

- Daily cron → Randomized scheduler: triggers daily (evidence: `README.md`)
- Randomized scheduler → Bot run: runs after delay (evidence: `README.md`)
- Bot run → MSEDCL scraper: runs scraper (evidence: `README.md`)
- Bot run → Mahatenders scraper: runs scraper (evidence: `README.md`)
- MSEDCL scraper → MSEDCL tender API: requests tenders (evidence: `main.py`)
- Mahatenders scraper → Mahatenders portal: searches tenders (evidence: `README.md`)
- MSEDCL scraper → District matching: matches location (evidence: `README.md`)
- Mahatenders scraper → District matching: matches location (evidence: `README.md`)
- MSEDCL scraper → Tender change detection: checks tenders (evidence: `README.md`)
- Mahatenders scraper → Tender change detection: checks tenders (evidence: `README.md`)
- Tender change detection → Tender archive: reads and updates (evidence: `README.md`)
- MSEDCL scraper → Alert formatting: formats alerts (evidence: `README.md`)
- Mahatenders scraper → Alert formatting: formats alerts (evidence: `README.md`)
- Bot run → WhatsApp sender: dispatches alerts (evidence: `README.md`)
- WhatsApp sender → Evolution API: posts messages (evidence: `main.py`)
- WhatsApp sender → MSEDCL WhatsApp group: sends MSEDCL batch (evidence: `README.md`)
- WhatsApp sender → Mahatenders WhatsApp group: sends Mahatenders batch (evidence: `README.md`)
- WhatsApp sender → Send delays: waits between sends (evidence: `README.md`)
- Bot run → Dated run logs: writes run log (evidence: `README.md`)
- Evolution API → Evolution Postgres: uses backing store (evidence: `README.md`)
