# quantum-label/quantum_labelling_tool architecture

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

- Interactive diagram: https://gitdiagram.com/quantum-label/quantum_labelling_tool
- Repository: https://github.com/quantum-label/quantum_labelling_tool

## Overview

##### Project Type and Purpose
- This is a full-stack Django web application (“QUANTUM Data Quality Labelling Tool”) designed to let data holders catalogue datasets, assess their quality, generate labels/certificates in RDF, and download them.
- Key use cases: guided dataset evaluation, certificate generation (PDF + RDF), visualization dashboards, compliance with HealthDCAT-AP/DCAT/DQV.

##### High-Level File Structure Analysis
- Top-level Django app:
- quantum/ (settings, URLs, WSGI/ASGI)
- manage.py
- webapp/ (models, views, templates, migrations, admin)
- templates/ & static/ (project-wide UI assets)
- staticfiles/ (collected static assets)
- Modular code under code/:
- code/fdp/ – functions to query Federated Data Points (FDP) and build certificate metadata
- code/label/ – HTML/PDF label generation (template engine, CSS/fonts, PDF creator)
- code/rdf/ – TTL templating for RDF export
- code/helpers/ – shared utilities (e.g., Django integrations)
- Configuration & deployment:
- docker/ (Dockerfile, docker-compose.yml, .env, init SQL)
- requirements.txt / requirements.in
- db.sqlite3 (development DB)

##### README Insights
- Technology stack: Python 3.11+, Django backend, Bootstrap-based HTML/CSS/JS frontend, SQLite (dev) or MariaDB (prod via Docker).
- Docker compose orchestrates two containers: webapp and database.
- Initial data loaded from docker/init/init.sql into MariaDB.
- Core flows: HTTP requests → Django views → ORM → DB; certificate generation via specialized modules; static/template rendering.

##### Main Components
a. Frontend Layer
- Browser UI
- Static assets (CSS, JS) and HTML templates (Bootstrap)
- Entry points: home, login, dashboards, dataset/catalogue forms, label download
b. Backend Layer
- Django web server (Django REST/views)
- URL router (quantum/urls.py → webapp/views.py)
- Business logic modules under code/ (fdp, label, rdf)
- ORM layer (webapp/models.py → SQLite3 or MariaDB)
c. Data Layer
- Development: SQLite3
- Production: MariaDB (Docker “database” service) initialized by init.sql
d. Docker & Deployment
- docker-compose: quantumtoolwebapp + quantumtooldatabase services
- Environment configuration (.env)
- build/run commands
e. External Systems
- FDP endpoints (queried by code/fdp)
- Certificate download (PDF)
- RDF export (TTL)

##### Relationships and Interactions
- Browser ↔ Django HTTP endpoints (GET/POST for forms, JSON or HTML responses)
- Django Views → Templates + Static (render UI)
- Views → code/fdp for metadata retrieval → code/label for PDF → code/rdf for TTL
- Django ORM → Database (read/write catalogue, dataset, assessment records)
- Docker network: webapp ↔ database (TCP 3306)

