# rafacalassara/fluke_dewk_1620a_project architecture

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

- Interactive diagram: https://gitdiagram.com/rafacalassara/fluke_dewk_1620a_project
- Repository: https://github.com/rafacalassara/fluke_dewk_1620a_project

## Overview

##### Project type and purpose
- This is a full-stack Django web application with real-time device communication. It manages Fluke DewK 1620A thermohygrometers, collects streaming data, stores it in SQLite, and exposes both web pages (Django templates) and a REST/WebSocket API for data visualization and control.

##### Main components
a. Frontend (Browser)
- HTML templates (fluke_data/templates/…)
- CSS (static/css/styles.css)
- JavaScript modules (static/js/*.js) for REST calls and WebSocket real-time updates
b. Backend Application
- Django ASGI/WSGI server (fluke_dewk_1620A_project/asgi.py & wsgi.py)
- URL router (fluke_dewk_1620A_project/urls.py & fluke_data/urls.py & fluke_data/api/urls.py)
- Django apps:
- fluke_data (models, forms, views, templates)
- fluke_data/api (REST views for sensor, certificate, analysis, export)
- Real-time layer:
- consumers.py & routing.py (Django Channels for live data)
- connection_manager.py (manages connections to device streams)
c. Device Integration
- PyVISA interface (thermohygrometer/thermohygrometer.py & fluke_data/visa_communication.py)
- Fluke DewK 1620A Thermohygrometer (Ethernet/USB device)
d. Database
- SQLite (configured in fluke_dewk_1620A_project/settings.py)
e. Deployment & Containerization
- Dockerfile & docker-compose.yml defining application container
- UV package manager for virtual env (pyproject.toml, uv.lock)

##### Relationships and data flows
- The user’s browser sends HTTP requests (page loads, REST calls) to the Django server.
- JS on the client subscribes to WebSocket channels for real-time updates.
- Django Channels routes WebSocket events to consumers, which push data to clients.
- Consumers and Django views both invoke connection_manager → visa_communication → thermohygrometer driver to poll or push commands to the physical device.
- Device readings flow back through the driver into Python, then to:
- Django Channels (live stream)
- Django ORM (persist in SQLite)
- REST endpoints for on-demand queries or export
- Admin/users interact via Django’s standard WSGI routes for CRUD (models, forms, templates).

##### Architectural patterns & design principles
- MVC/MVT: Models (fluke_data/models.py) → Views (Django views & API views) → Templates (HTML)
- Layered Architecture:
- Presentation Layer (templates + JS)
- Application Layer (Django views, REST API)
- Real-time Layer (Channels consumers)
- Domain Layer (models, business logic in crews, analysis tools)
- Infrastructure Layer (PyVISA driver, SQLite DB)
- Modularization by feature: fluke_data/api, fluke_data/crews, fluke_data/templates/fluke_data/...
- Separation of concerns: device driver separate from web logic.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser["Browser"]:::user
        Templates["HTML Templates"]:::frontend
        CSS["CSS Styles"]:::frontend
        JS["JavaScript Modules"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        WSGI["Django WSGI Server"]:::backend
        ASGI["Django ASGI Server"]:::backend
        URLProject["Project URL Router"]:::backend
        URLApp["App URL Router"]:::backend
        URLAPI["API URL Router"]:::backend
        Views["Django Views (Pages & CRUD)"]:::backend
        Models["Django Models"]:::backend
        Forms["Django Forms"]:::backend
        API_Sensor["Sensor API View"]:::backend
        API_Cert["Certificate API View"]:::backend
        API_CrewAna["Crew Analysis API View"]:::backend
        API_EnvAna["Environmental Analysis API View"]:::backend
        API_Export["Export Data API View"]:::backend
        API_Thermo["Thermohygrometer API View"]:::backend
    end

    %% Real-time Layer
    subgraph "Real-time Layer"
        ChannelRt["Channels Routing"]:::realtime
        Consumers["Real-time Consumers"]:::realtime
        ConnMgr["Connection Manager"]:::infrastructure
    end

    %% Domain Layer
    subgraph "Domain Layer"
        CrewsDir["Crews Module"]:::domain
        CrewDef["Crew Definitions"]:::domain
        DataTools["Data Analysis Tools"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        Driver["Thermohygrometer Driver"]:::device
        VISA["PyVISA Adapter"]:::device
        DB["SQLite Database"]:::storage
    end

    %% Containerization
    subgraph "Containerization"
        DockerfileNode["Dockerfile"]:::container
        Compose["docker-compose.yml"]:::container
        PyProj["pyproject.toml & uv.lock"]:::container
    end

    %% External Device
    Fluke["Fluke DewK 1620A Device"]:::device_ext

    %% Interactions
    Browser -->|"HTTP/REST"| WSGI
    Browser -->|"WebSocket"| ASGI
    ASGI --> ChannelRt
    ChannelRt --> Consumers
    Consumers --> ConnMgr
    WSGI --> URLProject
    URLProject --> URLApp
    URLApp --> URLAPI
    URLAPI --> API_Sensor
    URLAPI --> API_Cert
    URLAPI --> API_CrewAna
    URLAPI --> API_EnvAna
    URLAPI --> API_Export
    URLAPI --> API_Thermo
    URLApp --> Views
    Views --> Models
    Views --> Forms
    API_Sensor --> Models
    API_Cert --> Models
    API_CrewAna --> Models
    API_EnvAna --> Models
    API_Export --> Models
    API_Thermo --> Models
    Models --> DB
    Consumers --> Models
    Consumers --> DB
    Views --> ConnMgr
    API_Sensor --> ConnMgr
    API_Thermo --> ConnMgr
    ConnMgr --> VISA
    VISA --> Driver
    Driver -->|"VISA/Ethernet"| Fluke

    Browser --> Templates
    Browser --> CSS
    Browser --> JS

    %% Click Events
    click Templates "https://github.com/rafacalassara/fluke_dewk_1620a_project/tree/master/fluke_data/templates/fluke_data/"
    click CSS "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/static/css/styles.css"
    click JS "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/static/js/*.js"
    click ASGI "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_dewk_1620A_project/asgi.py"
    click WSGI "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_dewk_1620A_project/wsgi.py"
    click URLProject "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_dewk_1620A_project/urls.py"
    click URLApp "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/urls.py"
    click URLAPI "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/api/urls.py"
    click API_Sensor "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/api/views/sensor.py"
    click API_Cert "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/api/views/certificate.py"
    click API_CrewAna "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/api/views/crew_analysis.py"
    click API_EnvAna "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/api/views/environmental_analysis.py"
    click API_Export "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/api/views/export_data.py"
    click API_Thermo "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/api/views/thermohygrometer.py"
    click Consumers "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/consumers.py"
    click ChannelRt "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/routing.py"
    click ConnMgr "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/connection_manager.py"
    click VISA "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/visa_communication.py"
    click Driver "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/thermohygrometer/thermohygrometer.py"
    click Models "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/models.py"
    click Forms "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/forms.py"
    click Views "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/views.py"
    click CrewsDir "https://github.com/rafacalassara/fluke_dewk_1620a_project/tree/master/fluke_data/crews/"
    click CrewDef "https://github.com/rafacalassara/fluke_dewk_1620a_project/tree/master/fluke_data/crews/crews_definition/"
    click DataTools "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_data/crews/tools/data_analysis_tools.py"
    click DB "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/fluke_dewk_1620A_project/settings.py"
    click DockerfileNode "https://github.com/rafacalassara/fluke_dewk_1620a_project/tree/master/Dockerfile"
    click Compose "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/docker-compose.yml"
    click PyProj "https://github.com/rafacalassara/fluke_dewk_1620a_project/blob/master/pyproject.toml"

    %% Styles
    classDef frontend fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef backend fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef realtime fill:#e6e6e6,stroke:#333,stroke-width:1px
    classDef domain fill:#fff2cc,stroke:#333,stroke-width:1px
    classDef infrastructure fill:#dddddd,stroke:#333,stroke-width:1px
    classDef storage fill:#ffdead,stroke:#333,stroke-width:1px
    classDef container fill:#ffffcc,stroke:#333,stroke-width:1px
    classDef device fill:#dddddd,stroke:#333,stroke-width:1px
    classDef device_ext fill:#bbbbbb,stroke:#333,stroke-width:1px
    classDef user fill:#ccffcc,stroke:#333,stroke-width:1px
```
