# alesimattia/prog_avanzata architecture

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

- Interactive diagram: https://gitdiagram.com/alesimattia/prog_avanzata
- Repository: https://github.com/alesimattia/prog_avanzata

## Overview

Key Components to Include:

##### Client Layer
- Postman/API clients making HTTP requests
- JWT authentication flow

##### API Layer
- Express.js server (port 8080)
- Routes (/budget, /dataset, /upload, /process, /status)
- Middleware chain:
- Authorization middleware
- File upload middleware
- Python adapter middleware

##### Application Layer
- Controllers:
- AdminController
- UserController
- Models:
- Users
- Datasets
- Files
- BullMQ Queue System for processing tasks

##### Storage Layer
- PostgreSQL Database (port 5432)
- Redis Cache (port 6379)
- File System Storage for images/datasets

##### Processing Layer
- Python SAM Model service
- Image processing pipeline

- [Client Layer]
- ↓
- [API Layer]
- ↓
- [Application Layer]
- ↓
- [Storage/Processing Layer]

##### Connection types
- Double lines: Data persistence

##### Specific technical details
- Port numbers
- Database tables
- Queue names
- File storage paths

##### Authentication Flow
- JWT token validation
- Role-based access (Admin vs User)

##### Dataset Management
- Image/ZIP upload process
- Dataset CRUD operations
- Storage interaction

##### Processing Pipeline
- Task queue management
- Python SAM model interaction
- Result storage and retrieval

##### Data Flow
- Client request handling
- Middleware processing
- Controller logic
- Model interactions
- Storage operations

Special Considerations:

##### MVC pattern implementation
- Model: Database.ts and related models
- View: API responses
- Controller: AdminController and UserController

##### Demonstrate the Python integration through the adapter pattern

Remember to include Docker container boundaries since the application is containerized, showing how different services interact within the Docker network.

This system design should effectively communicate both the high-level architecture and the important implementation details of this neural network dataset processing system.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef client fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef middleware fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef controller fill:#e74c3c,stroke:#c0392b,color:white
    classDef model fill:#f1c40f,stroke:#f39c12,color:black
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:white
    classDef processing fill:#e67e22,stroke:#d35400,color:white
    
    %% Client Layer
    subgraph ClientLayer
        Client["API Client\n(Postman/HTTP)"]:::client
    end

    %% API Layer
    subgraph APILayer
        Server["Express Server\n(Port 8080)"]:::api
        Routes["API Routes"]:::api
    end
    click Server "https://github.com/alesimattia/Prog_avanzata/blob/main/index.ts"
    click Routes "https://github.com/alesimattia/Prog_avanzata/blob/main/routes/routes.ts"

    %% Middleware Layer
    subgraph MiddlewareLayer
        Auth["Authorization\nMiddleware"]:::middleware
        FileUpload["File Upload\nMiddleware"]:::middleware
        PythonAdapter["Python Adapter\nMiddleware"]:::middleware
    end
    click Auth "https://github.com/alesimattia/Prog_avanzata/blob/main/middleware/authorization.ts"
    click FileUpload "https://github.com/alesimattia/Prog_avanzata/blob/main/middleware/fileUploader.ts"
    click PythonAdapter "https://github.com/alesimattia/Prog_avanzata/blob/main/middleware/pythonAdapter.ts"

    %% Controller Layer
    subgraph ControllerLayer
        AdminCtrl["Admin\nController"]:::controller
        UserCtrl["User\nController"]:::controller
    end
    click AdminCtrl "https://github.com/alesimattia/Prog_avanzata/blob/main/controller/AdminController.ts"
    click UserCtrl "https://github.com/alesimattia/Prog_avanzata/blob/main/controller/UserController.ts"

    %% Model Layer
    subgraph ModelLayer
        DB["Database\nConnection"]:::model
        Users["Users\nModel"]:::model
        Datasets["Datasets\nModel"]:::model
        Files["Files\nModel"]:::model
    end
    click DB "https://github.com/alesimattia/Prog_avanzata/blob/main/model/Database.ts"
    click Users "https://github.com/alesimattia/Prog_avanzata/blob/main/model/Users.ts"
    click Datasets "https://github.com/alesimattia/Prog_avanzata/blob/main/model/Datasets.ts"
    click Files "https://github.com/alesimattia/Prog_avanzata/blob/main/model/Files.ts"

    %% Storage Layer
    subgraph StorageLayer
        Postgres[("PostgreSQL\n(Port 5432)")]:::storage
        Redis[("Redis Cache\n(Port 6379)")]:::storage
        FileSystem["File System\nStorage"]:::storage
    end
    click Postgres "https://github.com/alesimattia/Prog_avanzata/blob/main/SQL/SAM_storage.sql"

    %% Processing Layer
    subgraph ProcessingLayer
        SAM["SAM Model\nProcessor"]:::processing
        Queue["BullMQ\nQueue"]:::processing
    end
    click SAM "https://github.com/alesimattia/Prog_avanzata/blob/main/python/SAM_model.py"

    %% Connections
    Client --> Server
    Server --> Routes
    Routes --> Auth
    Auth --> FileUpload
    FileUpload --> PythonAdapter
    PythonAdapter --> AdminCtrl & UserCtrl
    AdminCtrl & UserCtrl --> DB
    DB --> Users & Datasets & Files
    Users & Datasets & Files --> Postgres
    AdminCtrl & UserCtrl --> Redis
    AdminCtrl & UserCtrl --> Queue
    Queue --> SAM
    SAM --> FileSystem
    
    %% Legend
    subgraph Legend
        C1["Client Components"]:::client
        A1["API Components"]:::api
        M1["Middleware"]:::middleware
        CT1["Controllers"]:::controller
        MD1["Models"]:::model
        S1["Storage"]:::storage
        P1["Processing"]:::processing
    end
```
