# chenn02z/is442g1t3 architecture

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

- Interactive diagram: https://gitdiagram.com/chenn02z/is442g1t3
- Repository: https://github.com/chenn02z/is442g1t3

## Overview

##### Project Type and Purpose
- The project is an ID Photo Generator application. Its purpose is to provide features like image upload, background removal, cropping, cartoonisation, and downloading processed images.
- The backend handles image processing (using OpenCV and custom services) while the frontend provides a user interface that interacts with these backend endpoints.
- The README confirms that the backend runs on Java (Spring Boot) and the frontend is run via npm with a local development server.

##### Analyzing the File Structure
- Backend:
- Contains standard Java/Spring Boot project structure with directories for configuration (ApplicationConfig, OpenCVConfig, WebConfig), controllers (handling API endpoints such as ImageUploadController, BackgroundRemovalController, etc.), DTOs, models, repositories, and service layers.
- There is a clear separation where controllers manage HTTP requests, services implement business logic (and delegate to their implementations in the “impl” folder), and repositories handle database interactions.
- There is a dedicated folder for OpenCV resources (an opencv jar and associated XML configuration for face detection), indicating the use of computer vision functionality.
- Database schema and supabase scripts in the resources imply integration with an external database.

- Frontend:
- Uses Next.js with React components and hooks.
- Organized into directories such as "app", "components", "context", and "styles", indicating a component-driven architecture.
- Contains UI-specific components (like BackgroundRemover, CropImage, UploadImageForm, etc.) that likely map to backend API endpoints for processing images.
- Utility functions and state management (e.g., UploadContext, custom hooks) suggest a well-thought separation of frontend logic and presentation.

a. Main Components:
- Frontend: A user interface layer built on Next.js/React (with components for uploading, displaying, and editing images).
- Backend: A Spring Boot application containing:
- API Controllers: Handling HTTP requests (e.g., ImageUploadController, PhotoSessionController).
- Service Layer: Business logic for operations like background removal, flood fill, cropping, cartoonisation, etc.
- Repository/Database Layer: Persistence logic connecting the application with a Supabase SQL database.
- Configuration Components: Managing application settings (including integration with OpenCV, external database connections via environment variables, etc.).
- OpenCV Integration: The section that manages image processing tasks (indicated by the OpenCVConfig and related resource files).

b. Relationships and Interactions:
- From Services, indicate calls to Repository components for persistent storage operations.
- An external connection to a Database (Supabase) linked to the backend repositories.
- Optionally, include external service/environment connections like environment variables required for configuration (e.g., DATABASE_URL, etc.).

c. Architectural Patterns and Design Principles:
- The backend follows a layered architecture (Controller → Service → Repository) along with clear configuration management.
- The frontend aligns with modern React/Next.js best practices, using contexts for state management and a component-based design.
- Integration of external libraries (OpenCV) and the separation of concerns between image processing and user interface management.

d. Relevant Technologies:
- Backend: Java 21, Spring Boot, Maven, and OpenCV.
- Database: Supabase (SQL, as suggested by the schema files).
- Frontend: Next.js, React, Tailwind CSS, and additional UI libraries/components.

