# korenkov/haas_mdc architecture

> Architecture diagram of the GitHub repository korenkov/haas_mdc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/korenkov/haas_mdc
- Repository: https://github.com/korenkov/haas_mdc

## Overview

##### Main Components
a. External CNC Machine
– The actual HAAS VF-2 CNC hardware, reachable over Ethernet or wireless.
b. Data Collection Service
– data_collection/main.py: orchestrates periodic data pulls.
– telnet.py + cnc_emulator*.py: encapsulate the Telnet protocol (production and emulators for testing).
– configs/network.ini & params.ini: supply connection settings and macro variable lists.
– create_schema.py: initializes the SQLite (or similar) database schema.
c. Database (Data Store)
– A lightweight file-based database (e.g., SQLite) created/updated by the Data Collection Service.
d. Visualization Web Service
– visualization/main.py: a small HTTP server (e.g., Flask or Bottle) serving dashboards.
– visualization/db.py: data-access layer for querying stored CNC data.
– visualization/chartjs.py + utils.py: build Chart.js data payloads.
– templates/*.html: Jinja2 templates for the UI pages.
e. Client Browser
– End user’s browser rendering the HTML + Chart.js charts served by the Visualization Web Service.

##### Relationships & Data Flows
– CNC Machine → (Telnet) → Data Collection Service
– Data Collection Service → (Write) → Database
– Visualization Web Service → (Read) → Database
– Visualization Web Service → (HTTP Response) → Client Browser
– Client Browser → (HTTP Request) → Visualization Web Service

##### Architectural Patterns
– Separation of concerns:
- Data Ingestion Layer (data_collection)
- Data Persistence Layer (database)
- Presentation Layer (visualization + browser)
– Configuration-driven behavior via INI files.
– Modular emulation for testing (cnc_emulator modules).
– Simple request-response web service (Flask/Bottle style).
– Client-side chart rendering with Chart.js (embedded via templates).

##### Relevant Technologies
– Telnet protocol (Python telnetlib wrapper in telnet.py)
– SQLite (or similar) for local storage
– Flask or Bottle for the HTTP server in visualization/main.py
– Jinja2 for HTML templates
– Chart.js for dynamic charts in the browser
– Python 3.x (see requirements.txt for versions)

## Diagram (Mermaid)

```mermaid
flowchart TD
    CNC["HAAS VF-2 CNC Machine"]:::external

    subgraph "Data Collection Service" 
        direction TB
        DCmain["data_collection/main.py"]:::backend
        Telnet["telnet.py"]:::backend
        CreateSchema["data_collection/create_schema.py"]:::backend
        subgraph "Testing Modules"
            direction TB
            E1["data_collection/cnc_emulator.py"]:::backend
            E2["data_collection/cnc_emulator2.py"]:::backend
            E3["data_collection/cnc_emulator3.py"]:::backend
        end
        subgraph "Configs"
            direction TB
            C1["data_collection/configs/network.ini"]:::backend
            C2["data_collection/configs/params.ini"]:::backend
        end
    end

    subgraph "Database (SQLite)" 
        DB[(SQLite DB)]:::db
    end

    subgraph "Visualization Web Service"
        direction TB
        VisMain["visualization/main.py"]:::backend
        DBAccess["visualization/db.py"]:::backend
        ChartJS["visualization/chartjs.py"]:::backend
        Utils["visualization/utils.py"]:::backend
        subgraph "Templates"
            direction TB
            T1["visualization/templates/index.html"]:::frontend
            T2["visualization/templates/new_chart.html"]:::frontend
            T3["visualization/templates/_charts/multi-y-axes-line-chart.html"]:::frontend
            T4["visualization/templates/_charts/timeline-chart.html"]:::frontend
        end
    end

    Browser["Client Browser"]:::frontend

    CNC -->|"Telnet Pull"| DCmain
    DCmain -->|"uses Telnet"| Telnet
    Telnet -->|"Collect Data"| DCmain
    DCmain -->|"Initialize Schema"| CreateSchema
    DCmain -->|"Write INSERT"| DB
    VisMain -->|"SELECT"| DB
    Browser -->|"HTTP Request"| VisMain
    VisMain -->|"HTTP Response"| Browser

    click DCmain "https://github.com/korenkov/haas_mdc/blob/master/data_collection/main.py"
    click Telnet "https://github.com/korenkov/haas_mdc/blob/master/telnet.py"
    click CreateSchema "https://github.com/korenkov/haas_mdc/blob/master/data_collection/create_schema.py"
    click E1 "https://github.com/korenkov/haas_mdc/blob/master/data_collection/cnc_emulator.py"
    click E2 "https://github.com/korenkov/haas_mdc/blob/master/data_collection/cnc_emulator2.py"
    click E3 "https://github.com/korenkov/haas_mdc/blob/master/data_collection/cnc_emulator3.py"
    click C1 "https://github.com/korenkov/haas_mdc/blob/master/data_collection/configs/network.ini"
    click C2 "https://github.com/korenkov/haas_mdc/blob/master/data_collection/configs/params.ini"
    click VisMain "https://github.com/korenkov/haas_mdc/blob/master/visualization/main.py"
    click DBAccess "https://github.com/korenkov/haas_mdc/blob/master/visualization/db.py"
    click ChartJS "https://github.com/korenkov/haas_mdc/blob/master/visualization/chartjs.py"
    click Utils "https://github.com/korenkov/haas_mdc/blob/master/visualization/utils.py"
    click T1 "https://github.com/korenkov/haas_mdc/blob/master/visualization/templates/index.html"
    click T2 "https://github.com/korenkov/haas_mdc/blob/master/visualization/templates/new_chart.html"
    click T3 "https://github.com/korenkov/haas_mdc/blob/master/visualization/templates/_charts/multi-y-axes-line-chart.html"
    click T4 "https://github.com/korenkov/haas_mdc/blob/master/visualization/templates/_charts/timeline-chart.html"

    classDef backend fill:#E3F2FD,stroke:#2196F3,color:#0D47A1;
    classDef db fill:#E8F5E9,stroke:#43A047,color:#1B5E20;
    classDef frontend fill:#FFF3E0,stroke:#FB8C00,color:#E65100;
    classDef external fill:#ECEFF1,stroke:#90A4AE,color:#37474F;
```
