# badrobin/ua_team_final_project architecture

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

- Interactive diagram: https://gitdiagram.com/badrobin/ua_team_final_project
- Repository: https://github.com/badrobin/ua_team_final_project

## Overview

##### Project Type and Purpose
- This is a full-stack web application designed to automate enterprise order management. It supports creating orders, approval workflows, supplier order management, and integration with external services like DigitalOcean Spaces for cloud storage.
- The README highlights key roles (Administrator, User, Head of Department, Finance, and Supply Manager) and background processes (price list processing, CSV parsing, archiving orders, etc.), which directly influence the system’s architectural elements.

##### File Structure
- The “src/main” directory houses the Java backend with a clear package structure: config, controllers, dto, models, repositories, and services. This suggests a layered (or MVC) design:
- Controllers: Handle HTTP requests (e.g., ProductController, AppController, SupplierOrderController).
- Services: Encapsulate business logic (e.g., OrderService, SupplierOrderService, DigitalOceanStorageService, EmailService).
- Repositories: Interface with the database using Spring Data JPA (e.g., UserRepository, OrderRepository, SupplierRepository).
- Configuration: Contains DigitalOcean and Security configuration settings.
- “src/main/resources” contains static files (HTML, CSS, JavaScript) and templates, supporting the frontend piece.
- The Maven build configuration (pom.xml, mvnw wrapper scripts, etc.) reinforces that this Java/Spring Boot application is managed via Maven.

a. Main Components:
- Frontend/UI:
- HTML templates (in src/main/resources/templates) and static assets (CSS and JavaScript in src/main/resources/static).
- Acts as the presentation layer, rendering pages for login, order management, and supplier order interfaces.
- Backend Application:
- Controllers: Entry point for incoming HTTP requests.
- Services: Business logic layer implementing workflows (order creation, email notifications, CSV file parsing, etc.).
- Repositories: Data access layer interfacing with MySQL.
- Models/DTOs: Represent data structures for orders, users, and supplier-related entities.
- Security:
- Spring Security configuration manages authentication and role-based access.
- External Components:
- Database (MySQL) for persistent storage.
- Cloud Services (DigitalOcean Spaces) for file storage and server hosting.
- Email Service: To send out supplier orders and order notifications.

b. Relationships and Data Flow:
- Requests from the user’s web browser (frontend) are routed to the backend’s controllers.
- Controllers invoke the appropriate services that encapsulate business logic like order processing or CSV parsing.
- Services interact with repositories for CRUD operations and database persistence.
- The security configuration (via SecurityConfig and CustomUserDetailsService) governs access control across these layers.
- Outgoing communications include:
- EmailService sending notifications/emails (e.g., OrderEmailSender).
- DigitalOceanStorageService managing file uploads/downloads.

##### Architectural Patterns and Principles
- The system uses a layered (MVC) architecture that cleanly separates concerns:
- The web layer (controllers and templates) is separated from the business logic (services) and data access (repositories).
- The configuration files (such as SecurityConfig and DigitalOceanConfig) indicate dependency injection and external configuration aspects via Spring Boot.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        UI["User Interface (HTML/CSS/JS)"]:::frontend
        Templates["Templates"]:::frontend
        StaticAssets["Static Assets"]:::frontend
    end

    subgraph "Backend Application"
        Controllers["Controllers (App, Product, SupplierOrder)"]:::backend
        Services["Business Services (OrderService, etc.)"]:::services
        Background["Background Processes (CSVParsing, PriceListProcessing, OrderArchival)"]:::services
        Repositories["Data Access/Repositories"]:::backend
        Models["Models"]:::backend
        DTOs["DTOs"]:::backend
        SecConf["Security & Configuration"]:::security
    end

    subgraph "External Systems"
        Database["MySQL Database"]:::database
        Cloud["DigitalOcean Spaces"]:::external
        Email["Email Service"]:::external
    end

    %% Data Flow Connections
    UI -->|"HTTPRequest"| Controllers
    Controllers -->|"InvokeLogic"| Services
    Services -->|"CRUDoperations"| Repositories
    Repositories -->|"PersistData"| Database
    Services -->|"FileTransfer"| Cloud
    Services -->|"SendNotifications"| Email
    Controllers -- "securedby" --> SecConf
    Services -->|"TriggerBackground"| Background
    Background -->|"ArchiveData"| Database

    %% Click Events
    click Templates "https://github.com/badrobin/ua_team_final_project/tree/main/src/main/resources/templates"
    click StaticAssets "https://github.com/badrobin/ua_team_final_project/tree/main/src/main/resources/static"
    click Controllers "https://github.com/badrobin/ua_team_final_project/tree/main/src/main/java/com/final_project/ua_team_final_project/controllers"
    click Services "https://github.com/badrobin/ua_team_final_project/tree/main/src/main/java/com/final_project/ua_team_final_project/services"
    click Repositories "https://github.com/badrobin/ua_team_final_project/tree/main/src/main/java/com/final_project/ua_team_final_project/repositories"
    click Models "https://github.com/badrobin/ua_team_final_project/tree/main/src/main/java/com/final_project/ua_team_final_project/models"
    click DTOs "https://github.com/badrobin/ua_team_final_project/tree/main/src/main/java/com/final_project/ua_team_final_project/dto"
    click SecConf "https://github.com/badrobin/ua_team_final_project/tree/main/src/main/java/com/final_project/ua_team_final_project/config"

    %% Styles
    classDef frontend fill:#a4c2f4,stroke:#0b5394,stroke-width:2px;
    classDef backend fill:#ffe599,stroke:#bf9000,stroke-width:2px;
    classDef services fill:#f4cccc,stroke:#cc0000,stroke-width:2px;
    classDef database fill:#d9ead3,stroke:#6aa84f,stroke-width:2px;
    classDef external fill:#ead1dc,stroke:#990099,stroke-width:2px;
    classDef security fill:#c9daf8,stroke:#1155cc,stroke-width:2px;
```
