# ndat99/compressionfile architecture

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

- Interactive diagram: https://gitdiagram.com/ndat99/compressionfile
- Repository: https://github.com/ndat99/compressionfile

## Overview

##### Project Type and Purpose
- This is a Java EE (Servlet + JSP) full-stack web application that provides a file-compression service.
- Users register/login, upload files, trigger asynchronous compression jobs, then view/download compressed outputs.

##### High-Level Architecture Overview
- Follows the classic web MVC layering:
- Presentation layer: JSP pages + static assets
- Controller layer: Servlets handling HTTP requests
- Business layer (BO): orchestrates compression jobs & user logic
- Data-access layer (DAO): JDBC-based persistence to a MySQL database
- Background worker: a thread that polls pending jobs, compresses files, updates job status

##### Main Components
a. Actor
– End User (Web Browser)
b. Presentation / Web Container
– JSP Views: index.jsp, login.jsp, register.jsp, upload.jsp, history.jsp
– Static CSS: index.css
– Web server/Servlet container (e.g., Tomcat)
c. Controller Layer (Servlets)
– AppListener (initializes DB connection pool, schedules BackgroundWorker)
– RegisterServlet (handles user signup)
– CheckLoginServlet (session/auth checks)
– FileControllerServlet (handles upload requests and job submission)
d. Business Layer (BO)
– UserBO (validates user logic)
– JobBO (creates and queues compression jobs)
– BackgroundWorker (polls `compression_jobs` table, invokes compression)
e. Data-Access Layer (DAO)
– DatabaseConnection (singleton/connection pooling)
– UserDAO (CRUD on `users` table)
– JobDAO (CRUD on `compression_jobs` table)
f. Database
– MySQL (schema defined in filecompression.sql)
g. File System / Storage
– Temporary storage for uploaded and compressed files
h. External Library
– mysql-connector-j-9.3.0.jar (JDBC driver)
– Compression library (built-in or third-party)

##### Relationships & Data Flows
1. User → Browser sends HTTP request →
2. Servlet Container routes to appropriate Servlet →
3. Servlet calls BO → BO calls DAO → DAO executes JDBC on MySQL →
4. DAO returns data → BO processes business rules → Servlet forwards to JSP →
5. JSP renders view → Browser displays response
6. For file compression: FileControllerServlet writes job record → BackgroundWorker (in same container) polls DB → reads file from storage → compresses → writes output to storage → updates job status in DB → User reloads history.jsp to see results

