# prilily/file-encryption-system architecture

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

- Interactive diagram: https://gitdiagram.com/prilily/file-encryption-system
- Repository: https://github.com/prilily/file-encryption-system

## Overview

##### Main Components
- User Interface Layer (JavaSwing GUI):
- Components: Login, Register, and UserHome screens.
- Purpose: Handle user authentication and allow users to choose between encrypting and decrypting files.
- Encryption/Decryption Module:
- Classes: Encrypt.java, Decrypt.java, and Algo.java.
- Purpose: Contain the AES encryption/decryption logic and processing of files.
- Exception Handling:
- Class: CryptoException.java.
- Purpose: Manage errors related to cryptographic operations.
- Persistence/Database Component:
- MySQL Connector: mysql-connector-j-8.0.31.jar.
- Role: Interface with a MySQL database, where encrypted files can be stored.
- External Libraries / Frameworks:
- JavaSwing: For building the user interface.
- MySQL JDBC driver: For database interactions.
- AES Cipher Algorithm: To provide the cryptographic functionality.

##### Relationships and Interactions
- The UI layer initiates the authentication process (Login/Register) and then presents the file selection options (UserHome).
- When a user chooses to perform encryption or decryption:
- The UI layer calls the corresponding Encrypt or Decrypt component.
- These modules then use the shared Algo class to execute the AES algorithm.
- Should an error occur during the cryptographic process, the CryptoException is thrown.
- After encryption, if the user selects to save the file, the encryption module interacts with the MySQL database via the JDBC driver.
- Data flows are clearly directional—from UI actions to business logic (encryption/decryption) and optionally to persistence (database storage).

##### Architectural Patterns and Principles
- Layered Architecture: Distinct separation between the UI (presentation) and the business logic (encryption/decryption) layers.
- Exception Handling: Centralized error management via the CryptoException class.
- Modular Design: Each Java class (e.g., Encrypt, Decrypt, Login, Register) handles a focused responsibility.

##### Elements
- Clear Labels:
- “User Interface (JavaSwing)” with sub-components (Login, Register, UserHome).
- “Encryption/Decryption Module” with Encrypt, Decrypt, and Algo classes.
- “Exception Handling” highlighted via CryptoException.
- From UI elements (Login/Register/UserHome) to the appropriate encryption/decryption functionalities.
- From encryption/decryption components to the Algo class.
- From encryption/decryption components to the Database component when persisting data.

- Inside, split into two paths: one for Encrypt and another for Decrypt operations.
- Relate both components back to the shared “Algo” utility.
- Optionally, note exception handling (CryptoException) alongside the encryption/decryption flow.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interface Layer
    subgraph "User Interface (JavaSwing)"
        UI_Login("Login"):::ui
        UI_Register("Register"):::ui
        UI_UserHome("UserHome"):::ui
    end

    %% Encryption/Decryption Module
    subgraph "Encryption/Decryption Module"
        Encrypt("Encrypt"):::enc
        Decrypt("Decrypt"):::enc
        Algo("Algo"):::algo
    end

    %% Exception Handling
    CryptoEx("CryptoException"):::exception

    %% Persistence/Database Component
    MySQL("MySQL Database"):::db

    %% External Libraries / Frameworks
    JavaSwingLib("JavaSwing"):::external
    MySQLJDBC("MySQL JDBC"):::external
    AESCipher("AES Cipher"):::external

    %% Connections within UI Layer
    UI_Login -->|"authSuccess"| UI_UserHome
    UI_Register -->|"registered"| UI_UserHome

    %% UI to Encryption/Decryption Interaction
    UI_UserHome -->|"encrypt"| Encrypt
    UI_UserHome -->|"decrypt"| Decrypt

    %% Business Logic Flow
    Encrypt -->|"uses"| Algo
    Decrypt -->|"uses"| Algo
    Encrypt -->|"store"| MySQL

    %% Exception Handling Flow
    Encrypt -->|"throws"| CryptoEx
    Decrypt -->|"throws"| CryptoEx

    %% External Dependencies Relationships
    JavaSwingLib -->|"supports"| UI_Login
    JavaSwingLib -->|"supports"| UI_Register
    JavaSwingLib -->|"supports"| UI_UserHome
    AESCipher -->|"powers"| Algo
    MySQLJDBC -->|"connects"| MySQL

    %% Click Events for Component Mappings
    click UI_Login "https://github.com/prilily/file-encryption-system/blob/master/main/java/Login.java"
    click UI_Register "https://github.com/prilily/file-encryption-system/blob/master/main/java/Register.java"
    click UI_UserHome "https://github.com/prilily/file-encryption-system/blob/master/main/java/UserHome.java"
    click Encrypt "https://github.com/prilily/file-encryption-system/blob/master/main/java/Encrypt.java"
    click Decrypt "https://github.com/prilily/file-encryption-system/blob/master/main/java/Decrypt.java"
    click Algo "https://github.com/prilily/file-encryption-system/blob/master/main/java/Algo.java"
    click CryptoEx "https://github.com/prilily/file-encryption-system/blob/master/main/java/CryptoException.java"
    click MySQL "https://github.com/prilily/file-encryption-system/blob/master/main/java/mysql-connector-j-8.0.31.jar"

    %% Styles
    classDef ui fill:#8ecae6,stroke:#023047,stroke-width:2px;
    classDef enc fill:#219ebc,stroke:#023047,stroke-width:2px;
    classDef algo fill:#ffb703,stroke:#fefae0,stroke-width:2px;
    classDef exception fill:#fb8500,stroke:#370617,stroke-width:2px;
    classDef db fill:#bbe1fa,stroke:#1b262c,stroke-width:2px;
    classDef external fill:#e76f51,stroke:#264653,stroke-width:2px;
```