- That any internal communications and dependencies (like service calls and configuration management) are clearly marked.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        FE1["Overall Application (UI)"]:::frontend
        FE2["Upload Image Component"]:::frontend
        FE3["Background Removal UI"]:::frontend
        FE4["Crop Image Component"]:::frontend
        FE5["Upload Context"]:::frontend
        FE6["Image Upload Handler"]:::frontend
        FE7["State Management Service"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend"
        %% API Controllers
        subgraph "API Controllers"
            BE_AC1["Image Upload Controller"]:::backend
            BE_AC2["Background Removal Controller"]:::backend
            BE_AC3["Flood Fill Controller"]:::backend
            BE_AC4["Image Crop Controller"]:::backend
            BE_AC5["Photo Session Controller"]:::backend
            BE_AC6["Image Download Controller"]:::backend
            BE_AC7["User Image Controller"]:::backend
        end

        %% Service Layer
        subgraph "Service Layer"
            BE_S1["Image Upload Service"]:::backend
            BE_S2["Background Removal Service"]:::backend
            BE_S3["Flood Fill Service"]:::backend
            BE_S4["Image Crop Service"]:::backend
            BE_S5["Image Download Service"]:::backend
            BE_S6["Photo Session Service"]:::backend
            BE_S7["Cartoonisation Service"]:::backend
            BE_S8["File Storage Service"]:::backend
        end

        %% Repositories
        subgraph "Repositories"
            BE_R1["Image Repository"]:::repository
            BE_R2["Photo Session Repository"]:::repository
        end

        %% Configuration Components
        subgraph "Configuration"
            BE_C1["Application Configuration"]:::config
            BE_C2["OpenCV Configuration"]:::config
            BE_C3["Web Configuration"]:::config
        end

        %% OpenCV Integration
        subgraph "OpenCV Integration"
            BE_OP1["OpenCV Jar"]:::opencv
            BE_OP2["OpenCV XML Configuration"]:::opencv
        end
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["Supabase Database"]:::database
    end

    %% Connections from Frontend to Backend Controllers (HTTP REST API Calls)
    FE1 -->|"HTTPREST"| BE_AC1
    FE1 -->|"HTTPREST"| BE_AC2
    FE1 -->|"HTTPREST"| BE_AC3
    FE1 -->|"HTTPREST"| BE_AC4
    FE1 -->|"HTTPREST"| BE_AC5
    FE1 -->|"HTTPREST"| BE_AC6
    FE1 -->|"HTTPREST"| BE_AC7

    %% Connections from Controllers to Service Layer (Delegation)
    BE_AC1 -->|"Delegate"| BE_S1
    BE_AC2 -->|"Delegate"| BE_S2
    BE_AC3 -->|"Delegate"| BE_S3
    BE_AC4 -->|"Delegate"| BE_S4
    BE_AC5 -->|"Delegate"| BE_S6
    BE_AC6 -->|"Delegate"| BE_S5
    BE_AC7 -->|"Delegate"| BE_S8

    %% Services interacting with Repositories (Persistence)
    BE_S1 -->|"Persist"| BE_R1
    BE_S6 -->|"Persist"| BE_R2

    %% Repositories storing data into the Database
    BE_R1 -->|"StoresData"| DB
    BE_R2 -->|"StoresData"| DB

    %% Service using OpenCV Integration (Image Processing)
    BE_S2 -->|"ImageProcess"| BE_OP1
    BE_S2 -->|"UsesConfig"| BE_OP2

    %% Configuration providing settings to Services
    BE_C2 -->|"ProvidesConfig"| BE_S2

    %% Styling Classes
    classDef frontend fill:#a0d8f0,stroke:#333,stroke-width:2px;
    classDef backend fill:#f5d0a9,stroke:#333,stroke-width:2px;
    classDef repository fill:#d0edd0,stroke:#333,stroke-width:2px;
    classDef config fill:#f9d5e5,stroke:#333,stroke-width:2px;
    classDef opencv fill:#e3e3e3,stroke:#333,stroke-width:2px;
    classDef database fill:#ffe599,stroke:#333,stroke-width:2px;

    %% Click Events - Frontend
    click FE1 "https://github.com/chenn02z/is442g1t3/tree/main/frontend/src/app"
    click FE2 "https://github.com/chenn02z/is442g1t3/blob/main/frontend/src/components/UploadImageForm.tsx"
    click FE3 "https://github.com/chenn02z/is442g1t3/blob/main/frontend/src/components/BackgroundRemover.tsx"
    click FE4 "https://github.com/chenn02z/is442g1t3/blob/main/frontend/src/components/CropImage.tsx"
    click FE5 "https://github.com/chenn02z/is442g1t3/blob/main/frontend/src/context/UploadContext.tsx"
    click FE6 "https://github.com/chenn02z/is442g1t3/blob/main/frontend/src/utils/ImageUploadHandler.tsx"
    click FE7 "https://github.com/chenn02z/is442g1t3/blob/main/frontend/src/utils/StateManagementService.ts"

    %% Click Events - Backend API Controllers
    click BE_AC1 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/controller/ImageUploadController.java"
    click BE_AC2 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/controller/BackgroundRemovalController.java"
    click BE_AC3 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/controller/FloodFillController.java"
    click BE_AC4 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/controller/ImageCropNewController.java"
    click BE_AC5 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/controller/PhotoSessionController.java"
    click BE_AC6 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/controller/ImageDownloadController.java"
    click BE_AC7 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/controller/UserImageController.java"

    %% Click Events - Backend Service Layer
    click BE_S1 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/service/ImageUploadService.java"
    click BE_S2 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/service/BackgroundRemovalService.java"
    click BE_S3 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/service/FloodFillService.java"
    click BE_S4 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/service/ImageCropNewService.java"
    click BE_S5 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/service/ImageDownloadService.java"
    click BE_S6 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/service/PhotoSessionService.java"
    click BE_S7 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/service/CartoonisationService.java"
    click BE_S8 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/service/FileStorageService.java"

    %% Click Events - Backend Repositories
    click BE_R1 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/repository/ImageNewRepository.java"
    click BE_R2 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/repository/PhotoSessionRepository.java"

    %% Click Events - Backend Configuration Components
    click BE_C1 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/config/ApplicationConfig.java"
    click BE_C2 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/config/OpenCVConfig.java"
    click BE_C3 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/config/WebConfig.java"

    %% Click Events - Backend OpenCV Integration
    click BE_OP1 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/java/IS442/G1T3/IDPhotoGenerator/service/impl/opencv-470.jar"
    click BE_OP2 "https://github.com/chenn02z/is442g1t3/blob/main/backend/src/main/resources/opencv/haarcascade_frontalface_default.xml"
```
