# pleszyk/file_girl architecture

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

- Interactive diagram: https://gitdiagram.com/pleszyk/file_girl
- Repository: https://github.com/pleszyk/file_girl

## Overview

##### Project Type and Purpose
- This is a full-stack application where the client-side (a React-based application structured under the “client” directory) handles the user interface and interactions (e.g., home page banners, registration, login, file upload with optional encryption).
- The back end (located in the “server” directory) implements RESTful endpoints for authentication, token refresh, file uploads, and interactions with AWS S3 for file storage. The server also manages user and file data in a database (inferred from the model files: User.js and File.js).

##### File Structure
- The “client” directory includes source code for components (like Home, Login, Register, Upload), global state management (with redux slices for auth, files, and API calls), and configuration files (e.g., Vite and Tailwind).
- The “server” directory is structured with clearly separated concerns:
- Configuration (database connection, CORS, allowed origins)
- Controllers (sub-divided into auth and file operations – plus utility functions for AWS S3 sessions, storage cap checks, etc.)
- Middleware (for tasks such as logging, JWT verification, error handling)
- Models (representing database entities like User and File)
- Routes linking endpoints to their corresponding controllers.
- This indicates the use of an MVC/MVC-like approach and middleware pipelines on the backend.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The clear split between client and server, plus within the server (controllers, middleware, models, configs), helps modularize functionality.
- API-Driven Communication: RESTful endpoints are defined for all key operations (login, register, refresh token, file uploads) with Redux slices handling API interactions on the front end.
- Security Patterns: Use of JWT for stateless authentication and refresh tokens for credential renewal.
- Scalability: The file upload process supports both single and multipart uploads, indicating a scalable design when dealing with large files.
- Reusability: Functionality like encryption and upload utilities are encapsulated in separate modules.

- Frontend Client (titled “Client – React Application”) with subcomponents for Home, Login, Register, Upload.
- Backend Server (labeled “API Server”) with subdivisions for Auth Controllers, File Controllers, Middleware, and Utility modules.
- Database (as an independent component) that connects to the backend.
- External AWS S3 Service (and optionally AWS STS) clearly marked as the external file storage provider.
- Data flow from user actions in the Frontend to the Backend.
- RESTful API interactions between the frontend and backend.
- Data persistence flows from the backend to the Database.
- External file upload flows (including the process for obtaining signed URLs, splitting files, and completing uploads with S3).