##### Architectural Patterns & Design Principles
- MVC (Model in webapp/models, Views in webapp/views, Templates)
- Modular separation of concerns:
- code/fdp (data retrieval)
- code/label (presentation generation)
- code/rdf (semantic export)
- Containerization for reproducibility and isolation
- Use of Django migrations for schema evolution

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer" 
        direction TB
        Browser["Browser (User)"]:::frontend
        Templates["HTML Templates"]:::frontend
        AppTemplates["App-specific Templates"]:::frontend
        StaticDev["Static Assets (dev)"]:::frontend
        StaticCol["Collected Static"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer" 
        direction TB
        DjangoServer["Django Web Server"]:::backend
        subgraph "Project Configuration"
            direction TB
            ManagePy["manage.py"]:::backend
            Settings["quantum/settings.py"]:::backend
            Urls["quantum/urls.py"]:::backend
            Asgi["quantum/asgi.py"]:::backend
            Wsgi["quantum/wsgi.py"]:::backend
        end
        subgraph "MVC Components"
            direction TB
            Models["webapp/models.py"]:::backend
            Views["webapp/views.py"]:::backend
            Admin["webapp/admin.py"]:::backend
            Tests["webapp/tests.py"]:::backend
            Migrations["webapp/migrations"]:::backend
        end
        subgraph "Business Logic Modules"
            direction TB
            FDP["code/fdp"]:::backend
            Label["code/label"]:::backend
            RDF["code/rdf"]:::backend
            Helpers["code/helpers/django.py"]:::backend
        end
    end

    %% Data Layer
    subgraph "Data Layer" 
        direction TB
        SQLite["SQLite3 (db.sqlite3)"]:::db
        MariaDB["MariaDB (Docker Service)"]:::db
    end

    %% Docker & Deployment
    subgraph "Docker & Deployment"
        direction TB
        Compose["docker-compose"]:::backend
        Dockerfile["docker/Dockerfile"]:::backend
        Env["docker/.env"]:::backend
        InitSQL["docker/init/init.sql"]:::backend
    end

    %% External Services
    ExternalFDP["External FDP API"]:::external

    %% Connections
    Browser -->|"HTTP GET/POST"| DjangoServer
    DjangoServer -->|"renders"| Templates
    DjangoServer -->|"renders"| AppTemplates
    DjangoServer -->|"serves"| StaticDev
    DjangoServer -->|"serves"| StaticCol

    DjangoServer -->|"+urls.py"| Urls
    DjangoServer -->|calls| Views
    Views -->|uses ORM| Models
    Views -->|registers| Admin
    Views -->|runs tests| Tests
    Views -->|applies migrations| Migrations

    DjangoServer -->|function calls| FDP
    DjangoServer -->|function calls| Label
    DjangoServer -->|function calls| RDF
    DjangoServer -->|imports| Helpers

    Models -->|ORM Query| SQLite
    Models -->|ORM Query| MariaDB

    FDP -->|HTTP requests| ExternalFDP
    Label -->|generates PDF| Browser
    RDF -->|exports TTL| Browser

    Compose -->|orchestrates| DjangoServer
    Compose -->|orchestrates| MariaDB
    Compose -->|loads init script| InitSQL
    Compose -->|uses env| Env
    Compose -->|builds| Dockerfile

    %% Click Events
    click Templates "https://github.com/quantum-label/quantum_labelling_tool/tree/main/templates/"
    click AppTemplates "https://github.com/quantum-label/quantum_labelling_tool/tree/main/webapp/templates/"
    click StaticDev "https://github.com/quantum-label/quantum_labelling_tool/tree/main/static/"
    click StaticCol "https://github.com/quantum-label/quantum_labelling_tool/tree/main/staticfiles/"
    click ManagePy "https://github.com/quantum-label/quantum_labelling_tool/blob/main/manage.py"
    click Settings "https://github.com/quantum-label/quantum_labelling_tool/blob/main/quantum/settings.py"
    click Urls "https://github.com/quantum-label/quantum_labelling_tool/blob/main/quantum/urls.py"
    click Asgi "https://github.com/quantum-label/quantum_labelling_tool/blob/main/quantum/asgi.py"
    click Wsgi "https://github.com/quantum-label/quantum_labelling_tool/blob/main/quantum/wsgi.py"
    click Models "https://github.com/quantum-label/quantum_labelling_tool/blob/main/webapp/models.py"
    click Views "https://github.com/quantum-label/quantum_labelling_tool/blob/main/webapp/views.py"
    click Admin "https://github.com/quantum-label/quantum_labelling_tool/blob/main/webapp/admin.py"
    click Tests "https://github.com/quantum-label/quantum_labelling_tool/blob/main/webapp/tests.py"
    click Migrations "https://github.com/quantum-label/quantum_labelling_tool/tree/main/webapp/migrations/"
    click FDP "https://github.com/quantum-label/quantum_labelling_tool/tree/main/code/fdp/"
    click Label "https://github.com/quantum-label/quantum_labelling_tool/tree/main/code/label/"
    click RDF "https://github.com/quantum-label/quantum_labelling_tool/tree/main/code/rdf/"
    click Helpers "https://github.com/quantum-label/quantum_labelling_tool/blob/main/code/helpers/django.py"
    click SQLite "https://github.com/quantum-label/quantum_labelling_tool/blob/main/db.sqlite3"
    click Compose "https://github.com/quantum-label/quantum_labelling_tool/blob/main/docker/docker-compose.yml"
    click Dockerfile "https://github.com/quantum-label/quantum_labelling_tool/tree/main/docker/Dockerfile"
    click Env "https://github.com/quantum-label/quantum_labelling_tool/blob/main/docker/.env"
    click InitSQL "https://github.com/quantum-label/quantum_labelling_tool/blob/main/docker/init/init.sql"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366D6,color:#0366D6
    classDef backend fill:#D0FFD6,stroke:#228B22,color:#228B22
    classDef db fill:#FFE4B5,stroke:#FF8C00,color:#FF8C00
    classDef external fill:#E0E0E0,stroke:#808080,color:#808080
```
