# jony99jrn/diu_drive_bot architecture

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

- Interactive diagram: https://gitdiagram.com/jony99jrn/diu_drive_bot
- Repository: https://github.com/jony99jrn/diu_drive_bot

## Overview

DIU Class Materials Bot is a Telegram service for students to browse course materials and for admins to upload, archive, and manage missing-file reports. Its main student flow is Department → Semester → Course → exam/file list → delivery; admin uploads and channel posts are parsed into catalog records, backed up to a private channel, and stored in Google Sheets. The graph reflects the README and shown calls. Some webhook logic is unsampled, so unverified subsystem links are omitted.

Main entry points: [`lib/sheets.js`](https://github.com/jony99jrn/diu_drive_bot/blob/main/lib/sheets.js) (Sheets access), [`api/webhook.js`](https://github.com/jony99jrn/diu_drive_bot/blob/main/api/webhook.js) (Webhook handler), [`lib/telegram.js`](https://github.com/jony99jrn/diu_drive_bot/blob/main/lib/telegram.js) (File delivery), [`lib/util.js`](https://github.com/jony99jrn/diu_drive_bot/blob/main/lib/util.js) (Parsing and helpers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Bot entry and interaction"]
  node_webhook["Webhook handler<br/>[webhook.js]"]
  node_normalizers["Parsing and helpers<br/>[util.js]"]
end

subgraph group_catalog["Materials catalog"]
  node_catalog_browse["Catalog browsing<br/>[webhook.js]"]
  node_file_delivery["File delivery<br/>[telegram.js]"]
end

subgraph group_admin["Admin workflows"]
  node_upload_flow["Guided uploads<br/>[webhook.js]"]
  node_batch_upload["Batch uploads<br/>[webhook.js]"]
  node_archive_flow["Semester archiving<br/>[webhook.js]"]
  node_reports["Missing-file reports<br/>[webhook.js]"]
end

subgraph group_storage["Persistence and delivery"]
  node_sheet_access["Sheets access<br/>[sheets.js]"]
  node_current_files[("Current files")]
  node_archive_files[("Archived files")]
  node_upload_state[("Pending uploads")]
  node_report_data[("Limits and reports")]
end

node_students(("Students"))
node_admins(("Admins"))
node_telegram{{"Telegram"}}
node_backup_channel{{"Storage channel"}}

node_telegram -->|"posts updates"| node_webhook
node_webhook -->|"responds via"| node_telegram
node_students -->|"browses and requests"| node_telegram
node_admins -->|"uploads and manages"| node_telegram
node_webhook -->|"routes callbacks"| node_catalog_browse
node_catalog_browse -->|"reads catalog"| node_sheet_access
node_catalog_browse -->|"requests file send"| node_file_delivery
node_file_delivery -->|"sends file"| node_telegram
node_webhook -->|"uses parsing"| node_normalizers
node_webhook -->|"routes uploads"| node_upload_flow
node_upload_flow -->|"stores upload state"| node_sheet_access
node_upload_flow -.->|"backs up files"| node_backup_channel
node_webhook -->|"handles batch commands"| node_batch_upload
node_batch_upload -->|"stores pending state"| node_sheet_access
node_webhook -->|"routes archive commands"| node_archive_flow
node_archive_flow -->|"counts and moves"| node_sheet_access
node_webhook -->|"handles report actions"| node_reports
node_reports -->|"logs and claims"| node_sheet_access
node_sheet_access -->|"reads and writes"| node_current_files
node_sheet_access -->|"reads and moves"| node_archive_files
node_sheet_access -->|"reads and writes"| node_upload_state
node_sheet_access -->|"reads and writes"| node_report_data

click node_webhook "https://github.com/jony99jrn/diu_drive_bot/blob/main/api/webhook.js"
click node_normalizers "https://github.com/jony99jrn/diu_drive_bot/blob/main/lib/util.js"
click node_catalog_browse "https://github.com/jony99jrn/diu_drive_bot/blob/main/api/webhook.js"
click node_file_delivery "https://github.com/jony99jrn/diu_drive_bot/blob/main/lib/telegram.js"
click node_upload_flow "https://github.com/jony99jrn/diu_drive_bot/blob/main/api/webhook.js"
click node_batch_upload "https://github.com/jony99jrn/diu_drive_bot/blob/main/api/webhook.js"
click node_archive_flow "https://github.com/jony99jrn/diu_drive_bot/blob/main/api/webhook.js"
click node_reports "https://github.com/jony99jrn/diu_drive_bot/blob/main/api/webhook.js"
click node_sheet_access "https://github.com/jony99jrn/diu_drive_bot/blob/main/lib/sheets.js"

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_webhook,node_normalizers toneBlue
class node_catalog_browse,node_file_delivery,node_backup_channel toneAmber
class node_upload_flow,node_batch_upload,node_archive_flow,node_reports toneMint
class node_sheet_access,node_current_files,node_archive_files,node_upload_state,node_report_data toneRose
class node_students,node_admins,node_telegram toneIndigo
```

## Components

### Bot entry and interaction

- [Webhook handler](https://github.com/jony99jrn/diu_drive_bot/blob/main/api/webhook.js): `api/webhook.js`
- [Parsing and helpers](https://github.com/jony99jrn/diu_drive_bot/blob/main/lib/util.js): `lib/util.js`

### Materials catalog

- [Catalog browsing](https://github.com/jony99jrn/diu_drive_bot/blob/main/api/webhook.js): `api/webhook.js`
- [File delivery](https://github.com/jony99jrn/diu_drive_bot/blob/main/lib/telegram.js): `lib/telegram.js`

### Admin workflows

- [Guided uploads](https://github.com/jony99jrn/diu_drive_bot/blob/main/api/webhook.js): `api/webhook.js`
- [Batch uploads](https://github.com/jony99jrn/diu_drive_bot/blob/main/api/webhook.js): `api/webhook.js`
- [Semester archiving](https://github.com/jony99jrn/diu_drive_bot/blob/main/api/webhook.js): `api/webhook.js`
- [Missing-file reports](https://github.com/jony99jrn/diu_drive_bot/blob/main/api/webhook.js): `api/webhook.js`

### Persistence and delivery

- [Sheets access](https://github.com/jony99jrn/diu_drive_bot/blob/main/lib/sheets.js): `lib/sheets.js`
- **Current files**
- **Archived files**
- **Pending uploads**
- **Limits and reports**

### Other components

- **Students**
- **Admins**
- **Telegram**
- **Storage channel**

## Connections

- Telegram → Webhook handler: posts updates (evidence: `README.md`)
- Webhook handler → Telegram: responds via (evidence: `api/webhook.js`)
- Students → Telegram: browses and requests (evidence: `README.md`)
- Admins → Telegram: uploads and manages (evidence: `README.md`)
- Webhook handler → Catalog browsing: routes callbacks (evidence: `api/webhook.js`)
- Catalog browsing → Sheets access: reads catalog (evidence: `api/webhook.js`)
- Catalog browsing → File delivery: requests file send (evidence: `api/webhook.js`)
- File delivery → Telegram: sends file (evidence: `lib/telegram.js`)
- Webhook handler → Parsing and helpers: uses parsing (evidence: `api/webhook.js`)
- Webhook handler → Guided uploads: routes uploads (evidence: `api/webhook.js`)
- Guided uploads → Sheets access: stores upload state (evidence: `api/webhook.js`)
- Guided uploads → Storage channel: backs up files (evidence: `README.md`)
- Webhook handler → Batch uploads: handles batch commands (evidence: `api/webhook.js`)
- Batch uploads → Sheets access: stores pending state (evidence: `api/webhook.js`)
- Webhook handler → Semester archiving: routes archive commands (evidence: `api/webhook.js`)
- Semester archiving → Sheets access: counts and moves (evidence: `api/webhook.js`)
- Webhook handler → Missing-file reports: handles report actions (evidence: `api/webhook.js`)
- Missing-file reports → Sheets access: logs and claims (evidence: `api/webhook.js`)
- Sheets access → Current files: reads and writes (evidence: `lib/sheets.js`)
- Sheets access → Archived files: reads and moves (evidence: `lib/sheets.js`)
- Sheets access → Pending uploads: reads and writes (evidence: `lib/sheets.js`)
- Sheets access → Limits and reports: reads and writes (evidence: `lib/sheets.js`)
