# magnat12/msm architecture

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

- Interactive diagram: https://gitdiagram.com/magnat12/msm
- Repository: https://github.com/magnat12/msm

## Overview

This is a Django shift-management backend: Hikvision access events are fetched and parsed, matched to employee schedules, and saved as daily work records; completed shifts move to history and can be exported to Excel. A separate Telegram bot can trigger scheduled web requests and download a report. The graph follows the documented sync command and sampled integrations; view and model internals were not sampled, and the bot’s `/test/` report URL does not match the documented `/excel/` route.

Main entry points: [`bot/main.py`](https://github.com/magnat12/msm/blob/main/bot/main.py) (Telegram bot), [`msaproject/hik/views.py`](https://github.com/magnat12/msm/blob/main/msaproject/hik/views.py) (HTTP views), [`msaproject/hik/management/commands/sync_hikvision.py`](https://github.com/magnat12/msm/blob/main/msaproject/hik/management/commands/sync_hikvision.py) (Sync command), [`msaproject/hik/models.py`](https://github.com/magnat12/msm/blob/main/msaproject/hik/models.py) (Attendance records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_acquisition["Event acquisition"]
  node_fetch["Event fetch and parse<br/>[getevent.py]"]
  node_sync["Sync command<br/>[sync_hikvision.py]"]
end

subgraph group_attendance["Shift processing"]
  node_attendance["Attendance matching<br/>[attendance.py]"]
  node_models["Attendance records<br/>[models.py]"]
  node_history["History transition<br/>[signals.py]"]
  node_store[("Application database<br/>[settings.py]")]
end

subgraph group_reporting["Reports and bot"]
  node_excel["Excel export<br/>[excel.py]"]
  node_bot["Telegram bot<br/>[main.py]"]
  node_report_download["Report download<br/>[report.py]"]
end

subgraph group_platform["Django platform"]
  node_views["HTTP views<br/>[views.py]"]
  node_routes["URL routing<br/>[urls.py]"]
end

node_operator(("Operator"))
node_hikvision{{"Hikvision device"}}
node_telegram(("Telegram user"))

node_operator -->|"runs sync"| node_sync
node_sync -->|"fetches events"| node_fetch
node_fetch -->|"requests events"| node_hikvision
node_sync -->|"passes reports"| node_attendance
node_attendance -->|"creates or updates"| node_models
node_models -->|"persists records"| node_store
node_models -->|"post-save signal"| node_history
node_history -->|"archives shifts"| node_store
node_routes -->|"routes requests"| node_views
node_views -->|"exports report"| node_excel
node_excel -->|"reads history"| node_store
node_telegram -.->|"sends commands"| node_bot
node_bot -.->|"requests HTTP endpoints"| node_views
node_bot -->|"downloads report"| node_report_download
node_report_download -.->|"requests report URL"| node_views
node_bot -.->|"sends report"| node_telegram

click node_fetch "https://github.com/magnat12/msm/blob/main/msaproject/hik/services/getevent.py"
click node_sync "https://github.com/magnat12/msm/blob/main/msaproject/hik/management/commands/sync_hikvision.py"
click node_attendance "https://github.com/magnat12/msm/blob/main/msaproject/hik/services/attendance.py"
click node_models "https://github.com/magnat12/msm/blob/main/msaproject/hik/models.py"
click node_history "https://github.com/magnat12/msm/blob/main/msaproject/hik/signals.py"
click node_store "https://github.com/magnat12/msm/blob/main/msaproject/msa/settings.py"
click node_excel "https://github.com/magnat12/msm/blob/main/msaproject/hik/services/excel.py"
click node_views "https://github.com/magnat12/msm/blob/main/msaproject/hik/views.py"
click node_routes "https://github.com/magnat12/msm/blob/main/msaproject/msa/urls.py"
click node_bot "https://github.com/magnat12/msm/blob/main/bot/main.py"
click node_report_download "https://github.com/magnat12/msm/blob/main/bot/report.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_fetch,node_sync,node_telegram toneBlue
class node_attendance,node_models,node_history,node_store toneAmber
class node_excel,node_bot,node_report_download toneMint
class node_views,node_routes toneRose
class node_operator,node_hikvision toneIndigo
```

## Components

### Event acquisition

- [Event fetch and parse](https://github.com/magnat12/msm/blob/main/msaproject/hik/services/getevent.py): `msaproject/hik/services/getevent.py`
- [Sync command](https://github.com/magnat12/msm/blob/main/msaproject/hik/management/commands/sync_hikvision.py): `msaproject/hik/management/commands/sync_hikvision.py`

### Shift processing

- [Attendance matching](https://github.com/magnat12/msm/blob/main/msaproject/hik/services/attendance.py): `msaproject/hik/services/attendance.py`
- [Attendance records](https://github.com/magnat12/msm/blob/main/msaproject/hik/models.py): `msaproject/hik/models.py`
- [History transition](https://github.com/magnat12/msm/blob/main/msaproject/hik/signals.py): `msaproject/hik/signals.py`
- [Application database](https://github.com/magnat12/msm/blob/main/msaproject/msa/settings.py): `msaproject/msa/settings.py`

### Reports and bot

- [Excel export](https://github.com/magnat12/msm/blob/main/msaproject/hik/services/excel.py): `msaproject/hik/services/excel.py`
- [Telegram bot](https://github.com/magnat12/msm/blob/main/bot/main.py): `bot/main.py`
- [Report download](https://github.com/magnat12/msm/blob/main/bot/report.py): `bot/report.py`

### Django platform

- [HTTP views](https://github.com/magnat12/msm/blob/main/msaproject/hik/views.py): `msaproject/hik/views.py`
- [URL routing](https://github.com/magnat12/msm/blob/main/msaproject/msa/urls.py): `msaproject/msa/urls.py`

### Other components

- **Operator**
- **Hikvision device**
- **Telegram user**

## Connections

- Operator → Sync command: runs sync
- Sync command → Event fetch and parse: fetches events
- Event fetch and parse → Hikvision device: requests events
- Sync command → Attendance matching: passes reports
- Attendance matching → Attendance records: creates or updates
- Attendance records → Application database: persists records
- Attendance records → History transition: post-save signal
- History transition → Application database: archives shifts
- URL routing → HTTP views: routes requests
- HTTP views → Excel export: exports report
- Excel export → Application database: reads history
- Telegram user → Telegram bot: sends commands
- Telegram bot → HTTP views: requests HTTP endpoints
- Telegram bot → Report download: downloads report
- Report download → HTTP views: requests report URL
- Telegram bot → Telegram user: sends report
