# dddanielliu/trash-classify architecture

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

- Interactive diagram: https://gitdiagram.com/dddanielliu/trash-classify
- Repository: https://github.com/dddanielliu/trash-classify

## Overview

##### Project Overview & Purpose
- This is a full-stack application whose primary goal is to allow users to upload pictures of trash so that an integrated machine learning model can classify them into one of eight trash categories.
- The project has two main parts: a Django-based website (in the “website” directory) handling user interactions, image uploads, and administrative functions, and a model component (in the “model” directory) that contains the classification logic, the trained models, and training scripts.

##### Analyzing the File Structure
- At the top level, you have configuration files (.gitignore, compose.yaml, README.md) which indicate container orchestration via Docker Compose.
- The “model” directory includes:
- Python scripts (ClassifyInterface.py, main.py) to interface with the machine learning model.
- Training related materials (train.ipynb, training logs, trained Keras model files).
- A Dockerfile for containerizing the model service.
- The “website” directory houses a Django project:
- Django project files (manage.py, settings.py, urls.py, wsgi.py/asgi.py).
- Static assets (CSS, JavaScript, images, PDFs) and Django templates for the UI.
- An “admin” section and defined routes such as home, about, display, and admin pages.
- A SQLite database file (db.sqlite3) which indicates persistence for the web side.

##### Key Architectural Elements to Capture
a. Main Components:
- User Interface Frontend: The website (Django based) that handles HTTP requests, image uploads, and displays classification results.
- Backend Web Application: The Django application managing views, models, templates, and authentication (staff/admin features).
- Machine Learning (ML) Service: The “model” component responsible for classifying images. It encapsulates the classification logic and may also be involved in training/updating the model.
- Persistence: SQLite database (within the website container) that stores user data and possibly logs the classification outputs.
- Supporting Infrastructure: Docker Compose configuration that orchestrates separate containers. Also note the shared volume (“images” directory) used for storing uploaded pictures.

b. Relationships & Interactions:
- The user accesses the web application via a browser (HTTP/HTTPS).
- When a picture is uploaded, the website backend passes the image data to the ML service component. This could be through an API call or an internal library call, depending on the integration implemented.
- The ML service processes the image and returns the predicted class label, which is then rendered on one of the website pages (e.g., at the display page).
- The Docker Compose setup ensures that the website container and the ML service container can communicate with each other using internal networking.
- There is an upload directory (or mounted volume) for image storage and persistence for logs and trained models.

c. Architectural Patterns & Design Principles:
- Separation of concerns: The system distinctly separates the web interface and ML logic, making it easier to maintain or scale each independently (microservices-like separation).
- Containerization: Both components have Dockerfiles that allow them to run in isolated environments managed by Docker Compose.
- MVC (in the Django side), where the views interact with models and templates to render the UI.
- The provision for re-training the model (using Jupyter Notebook and training logs) is also a key design element, showing that the system is designed to support updates to the ML component.

d. Relevant Technologies & Frameworks:
- Django Web Framework (Python) for the website.
- SQLite for the website’s database.
- Keras/TensorFlow for the machine learning model and training processes.
- Docker (and Docker Compose) for container orchestration.
- Likely JavaScript/CSS for frontend interactions in the “website/static” folder.

## Diagram (Mermaid)

```mermaid
flowchart TD
    UserBrowser["User Browser"]:::user

    subgraph "Website Container"
        UI_Templates["UI Templates (Django HTML)"]:::frontend
        Static_Assets["Static Assets (CSS/JS)"]:::frontend
        Django_Core["Django Core (Views, Models, URLs, Admin)"]:::backend
        Django_Config["Django Config (Settings, WSGI, ASGI)"]:::backend
        SQLite_DB["SQLite Database"]:::database
    end

    subgraph "Model Container"
        ML_Service["ML Service (Classification Engine & Training)"]:::ml
    end

    DockerCompose["Docker Compose Orchestration"]:::orchestration
    Website_Dockerfile["Website Dockerfile"]:::orchestration
    Model_Dockerfile["Model Dockerfile"]:::orchestration

    Shared_Volume["Shared Volume (images)"]:::storage

    UserBrowser -->|"HTTP_Request/ImageUpload"| UI_Templates
    UserBrowser -->|"HTTP_Request/ImageUpload"| Static_Assets

    UI_Templates -->|"SubmitImage"| Django_Core
    Django_Core -->|"RequestClassification"| ML_Service
    ML_Service -->|"ReturnResult"| Django_Core
    Django_Core -->|"StoreData"| SQLite_DB

    UI_Templates -->|"SaveUploadedImage"| Shared_Volume
    ML_Service -->|"StoreLogsModels"| Shared_Volume

    DockerCompose ---|"Orchestrates"| UI_Templates
    DockerCompose ---|"Orchestrates"| Django_Core
    DockerCompose ---|"Orchestrates"| ML_Service

    DockerCompose ---|"Uses"| Website_Dockerfile
    DockerCompose ---|"Uses"| Model_Dockerfile

    click UI_Templates "https://github.com/dddanielliu/trash-classify/tree/main/website/trash_classify/templates"
    click Static_Assets "https://github.com/dddanielliu/trash-classify/tree/main/website/static"
    click Django_Core "https://github.com/dddanielliu/trash-classify/tree/main/website/trash_classify"
    click Django_Config "https://github.com/dddanielliu/trash-classify/tree/main/website/website"
    click SQLite_DB "https://github.com/dddanielliu/trash-classify/blob/main/website/db.sqlite3"
    click ML_Service "https://github.com/dddanielliu/trash-classify/tree/main/model"
    click DockerCompose "https://github.com/dddanielliu/trash-classify/blob/main/compose.yaml"
    click Website_Dockerfile "https://github.com/dddanielliu/trash-classify/tree/main/website/Dockerfile"
    click Model_Dockerfile "https://github.com/dddanielliu/trash-classify/tree/main/model/Dockerfile"

    classDef user fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef frontend fill:#a0c4ff,stroke:#333,stroke-width:2px;
    classDef backend fill:#bdb2ff,stroke:#333,stroke-width:2px;
    classDef database fill:#ffadad,stroke:#333,stroke-width:2px;
    classDef ml fill:#caffbf,stroke:#333,stroke-width:2px;
    classDef orchestration fill:#ffd6a5,stroke:#333,stroke-width:2px;
    classDef storage fill:#fdffb6,stroke:#333,stroke-width:2px;
```