##### Final Details
- Be very detailed—ensure every significant module (such as each redux slice, controller, and middleware) is represented where it affects the overall flow.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client – React Application
    subgraph "Client – React Application"
        %% UI Components
        subgraph "UI Components"
            UI_Home["Home"]:::client
            UI_Login["Login"]:::client
            UI_Register["Register"]:::client
            UI_Upload["Upload"]:::client
            UI_FileList["File List"]:::client
            UI_Nav["Navigation"]:::client
            UI_PrivateRoute["Private Route"]:::client
        end
        %% State Management (Redux)
        subgraph "State Management (Redux)"
            Redux_Auth["Auth Slice"]:::client
            Redux_Api["API Slice"]:::client
            Redux_FileApi["File API Slice"]:::client
            Redux_FileData["File Data Slice"]:::client
            Redux_UsersApi["Users API Slice"]:::client
        end
        %% Utility Functions
        subgraph "Utility Functions"
            Util_Encrypt["Encryption Utility"]:::client
            Util_S3Upload["S3 Upload Utility"]:::client
            Util_Loader["Loader Utility"]:::client
        end
    end

    %% API Server
    subgraph "API Server"
        %% Authentication Controllers
        subgraph "Authentication Controllers"
            AuthController["Auth Controller"]:::server
            RegController["Registration Controller"]:::server
            LogoutController["Logout Controller"]:::server
            RefreshTokenController["Refresh Token Controller"]:::server
        end
        %% File Management Controllers
        subgraph "File Management Controllers"
            SingleUpload["Single File Upload"]:::server
            MultiUpload["Multi File Upload"]:::server
            DeleteFile["File Deletion Controller"]:::server
            DownloadFile["File Download Controller"]:::server
            ListFile["File Listing Controller"]:::server
            S3Session["AWS S3 Session Utility"]:::server
            STSSession["AWS STS Session Token Utility"]:::server
            StorageCap["Storage Capacity Check Utility"]:::server
        end
        %% User Management
        subgraph "User Management"
            UserController["User Controller"]:::server
        end
        %% Middleware
        subgraph "Middleware"
            MD_Credentials["Credentials Middleware"]:::server
            MD_Error["Error Handling Middleware"]:::server
            MD_Logging["Logging Middleware"]:::server
            MD_JWT["JWT Verification Middleware"]:::server
            MD_Roles["Role Verification Middleware"]:::server
        end
        %% Configuration
        subgraph "Configuration"
            Config_AllowedOrigins["Allowed Origins"]:::server
            Config_CORS["CORS Options"]:::server
            Config_dbConn["Database Connection"]:::server
        end
        %% Routes & Setup
        subgraph "Routes & Setup"
            Routes["Route Definitions"]:::server
            ServerStartup["Server Startup File"]:::server
        end
        %% Database Models
        subgraph "Database Models"
            FileModel["File Model"]:::server
            UserModel["User Model"]:::server
        end
    end

    %% External and Data Storage
    Database["Database"]:::database
    AWS_S3["AWS S3 Storage"]:::external
    AWS_STS["AWS STS"]:::external
    Request_Logging["Request Logging File"]:::logging

    %% Connections from Client to API Server
    UI_Login -- "POST_Login" --> AuthController
    UI_Register -- "POST_Register" --> RegController
    UI_Upload -- "File_Upload" --> SingleUpload
    UI_FileList -- "Fetch_Files" --> ListFile

    %% Connections within Client
    UI_Login -- "Update_State" --> Redux_Auth
    UI_Register -- "Update_State" --> Redux_Auth

    %% Token Refresh Flow
    RefreshTokenController -- "Token_Refresh" --> Redux_Auth

    %% API Server to Database Models and then Database
    AuthController -- "Persist_User" --> UserModel
    RegController -- "Persist_User" --> UserModel
    UserController -- "User_Data" --> UserModel
    SingleUpload -- "Save_File_Metadata" --> FileModel
    MultiUpload -- "Save_File_Metadata" --> FileModel
    DeleteFile -- "Update_File_Record" --> FileModel
    DownloadFile -- "Retrieve_File_Info" --> FileModel
    ListFile -- "Retrieve_File_List" --> FileModel

    FileModel -- "Store" --> Database
    UserModel -- "Store" --> Database

    %% API Server to External AWS Services
    SingleUpload -- "Get_Signed_URL" --> S3Session
    S3Session -- "Communicate" --> AWS_S3
    MultiUpload -- "Request_Temp_Creds" --> STSSession
    STSSession -- "Communicate" --> AWS_STS

    %% Logging Middleware to Request Logging
    MD_Logging -- "Log_Event" --> Request_Logging

    %% Class Definitions for styling
    classDef client fill:#AEDFF7,stroke:#000,stroke-width:2px;
    classDef server fill:#D1E8E2,stroke:#000,stroke-width:2px;
    classDef external fill:#FFECB3,stroke:#000,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#000,stroke-width:2px;
    classDef logging fill:#F5CBA7,stroke:#000,stroke-width:2px;

    %% Click Events for Client – UI Components
    click UI_Home "https://github.com/pleszyk/file_girl/blob/main/client/src/components/Home.jsx"
    click UI_Login "https://github.com/pleszyk/file_girl/blob/main/client/src/components/Login.jsx"
    click UI_Register "https://github.com/pleszyk/file_girl/blob/main/client/src/components/Register.jsx"
    click UI_Upload "https://github.com/pleszyk/file_girl/blob/main/client/src/components/Upload.jsx"
    click UI_FileList "https://github.com/pleszyk/file_girl/blob/main/client/src/components/FileList.jsx"
    click UI_Nav "https://github.com/pleszyk/file_girl/blob/main/client/src/components/Nav.jsx"
    click UI_PrivateRoute "https://github.com/pleszyk/file_girl/blob/main/client/src/components/PrivateRoute.jsx"

    %% Click Events for Client – State Management (Redux Slices)
    click Redux_Auth "https://github.com/pleszyk/file_girl/blob/main/client/src/slices/authSlice.js"
    click Redux_Api "https://github.com/pleszyk/file_girl/blob/main/client/src/slices/apiSlice.js"
    click Redux_FileApi "https://github.com/pleszyk/file_girl/blob/main/client/src/slices/fileApiSlice.js"
    click Redux_FileData "https://github.com/pleszyk/file_girl/blob/main/client/src/slices/fileSlice.js"
    click Redux_UsersApi "https://github.com/pleszyk/file_girl/blob/main/client/src/slices/usersApiSlice.js"

    %% Click Events for Client – Utility Functions
    click Util_Encrypt "https://github.com/pleszyk/file_girl/blob/main/client/src/util/encrypt.js"
    click Util_S3Upload "https://github.com/pleszyk/file_girl/blob/main/client/src/util/uploadToS3.js"
    click Util_Loader "https://github.com/pleszyk/file_girl/blob/main/client/src/util/Loader.jsx"

    %% Click Events for Backend – Authentication Controllers
    click AuthController "https://github.com/pleszyk/file_girl/blob/main/server/controllers/auth/authController.js"
    click RegController "https://github.com/pleszyk/file_girl/blob/main/server/controllers/auth/registerController.js"
    click LogoutController "https://github.com/pleszyk/file_girl/blob/main/server/controllers/auth/logoutController.js"
    click RefreshTokenController "https://github.com/pleszyk/file_girl/blob/main/server/controllers/auth/refreshTokenController.js"

    %% Click Events for Backend – File Management Controllers
    click SingleUpload "https://github.com/pleszyk/file_girl/blob/main/server/controllers/file/singleUploadController.js"
    click MultiUpload "https://github.com/pleszyk/file_girl/blob/main/server/controllers/file/multiUploadController.js"
    click DeleteFile "https://github.com/pleszyk/file_girl/blob/main/server/controllers/file/deleteFileController.js"
    click DownloadFile "https://github.com/pleszyk/file_girl/blob/main/server/controllers/file/downloadController.js"
    click ListFile "https://github.com/pleszyk/file_girl/blob/main/server/controllers/file/listFileController.js"
    click S3Session "https://github.com/pleszyk/file_girl/blob/main/server/controllers/file/util/s3Session.js"
    click STSSession "https://github.com/pleszyk/file_girl/blob/main/server/controllers/file/util/sessionToken.js"
    click StorageCap "https://github.com/pleszyk/file_girl/blob/main/server/controllers/file/util/storageCap.js"

    %% Click Event for Backend – User Management Controller
    click UserController "https://github.com/pleszyk/file_girl/blob/main/server/controllers/usersController.js"

    %% Click Events for Backend – Middleware
    click MD_Credentials "https://github.com/pleszyk/file_girl/blob/main/server/middleware/credentials.js"
    click MD_Error "https://github.com/pleszyk/file_girl/blob/main/server/middleware/errorHandler.js"
    click MD_Logging "https://github.com/pleszyk/file_girl/blob/main/server/middleware/logEvents.js"
    click MD_JWT "https://github.com/pleszyk/file_girl/blob/main/server/middleware/verifyJWT.js"
    click MD_Roles "https://github.com/pleszyk/file_girl/blob/main/server/middleware/verifyRoles.js"

    %% Click Events for Backend – Configuration
    click Config_AllowedOrigins "https://github.com/pleszyk/file_girl/blob/main/server/config/allowedOrigins.js"
    click Config_CORS "https://github.com/pleszyk/file_girl/blob/main/server/config/corsOptions.js"
    click Config_dbConn "https://github.com/pleszyk/file_girl/blob/main/server/config/dbConn.js"

    %% Click Events for Backend – Routes & Setup
    click Routes "https://github.com/pleszyk/file_girl/blob/main/server/routes/routes.js"
    click ServerStartup "https://github.com/pleszyk/file_girl/blob/main/server/server.js"

    %% Click Events for Backend – Database Models
    click FileModel "https://github.com/pleszyk/file_girl/blob/main/server/model/File.js"
    click UserModel "https://github.com/pleszyk/file_girl/blob/main/server/model/User.js"

    %% Click Event for Logging
    click Request_Logging "https://github.com/pleszyk/file_girl/blob/main/server/logs/reqLog.txt"
```
