# hinnuryuu/ujn-temperature-reporter architecture

> Architecture diagram of the GitHub repository hinnuryuu/ujn-temperature-reporter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hinnuryuu/ujn-temperature-reporter
- Repository: https://github.com/hinnuryuu/ujn-temperature-reporter

## Overview

##### Project Type and Purpose
- This is an automation + monitoring script (Python) with an optional web UI.
- Purpose: Log in to UJN SSO daily, submit the user’s body-temperature form automatically, manage multiple users, and optionally display status via a Flask dashboard.

##### File Structure
- Top-level scripts:
- app.py – Flask web UI entry point
- start.py – long-running scheduler that triggers the daily task
- task.py – orchestrates “fetch users → encrypt → login → submit form”
- database_manager.py – handles user credentials storage and retrieval
- des.py – RSA/JS encryption logic via pyexecjs (des.js wrapper)
- report.py – HTTP POST/GET wrapper for the report endpoints
- templates/index.html – HTML template for the Flask dashboard

##### README Insights
- Key libraries: pyexecjs (DES/RSA encryption), requests (HTTP), apschedule (scheduling), flask (monitoring UI)
- Usage patterns: daily 6 PM trigger, credentials stored via database_manager, encryption via des.js

a. Scheduler Component (APScheduler in start.py)
b. Task Controller (task.py)
c. User Store (database_manager.py)
d. Encryption Module (des.py + pyexecjs + des.js)
e. HTTP Client (report.py + requests)
f. External Services:
- UJN SSO (login endpoint)
- UJN Temperature Submission API
g. Optional Dashboard (app.py + Flask + templates/index.html)

##### Relationships & Data Flows
1. Scheduler triggers Task Controller once per day.
2. Task Controller queries User Store for all user credentials.
3. For each user:
– Pass credentials into Encryption Module → obtain encrypted payload.
– Use HTTP Client to POST login → receive Session token.
– Use HTTP Client to POST temperature report with Session.
4. Task Controller logs success/failure back to User Store or a log.
5. Dashboard (Flask) queries User Store or logs to display current status.

##### Architectural Patterns & Principles
- Modular separation:
- Data layer (database_manager.py)
- Business logic (task.py, report.py)
- Crypto layer (des.py)
- Orchestration/scheduling (start.py)
- Presentation (Flask UI)
- Single responsibility per module
- Asynchronous/periodic execution via APScheduler
- Clear external system boundary: UJN SSO & reporting API

##### Technologies & Libraries to Annotate
- Python 3.9
- pyexecjs + des.js (RSA encryption)
- requests (HTTP)
- APScheduler (job scheduling)
- Flask + Jinja2 templates

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Python Application"
        Scheduler["Scheduler (APScheduler)"]:::service
        TaskCtrl["Task Controller"]:::service
        Encryption["Encryption Module"]:::service
        HTTPClient["HTTP Client"]:::service
        UserStore["User Store (User DB)"]:::data
    end

    subgraph "Flask Dashboard"
        FlaskApp["Flask App"]:::service
        Template["Jinja2 Template"]:::service
    end

    CloudSSO["UJN SSO"]:::external
    CloudReport["UJN Temperature API"]:::external

    Scheduler -->|"Trigger job (daily 6PM)"| TaskCtrl
    TaskCtrl -->|"Read creds"| UserStore
    TaskCtrl -->|"Encrypt payload"| Encryption
    Encryption -->|"Encrypted data"| TaskCtrl
    TaskCtrl -->|"POST login"| HTTPClient
    HTTPClient -->|"login request"| CloudSSO
    CloudSSO -->|"session token"| HTTPClient
    TaskCtrl -->|"POST report"| HTTPClient
    HTTPClient -->|"report request"| CloudReport
    CloudReport -->|"report response"| HTTPClient
    TaskCtrl -->|"Log result"| UserStore
    FlaskApp -->|"Fetch status"| UserStore
    FlaskApp -->|"Render UI"| Template

    click Scheduler "https://github.com/hinnuryuu/ujn-temperature-reporter/blob/main/start.py"
    click TaskCtrl "https://github.com/hinnuryuu/ujn-temperature-reporter/blob/main/task.py"
    click UserStore "https://github.com/hinnuryuu/ujn-temperature-reporter/blob/main/database_manager.py"
    click Encryption "https://github.com/hinnuryuu/ujn-temperature-reporter/blob/main/des.py"
    click HTTPClient "https://github.com/hinnuryuu/ujn-temperature-reporter/blob/main/report.py"
    click FlaskApp "https://github.com/hinnuryuu/ujn-temperature-reporter/blob/main/app.py"
    click Template "https://github.com/hinnuryuu/ujn-temperature-reporter/blob/main/templates/index.html"

    classDef service fill:#e0f7fa,stroke:#006064,stroke-width:1px
    classDef data fill:#e8eaf6,stroke:#3f51b5,stroke-width:2px
    classDef external fill:#fff3e0,stroke:#e65100,stroke-width:1px,stroke-dasharray: 5 5
    class Scheduler,TaskCtrl,Encryption,HTTPClient,FlaskApp service
    class UserStore data
    class CloudSSO,CloudReport external
```
