# r14bz/hotspotmanager architecture

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

- Interactive diagram: https://gitdiagram.com/r14bz/hotspotmanager
- Repository: https://github.com/r14bz/hotspotmanager

## Overview

HotspotManager is a multi-router MikroTik hotspot-voucher management dashboard. An administrator logs in, selects a router, then generates and manages vouchers, monitors router resources and active users, and reviews or imports sales reports. A cron-triggered sync reconciles voucher state and sales data with MikroTik and Supabase. The README also documents voucher printing, per-router portal settings, and an FTP file manager (not used in production). Some UI and API wiring is not shown in the excerpts; those links are documented at the capability level.

Main entry points: [`src/app/api/vouchers/generate/route.ts`](https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/vouchers/generate/route.ts) (Voucher generation), [`src/lib/sync.ts`](https://github.com/r14bz/hotspotmanager/blob/main/src/lib/sync.ts) (Voucher reconciliation), [`src/app/dashboard/vouchers/page.tsx`](https://github.com/r14bz/hotspotmanager/blob/main/src/app/dashboard/vouchers/page.tsx) (Voucher screens), [`src/app/dashboard/reports/page.tsx`](https://github.com/r14bz/hotspotmanager/blob/main/src/app/dashboard/reports/page.tsx) (Sales reports screen)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and router setup"]
  node_loginui["Login page<br/>[page.tsx]"]
  node_loginapi["Login endpoint<br/>[route.ts]"]
  node_sessions["Signed sessions<br/>[session.ts]"]
  node_sessiongate["Session gate<br/>[proxy.ts]"]
  node_dashboard["Management dashboard<br/>[page.tsx]"]
  node_routerapi["Router management<br/>[route.ts]"]
  node_routerselect["Active router context<br/>[router-context.tsx]"]
end

subgraph group_voucher["Voucher operations"]
  node_voucherui["Voucher screens<br/>[page.tsx]"]
  node_generate["Voucher generation<br/>[route.ts]"]
  node_duration["Profile duration labels<br/>[duration.ts]"]
  node_voucherops["Voucher list and actions<br/>[route.ts]"]
  node_print["Voucher printing<br/>[page.tsx]"]
end

subgraph group_monitor["Monitoring and sync"]
  node_monitorui["Router monitoring screens<br/>[page.tsx]"]
  node_monitorapi["Router monitoring APIs<br/>[route.ts]"]
  node_syncjob["Scheduled sync endpoint<br/>[route.ts]"]
  node_sync["Voucher reconciliation<br/>[sync.ts]"]
  node_mikrotik["RouterOS connection<br/>[mikrotik.ts]"]
  node_ftpapi["Hotspot file endpoints<br/>[route.ts]"]
  node_ftp["Portal FTP manager<br/>[hotspot-ftp.ts]"]
end

subgraph group_reports["Sales reporting"]
  node_reportsui["Sales reports screen<br/>[page.tsx]"]
  node_sales["Sales report API<br/>[route.ts]"]
  node_import["Mikhmon CSV import<br/>[route.ts]"]
  node_export["Excel export<br/>[report-export.ts]"]
end

subgraph group_settings["Portal settings"]
  node_settingsui["Portal settings screen<br/>[page.tsx]"]
  node_settingsapi["Settings API<br/>[route.ts]"]
  node_settings["Settings and pricing<br/>[settings.ts]"]
end

node_admin(("Administrator"))
node_supabase[("Supabase database")]
node_routeros{{"MikroTik routers"}}
node_ftpservice{{"Router FTP service"}}

node_admin -->|"opens"| node_loginui
node_loginui -.->|"submits credentials"| node_loginapi
node_loginapi -->|"creates token"| node_sessions
node_loginapi -->|"checks login records"| node_supabase
node_sessiongate -->|"verifies token"| node_sessions
node_admin -->|"uses"| node_dashboard
node_dashboard -.->|"selects router"| node_routerselect
node_routerapi -->|"reads router records"| node_supabase
node_voucherui -.->|"requests generation"| node_generate
node_generate -->|"opens connection"| node_mikrotik
node_generate -->|"gets duration label"| node_duration
node_generate -->|"stores batch and vouchers"| node_supabase
node_generate -->|"adds hotspot users"| node_routeros
node_voucherui -.->|"manages vouchers"| node_voucherops
node_voucherui -.->|"prints vouchers"| node_print
node_monitorui -.->|"views status"| node_monitorapi
node_monitorapi -->|"queries router"| node_mikrotik
node_syncjob -->|"starts sync"| node_sync
node_sync -->|"reads router state"| node_mikrotik
node_sync -->|"reconciles voucher data"| node_supabase
node_sync -->|"resolves prices"| node_settings
node_ftpapi -->|"delegates file operation"| node_ftp
node_ftp -->|"lists router files"| node_routeros
node_ftp -->|"transfers portal files"| node_ftpservice
node_reportsui -.->|"requests reports"| node_sales
node_sales -->|"reads sales data"| node_supabase
node_reportsui -.->|"imports CSV"| node_import
node_import -->|"upserts imported vouchers"| node_supabase
node_reportsui -.->|"exports workbook"| node_export
node_settingsui -.->|"edits portal settings"| node_settingsapi
node_settingsapi -->|"reads and saves settings"| node_supabase
node_settingsapi -->|"uses defaults"| node_settings

click node_loginui "https://github.com/r14bz/hotspotmanager/blob/main/src/app/login/page.tsx"
click node_loginapi "https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/auth/login/route.ts"
click node_sessions "https://github.com/r14bz/hotspotmanager/blob/main/src/lib/session.ts"
click node_sessiongate "https://github.com/r14bz/hotspotmanager/blob/main/src/proxy.ts"
click node_dashboard "https://github.com/r14bz/hotspotmanager/blob/main/src/app/dashboard/page.tsx"
click node_routerapi "https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/routers/route.ts"
click node_routerselect "https://github.com/r14bz/hotspotmanager/blob/main/src/lib/router-context.tsx"
click node_voucherui "https://github.com/r14bz/hotspotmanager/blob/main/src/app/dashboard/vouchers/page.tsx"
click node_generate "https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/vouchers/generate/route.ts"
click node_duration "https://github.com/r14bz/hotspotmanager/blob/main/src/lib/duration.ts"
click node_voucherops "https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/vouchers/list/route.ts"
click node_print "https://github.com/r14bz/hotspotmanager/blob/main/src/app/print/page.tsx"
click node_monitorui "https://github.com/r14bz/hotspotmanager/blob/main/src/app/dashboard/users/page.tsx"
click node_monitorapi "https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/mikrotik/dashboard/route.ts"
click node_syncjob "https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/cron/sync/route.ts"
click node_sync "https://github.com/r14bz/hotspotmanager/blob/main/src/lib/sync.ts"
click node_mikrotik "https://github.com/r14bz/hotspotmanager/blob/main/src/lib/mikrotik.ts"
click node_ftpapi "https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/mikrotik/hotspot-files/list/route.ts"
click node_ftp "https://github.com/r14bz/hotspotmanager/blob/main/src/lib/hotspot-ftp.ts"
click node_reportsui "https://github.com/r14bz/hotspotmanager/blob/main/src/app/dashboard/reports/page.tsx"
click node_sales "https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/reports/sales/route.ts"
click node_import "https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/reports/import-mikhmon/route.ts"
click node_export "https://github.com/r14bz/hotspotmanager/blob/main/src/lib/report-export.ts"
click node_settingsui "https://github.com/r14bz/hotspotmanager/blob/main/src/app/dashboard/settings/page.tsx"
click node_settingsapi "https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/settings/route.ts"
click node_settings "https://github.com/r14bz/hotspotmanager/blob/main/src/lib/settings.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_loginui,node_loginapi,node_sessions,node_sessiongate,node_dashboard,node_routerapi,node_routerselect toneBlue
class node_voucherui,node_generate,node_duration,node_voucherops,node_print,node_supabase toneAmber
class node_monitorui,node_monitorapi,node_syncjob,node_sync,node_mikrotik,node_ftpapi,node_ftp,node_routeros,node_ftpservice toneMint
class node_reportsui,node_sales,node_import,node_export toneRose
class node_settingsui,node_settingsapi,node_settings,node_admin toneIndigo
```

## Components

### Access and router setup

- [Login page](https://github.com/r14bz/hotspotmanager/blob/main/src/app/login/page.tsx): `src/app/login/page.tsx`
- [Login endpoint](https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/auth/login/route.ts): `src/app/api/auth/login/route.ts`
- [Signed sessions](https://github.com/r14bz/hotspotmanager/blob/main/src/lib/session.ts): `src/lib/session.ts`
- [Session gate](https://github.com/r14bz/hotspotmanager/blob/main/src/proxy.ts): `src/proxy.ts`
- [Management dashboard](https://github.com/r14bz/hotspotmanager/blob/main/src/app/dashboard/page.tsx): `src/app/dashboard/page.tsx`
- [Router management](https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/routers/route.ts): `src/app/api/routers/route.ts`
- [Active router context](https://github.com/r14bz/hotspotmanager/blob/main/src/lib/router-context.tsx): `src/lib/router-context.tsx`

### Voucher operations

- [Voucher screens](https://github.com/r14bz/hotspotmanager/blob/main/src/app/dashboard/vouchers/page.tsx): `src/app/dashboard/vouchers/page.tsx`
- [Voucher generation](https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/vouchers/generate/route.ts): `src/app/api/vouchers/generate/route.ts`
- [Profile duration labels](https://github.com/r14bz/hotspotmanager/blob/main/src/lib/duration.ts): `src/lib/duration.ts`
- [Voucher list and actions](https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/vouchers/list/route.ts): `src/app/api/vouchers/list/route.ts`
- [Voucher printing](https://github.com/r14bz/hotspotmanager/blob/main/src/app/print/page.tsx): `src/app/print/page.tsx`

### Monitoring and sync

- [Router monitoring screens](https://github.com/r14bz/hotspotmanager/blob/main/src/app/dashboard/users/page.tsx): `src/app/dashboard/users/page.tsx`
- [Router monitoring APIs](https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/mikrotik/dashboard/route.ts): `src/app/api/mikrotik/dashboard/route.ts`
- [Scheduled sync endpoint](https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/cron/sync/route.ts): `src/app/api/cron/sync/route.ts`
- [Voucher reconciliation](https://github.com/r14bz/hotspotmanager/blob/main/src/lib/sync.ts): `src/lib/sync.ts`
- [RouterOS connection](https://github.com/r14bz/hotspotmanager/blob/main/src/lib/mikrotik.ts): `src/lib/mikrotik.ts`
- [Hotspot file endpoints](https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/mikrotik/hotspot-files/list/route.ts): `src/app/api/mikrotik/hotspot-files/list/route.ts`
- [Portal FTP manager](https://github.com/r14bz/hotspotmanager/blob/main/src/lib/hotspot-ftp.ts): `src/lib/hotspot-ftp.ts`

### Sales reporting

- [Sales reports screen](https://github.com/r14bz/hotspotmanager/blob/main/src/app/dashboard/reports/page.tsx): `src/app/dashboard/reports/page.tsx`
- [Sales report API](https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/reports/sales/route.ts): `src/app/api/reports/sales/route.ts`
- [Mikhmon CSV import](https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/reports/import-mikhmon/route.ts): `src/app/api/reports/import-mikhmon/route.ts`
- [Excel export](https://github.com/r14bz/hotspotmanager/blob/main/src/lib/report-export.ts): `src/lib/report-export.ts`

### Portal settings

- [Portal settings screen](https://github.com/r14bz/hotspotmanager/blob/main/src/app/dashboard/settings/page.tsx): `src/app/dashboard/settings/page.tsx`
- [Settings API](https://github.com/r14bz/hotspotmanager/blob/main/src/app/api/settings/route.ts): `src/app/api/settings/route.ts`
- [Settings and pricing](https://github.com/r14bz/hotspotmanager/blob/main/src/lib/settings.ts): `src/lib/settings.ts`

### Other components

- **Administrator**
- **Supabase database**
- **MikroTik routers**
- **Router FTP service**

## Connections

- Administrator → Login page: opens (evidence: `README.md`)
- Login page → Login endpoint: submits credentials (evidence: `README.md`)
- Login endpoint → Signed sessions: creates token (evidence: `src/app/api/auth/login/route.ts`)
- Login endpoint → Supabase database: checks login records (evidence: `src/app/api/auth/login/route.ts`)
- Session gate → Signed sessions: verifies token (evidence: `src/proxy.ts`)
- Administrator → Management dashboard: uses (evidence: `README.md`)
- Management dashboard → Active router context: selects router (evidence: `README.md`)
- Router management → Supabase database: reads router records (evidence: `src/app/api/routers/route.ts`)
- Voucher screens → Voucher generation: requests generation (evidence: `README.md`)
- Voucher generation → RouterOS connection: opens connection (evidence: `src/app/api/vouchers/generate/route.ts`)
- Voucher generation → Profile duration labels: gets duration label (evidence: `src/app/api/vouchers/generate/route.ts`)
- Voucher generation → Supabase database: stores batch and vouchers (evidence: `src/app/api/vouchers/generate/route.ts`)
- Voucher generation → MikroTik routers: adds hotspot users (evidence: `src/app/api/vouchers/generate/route.ts`)
- Voucher screens → Voucher list and actions: manages vouchers (evidence: `README.md`)
- Voucher screens → Voucher printing: prints vouchers (evidence: `README.md`)
- Router monitoring screens → Router monitoring APIs: views status (evidence: `README.md`)
- Router monitoring APIs → RouterOS connection: queries router (evidence: `src/app/api/mikrotik/dashboard/route.ts`)
- Scheduled sync endpoint → Voucher reconciliation: starts sync (evidence: `src/app/api/cron/sync/route.ts`)
- Voucher reconciliation → RouterOS connection: reads router state (evidence: `src/lib/sync.ts`)
- Voucher reconciliation → Supabase database: reconciles voucher data (evidence: `src/lib/sync.ts`)
- Voucher reconciliation → Settings and pricing: resolves prices (evidence: `src/lib/sync.ts`)
- Hotspot file endpoints → Portal FTP manager: delegates file operation (evidence: `src/app/api/mikrotik/hotspot-files/list/route.ts`)
- Portal FTP manager → MikroTik routers: lists router files (evidence: `src/lib/hotspot-ftp.ts`)
- Portal FTP manager → Router FTP service: transfers portal files (evidence: `README.md`)
- Sales reports screen → Sales report API: requests reports (evidence: `README.md`)
- Sales report API → Supabase database: reads sales data (evidence: `src/app/api/reports/sales/route.ts`)
- Sales reports screen → Mikhmon CSV import: imports CSV (evidence: `README.md`)
- Mikhmon CSV import → Supabase database: upserts imported vouchers (evidence: `src/app/api/reports/import-mikhmon/route.ts`)
- Sales reports screen → Excel export: exports workbook (evidence: `README.md`)
- Portal settings screen → Settings API: edits portal settings (evidence: `README.md`)
- Settings API → Supabase database: reads and saves settings (evidence: `src/app/api/settings/route.ts`)
- Settings API → Settings and pricing: uses defaults (evidence: `src/app/api/settings/route.ts`)