##### Architectural Patterns & Design Principles
- MVC separation (Presentation / Controller / Model)
- Layered architecture (Controller → Business → DAO → Persistence)
- Asynchronous processing (BackgroundWorker for non-blocking file compression)
- Singleton/Factory for DB connections
- JSP for view templates, Servlets for request handling

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actor
    Browser("End User (Web Browser)"):::external

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Index["index.jsp"]:::presentation
        Login["login.jsp"]:::presentation
        Register["register.jsp"]:::presentation
        Upload["upload.jsp"]:::presentation
        History["history.jsp"]:::presentation
        Header["header.jsp"]:::presentation
        CSS["index.css"]:::presentation
    end

    %% Controller Layer
    subgraph "Controller Layer"
        direction TB
        AppListener["AppListener"]:::controller
        CheckLogin["CheckLoginServlet"]:::controller
        FileController["FileControllerServlet"]:::controller
        RegisterServlet["RegisterServlet"]:::controller
    end

    %% Business Layer
    subgraph "Business Layer"
        direction TB
        UserBO["UserBO"]:::business
        JobBO["JobBO"]:::business
        BackgroundWorker["BackgroundWorker"]:::business
    end

    %% Data-Access Layer
    subgraph "DAO Layer"
        direction TB
        DBConn["DatabaseConnection"]:::dao
        UserDAO["UserDAO"]:::dao
        JobDAO["JobDAO"]:::dao
    end

    %% Database and Storage
    MySQL[(MySQL Database)]:::database
    Storage[(File Storage)]:::storage

    %% User Request Flow
    Browser -->|"HTTP GET/POST"| AppListener
    AppListener -->|initializes| DBConn
    Browser -->|HTTP GET/POST| CheckLogin
    Browser -->|HTTP GET/POST| RegisterServlet
    Browser -->|HTTP GET/POST| FileController

    %% Controller to Business to DAO to DB
    CheckLogin -->|"validate session"| UserBO
    RegisterServlet -->|"signup logic"| UserBO
    FileController -->|"submit job"| JobBO
    UserBO -->|queries| UserDAO
    JobBO -->|insert job record| JobDAO
    UserDAO -->|JDBC calls| MySQL
    JobDAO -->|JDBC calls| MySQL

    %% Business to Presentation
    CheckLogin -->|"forward to JSP"| Login
    RegisterServlet -->|"forward to JSP"| Register
    FileController -->|"forward to JSP"| Upload
    FileController -->|"forward to JSP"| History

    %% Asynchronous Compression Flow
    BackgroundWorker -->|"polls pending jobs"| MySQL
    BackgroundWorker -->|"reads file"| Storage
    BackgroundWorker -->|"compresses file"| Storage
    BackgroundWorker -->|"updates status"| MySQL
    Browser -->|reload history| History

    %% Click Events
    click Index "https://github.com/ndat99/compressionfile/blob/master/src/main/webapp/index.jsp"
    click Login "https://github.com/ndat99/compressionfile/blob/master/src/main/webapp/login.jsp"
    click Register "https://github.com/ndat99/compressionfile/blob/master/src/main/webapp/register.jsp"
    click Upload "https://github.com/ndat99/compressionfile/blob/master/src/main/webapp/upload.jsp"
    click History "https://github.com/ndat99/compressionfile/blob/master/src/main/webapp/history.jsp"
    click Header "https://github.com/ndat99/compressionfile/blob/master/src/main/webapp/header.jsp"
    click CSS "https://github.com/ndat99/compressionfile/blob/master/src/main/webapp/index.css"
    click AppListener "https://github.com/ndat99/compressionfile/blob/master/src/main/java/controller/AppListener.java"
    click CheckLogin "https://github.com/ndat99/compressionfile/blob/master/src/main/java/controller/CheckLoginServlet.java"
    click FileController "https://github.com/ndat99/compressionfile/blob/master/src/main/java/controller/FileControllerServlet.java"
    click RegisterServlet "https://github.com/ndat99/compressionfile/blob/master/src/main/java/controller/RegisterServlet.java"
    click UserBO "https://github.com/ndat99/compressionfile/blob/master/src/main/java/model/bo/UserBO.java"
    click JobBO "https://github.com/ndat99/compressionfile/blob/master/src/main/java/model/bo/JobBO.java"
    click BackgroundWorker "https://github.com/ndat99/compressionfile/blob/master/src/main/java/model/bo/BackgroundWorker.java"
    click DBConn "https://github.com/ndat99/compressionfile/blob/master/src/main/java/model/dao/DatabaseConnection.java"
    click UserDAO "https://github.com/ndat99/compressionfile/blob/master/src/main/java/model/dao/UserDAO.java"
    click JobDAO "https://github.com/ndat99/compressionfile/blob/master/src/main/java/model/dao/JobDAO.java"

    %% Styles
    classDef presentation fill:#AED6F1,stroke:#1F618D,color:#1B2631
    classDef controller fill:#A9DFBF,stroke:#196F3D,color:#1B2631
    classDef business fill:#ABEBC6,stroke:#145A32,color:#1B2631
    classDef dao fill:#A3E4D7,stroke:#0E6655,color:#1B2631
    classDef database fill:#F5CBA7,stroke:#7E5109,color:#1B2631
    classDef storage fill:#D5DBDB,stroke:#566573,color:#1B2631
    classDef external fill:#E8DAEF,stroke:#512E5F,color:#1B2631
```
