# ppaauuoo/paper_cutting_project architecture

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

- Interactive diagram: https://gitdiagram.com/ppaauuoo/paper_cutting_project
- Repository: https://github.com/ppaauuoo/paper_cutting_project

## Overview

##### Project type and purpose
- This is a full-stack order optimization system built with Django on the backend and a simple HTML/JS frontend (using HTMX for dynamic interactions).
- The core functionality is batch processing of paper-cut orders: reading CSV/Excel inputs, running optimization (genetic algorithms, linear programming stub, custom “common-logic” routines), and presenting results in a web UI.

##### File structure
- Top-level Django project:
- manage.py, ordplan_project/ (settings, URLs, WSGI/ASGI)
- order_optimization/ Django app (models, views, forms, templates, URLs, migrations)
- paper_subsitution/ Django app (similar structure for paper substitution feature)
- templates/ and static/ for shared UI components (base.html, alerts, progress bar, HTMX.js)
- modules/ directory: pure-Python algorithmic modules (cnb, ga, hd, lp, ordplan, yggdrasil) and their serialized ML model artifacts under modules/*_models and modules/randomforest_models.
- data/ folder: raw input files (CSV, XLSX) and “true”/test data.
- db.sqlite3: the default SQLite database for persisting orders and substitution records.
- dev/ notebooks and scripts for exploratory analysis and algorithm tuning (not part of the production web stack but useful for offline development).

##### Extract additional insights from the README
- Data processing is handled by pandas.
- Optimization relies on PyGAD (genetic algorithm) with a placeholder for future linear programming.
- A web interface is planned/implemented via Django (forms + templates + HTMX).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser["Browser (User)"]:::frontend
        subgraph "Frontend/UI"
            Base["base.html"]:::frontend
            Alerts["alerts.html"]:::frontend
            Progress["progress_bar.html"]:::frontend
            DatePicker["date_picker.html"]:::frontend
            Loading["loading_overlay.html"]:::frontend
            Login["login.html"]:::frontend
            Greeting["user_greeting.html"]:::frontend
            HTMX["HTMX.js"]:::frontend
        end
    end

    %% Application Layer
    subgraph "Application Layer"
        Router["URL Router<br/>ordplan_project/urls.py"]:::django
        Settings["Settings<br/>ordplan_project/settings.py"]:::django
        WSGI["WSGI/ASGI<br/>ordplan_project/wsgi.py & asgi.py"]:::django
        subgraph "Order Optimization App"
            OO_models["models.py"]:::django
            OO_views["views.py"]:::django
            OO_forms["forms.py"]:::django
            OO_urls["urls.py"]:::django
            OO_controller["controller.py"]:::django
            OO_getter["getter.py"]:::django
            OO_setter["setter.py"]:::django
            OO_formatter["formatter.py"]:::django
            OO_handler["handler.py"]:::django
            OO_container["container.py"]:::django
            OO_templates["optimize.html,<br/>results.html,<br/>parameters_form.html,<br/>form_modals.html,<br/>saved_orders_table.html,<br/>test.html,<br/>test_table.html"]:::frontend
        end
        subgraph "Paper Substitution App"
            PS_models["models.py"]:::django
            PS_views["views.py"]:::django
            PS_urls["urls.py"]:::django
            PS_templates["paper.html"]:::frontend
        end
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        GA["GA Engine<br/>modules/ga.py"]:::service
        NewGA["New GA<br/>modules/new_ga.py"]:::service
        LP["LP Stub<br/>modules/lp.py"]:::service
        CNB["CNB Logic<br/>modules/cnb.py"]:::service
        HD["HD Logic<br/>modules/hd.py"]:::service
        OrdPlan["OrdPlan Logic<br/>modules/ordplan.py"]:::service
        YGG["Yggdrasil<br/>modules/yggdrasil.py"]:::service
        subgraph "Model Artifacts"
            CNB_models["cnb_models/"]:::persistence
            RF_models["randomforest_models/"]:::persistence
            YGG_models["yggdrasil_models/"]:::persistence
        end
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        DB["SQLite<br/>db.sqlite3"]:::persistence
        DataFiles["Data Files Folder"]:::persistence
    end

    %% Offline Development
    Offline["Offline Dev & Analysis (dev/)"]:::offline

    %% Relationships
    Browser -->|"loads templates"| Base
    Browser --> HTMX
    HTMX -->|"AJAX calls"| Router
    Router --> OO_views
    Router --> PS_views
    OO_views -->|"uses forms"| OO_forms
    OO_views -->|"calls service"| GA
    OO_views -->|"calls service"| NewGA
    OO_views -->|"calls service"| LP
    OO_views -->|"calls service"| CNB
    OO_views -->|"calls service"| HD
    OO_views -->|"calls service"| OrdPlan
    OO_views -->|"calls service"| YGG
    PS_views -->|"calls service"| CNB
    PS_views -->|"calls service"| HD
    GA --> CNB_models
    GA --> RF_models
    GA --> DataFiles
    NewGA --> DataFiles
    LP --> DataFiles
    CNB --> CNB_models
    HD --> DataFiles
    OrdPlan --> DataFiles
    YGG --> YGG_models
    GA -->|"results"| OO_views
    OO_views -->|"persist results"| DB
    PS_views -->|"persist substitution"| DB
    OO_views -->|"render"| OO_templates
    PS_views -->|"render"| PS_templates

    %% Click Events
    click HTMX "https://github.com/ppaauuoo/paper_cutting_project/blob/main/static/js/htmx.js"
    click Base "https://github.com/ppaauuoo/paper_cutting_project/blob/main/templates/base.html"
    click Alerts "https://github.com/ppaauuoo/paper_cutting_project/blob/main/templates/alerts.html"
    click Progress "https://github.com/ppaauuoo/paper_cutting_project/blob/main/templates/progress_bar.html"
    click DatePicker "https://github.com/ppaauuoo/paper_cutting_project/blob/main/templates/date_picker.html"
    click Loading "https://github.com/ppaauuoo/paper_cutting_project/blob/main/templates/loading_overlay.html"
    click Login "https://github.com/ppaauuoo/paper_cutting_project/blob/main/templates/login.html"
    click Greeting "https://github.com/ppaauuoo/paper_cutting_project/blob/main/templates/user_greeting.html"
    click Router "https://github.com/ppaauuoo/paper_cutting_project/blob/main/ordplan_project/urls.py"
    click Settings "https://github.com/ppaauuoo/paper_cutting_project/blob/main/ordplan_project/settings.py"
    click WSGI "https://github.com/ppaauuoo/paper_cutting_project/blob/main/ordplan_project/wsgi.py"
    click WSGI "https://github.com/ppaauuoo/paper_cutting_project/blob/main/ordplan_project/asgi.py"
    click OO_models "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/models.py"
    click OO_views "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/views.py"
    click OO_forms "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/forms.py"
    click OO_urls "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/urls.py"
    click OO_controller "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/controller.py"
    click OO_getter "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/getter.py"
    click OO_setter "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/setter.py"
    click OO_formatter "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/formatter.py"
    click OO_handler "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/handler.py"
    click OO_container "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/container.py"
    click OO_templates "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/templates/optimize.html"
    click OO_templates "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/templates/results.html"
    click OO_templates "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/templates/parameters_form.html"
    click OO_templates "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/templates/form_modals.html"
    click OO_templates "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/templates/saved_orders_table.html"
    click OO_templates "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/templates/test.html"
    click OO_templates "https://github.com/ppaauuoo/paper_cutting_project/blob/main/order_optimization/templates/test_table.html"
    click PS_models "https://github.com/ppaauuoo/paper_cutting_project/blob/main/paper_subsitution/models.py"
    click PS_views "https://github.com/ppaauuoo/paper_cutting_project/blob/main/paper_subsitution/views.py"
    click PS_urls "https://github.com/ppaauuoo/paper_cutting_project/blob/main/paper_subsitution/urls.py"
    click PS_templates "https://github.com/ppaauuoo/paper_cutting_project/blob/main/paper_subsitution/templates/paper.html"
    click GA "https://github.com/ppaauuoo/paper_cutting_project/blob/main/modules/ga.py"
    click NewGA "https://github.com/ppaauuoo/paper_cutting_project/blob/main/modules/new_ga.py"
    click LP "https://github.com/ppaauuoo/paper_cutting_project/blob/main/modules/lp.py"
    click CNB "https://github.com/ppaauuoo/paper_cutting_project/blob/main/modules/cnb.py"
    click HD "https://github.com/ppaauuoo/paper_cutting_project/blob/main/modules/hd.py"
    click OrdPlan "https://github.com/ppaauuoo/paper_cutting_project/blob/main/modules/ordplan.py"
    click YGG "https://github.com/ppaauuoo/paper_cutting_project/blob/main/modules/yggdrasil.py"
    click CNB_models "https://github.com/ppaauuoo/paper_cutting_project/tree/main/modules/cnb_models/"
    click RF_models "https://github.com/ppaauuoo/paper_cutting_project/tree/main/modules/randomforest_models/"
    click YGG_models "https://github.com/ppaauuoo/paper_cutting_project/tree/main/modules/yggdrasil_models/"
    click DataFiles "https://github.com/ppaauuoo/paper_cutting_project/blob/main/data/input.csv"
    click DataFiles "https://github.com/ppaauuoo/paper_cutting_project/blob/main/data/order2024.xlsx"
    click DataFiles "https://github.com/ppaauuoo/paper_cutting_project/blob/main/data/ordplan.csv"
    click DataFiles "https://github.com/ppaauuoo/paper_cutting_project/blob/main/data/paper-substitution.csv"
    click DataFiles "https://github.com/ppaauuoo/paper_cutting_project/blob/main/data/test_common_logic.csv"
    click DataFiles "https://github.com/ppaauuoo/paper_cutting_project/blob/main/data/true_ordplan.csv"
    click DB "https://github.com/ppaauuoo/paper_cutting_project/blob/main/db.sqlite3"
    click Offline "https://github.com/ppaauuoo/paper_cutting_project/tree/main/dev/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef django fill:#DFFFE0,stroke:#2E7D32,color:#2E7D32;
    classDef service fill:#FFF3D0,stroke:#F57C00,color:#F57C00;
    classDef persistence fill:#F0F0F0,stroke:#616161,color:#424242;
    classDef offline fill:#F3E5F5,stroke:#8E24AA,color:#8E24AA;
```
