# sprinting/filebox architecture

> Architecture diagram of the GitHub repository sprinting/filebox, 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/sprinting/filebox
- Repository: https://github.com/sprinting/filebox

## Overview

##### Project Type and Purpose
- FileBox is a web application built on the Java Servlet API (v3.1) deployed on a Tomcat 8 server.
- It uses a simple MVC pattern where the presentation is handled via JSP, HTML, CSS, and JavaScript; the business logic is implemented in the servlet and service layers; and security is managed via custom classes for JSON Web Tokens and session management.
- Key features include Login/Logout, session management, file upload/download, and JSON Web Token based verification.

##### Analyzing the File Structure
- WebContent Folder:
– Contains the static and view components: JSP pages (dashboard.jsp, index.jsp), HTML (upload.html), CSS (dashboard.css) and JavaScript (dashboard.js).
– Also contains deployment descriptors and configuration (WEB-INF/web.xml) along with library dependencies.
- src Directory:
– Contains several packages:
- security: Implements authentication and token management (BCrypt, JsonTokenVerifier, JsonWebToken etc.). Also holds exception classes and managers like DashboardManager, UploadManager, and SQLManager.
- service: Houses servlets handling various functionalities (LoginInit, Logout, Dashboard, FileShare, FileDownload, ReceiveSharedFile) and filters (IndexFilter, LoggedInFilter) that manage request flow.
- examples and tests: Provide a reference example (ExampleFileUploader) and unit tests for security and service functionality.

##### Key Components and Their Interactions
– Client/Browser: Initiates requests through the user interface by interacting with HTML forms, JSP pages, and JavaScript.
– Web Server (Tomcat): Hosts the application and manages the execution of servlets.
– Presentation Layer (View):
- Located in WebContent (JSP, HTML, CSS, JS files).
- Responsible for rendering the UI to the user.
– Controller/Service Layer:
- Servlets found in the src/service package handle HTTP requests.
- Filters (IndexFilter, LoggedInFilter) pre-process requests to manage sessions and restrict access.
– Security Module:
- The src/security package contains logic for authentication and authorization using BCrypt for password hashing and JSON Web Tokens for stateless operations.
- Security managers (DashboardManager, UploadManager) and token verification classes (JsonTokenVerifier, JsonWebToken) are central to this module.
– Data Access/Management (Optional/Abstraction):
- SQLManager suggests that there is a component interacting with databases, even if the actual data store isn’t detailed here.
– Testing Suite:
- Located in src/tests, includes unit tests ensuring the correctness of security and service components.

##### Architectural Patterns and Design Principles
- MVC Pattern: Clear separation of concerns between the view (WebContent), controller (servlets and filters), and model (service/business logic in security and service packages).
- Security Best Practices: Use of JSON Web Tokens for stateless verification and BCrypt for secure password handling.
- Layered Architecture: There is a distinct separation between presentation, controller/service, and security/data access layers.

- Client (Browser)
- Web Server (Tomcat container)
- Presentation Layer: WebContent (JSP, HTML, CSS, JavaScript)
- Controller/Service Layer: Servlets (LoginInit, Logout, FileShare, FileDownload, etc.) and Filters (IndexFilter, LoggedInFilter)
- Security Module: All classes under src/security (BCrypt, JsonTokenVerifier, JsonWebToken, etc.)
- Testing Suite: Indicate as a separate component or note that tests run against various modules.
– From Browser to Web Server (HTTP requests).
– Between the Presentation Layer to Controller layer (user actions triggering servlets).
– From Controllers to Security Module (for authentication and authorization tasks).
– From Controllers (or Security) to Data Access if applicable.

## Diagram (Mermaid)

```mermaid
graph TD
    A["Browser (Client)"]:::frontend
    B["Web Server (Tomcat)"]:::backend

    subgraph "Presentation Layer"
        C1["dashboard.jsp"]:::presentation
        C2["index.jsp"]:::presentation
        C3["upload.html"]:::presentation
        C4["dashboard.css"]:::presentation
        C5["dashboard.js"]:::presentation
    end

    subgraph "Controller/Service Layer"
        D1["LoginInit Servlet"]:::controller
        D2["Logout Servlet"]:::controller
        D3["Dashboard Servlet"]:::controller
        D4["FileShare Servlet"]:::controller
        D5["FileDownload Servlet"]:::controller
        D6["ReceiveSharedFile Servlet"]:::controller
        subgraph "Request Filters"
            F1["IndexFilter"]:::filter
            F2["LoggedInFilter"]:::filter
        end
    end

    subgraph "Security Module"
        S1["BCrypt"]:::security
        S2["JsonTokenVerifier"]:::security
        S3["JsonWebToken"]:::security
        S4["DashboardManager"]:::security
        S5["UploadManager"]:::security
        S6["(Exception Classes)"]:::security
    end

    subgraph "Data Access"
        DA["SQLManager"]:::data
    end

    subgraph "Testing Suite"
        T1["BCryptTest"]:::testing
        T2["StringTest"]:::testing
        T3["TestLoginManager"]:::testing
        T4["TokenManager"]:::testing
    end

    subgraph "Example/Reference"
        E1["ExampleFileUploader"]:::example
    end

    %% Connections
    A -->|"HTTPRequest"| B

    %% Web Server distributes view resources and processes actions
    B -->|"Delivers View"| C1
    B --> C2
    B --> C3
    B --> C4
    B --> C5

    %% User actions from Presentation Layer to Controller Layer
    C2 -->|"loginRequest"| D1
    C1 -->|"dashboardRequest"| D3
    C3 -->|"fileUploadRequest"| D4

    %% Request Filters intercept requests before controllers
    F1 -->|"preprocess"| D1
    F2 -->|"checkSession"| D3

    %% Controllers delegate authentication and token verification to Security Module
    D1 -->|"authenticate"| S2
    D4 -->|"verifyToken"| S3

    %% Security Managers interact with Data Access
    S4 -->|"dbOperation"| DA
    S5 --> DA

    %% Example usage connection (Reference implementation for uploads)
    E1 -->|"demonstrates"| D4

    %% Styles 
    classDef presentation fill:#ffe6e6,stroke:#b30000,stroke-width:2px;
    classDef controller fill:#e6f0ff,stroke:#005ce6,stroke-width:2px;
    classDef filter fill:#e6ffe6,stroke:#009933,stroke-width:2px;
    classDef security fill:#fff0cc,stroke:#cc7a00,stroke-width:2px;
    classDef data fill:#e6ffe6,stroke:#2d862d,stroke-width:2px;
    classDef testing fill:#e6f9ff,stroke:#0080ff,stroke-width:2px;
    classDef example fill:#fff5cc,stroke:#e6b800,stroke-width:2px;
    classDef frontend fill:#f2e6ff,stroke:#8000ff,stroke-width:2px;
    classDef backend fill:#e6f9e6,stroke:#008000,stroke-width:2px;

    %% Click Events for Presentation Layer
    click C1 "https://github.com/sprinting/filebox/blob/move/WebContent/dashboard.jsp"
    click C2 "https://github.com/sprinting/filebox/blob/move/WebContent/index.jsp"
    click C3 "https://github.com/sprinting/filebox/blob/move/WebContent/upload.html"
    click C4 "https://github.com/sprinting/filebox/blob/move/WebContent/dashboard.css"
    click C5 "https://github.com/sprinting/filebox/blob/move/WebContent/dashboard.js"

    %% Click Events for Controller/Service Layer (Servlets)
    click D1 "https://github.com/sprinting/filebox/blob/move/src/service/LoginInit.java"
    click D2 "https://github.com/sprinting/filebox/blob/move/src/service/Logout.java"
    click D3 "https://github.com/sprinting/filebox/blob/move/src/service/Dashboard.java"
    click D4 "https://github.com/sprinting/filebox/blob/move/src/service/FileShare.java"
    click D5 "https://github.com/sprinting/filebox/blob/move/src/service/FileDownload.java"
    click D6 "https://github.com/sprinting/filebox/blob/move/src/service/ReceiveSharedFile.java"

    %% Click Events for Request Filters
    click F1 "https://github.com/sprinting/filebox/blob/move/src/service/filters/IndexFilter.java"
    click F2 "https://github.com/sprinting/filebox/blob/move/src/service/filters/LoggedInFilter.java"

    %% Click Events for Security Module
    click S1 "https://github.com/sprinting/filebox/blob/move/src/security/BCrypt.java"
    click S2 "https://github.com/sprinting/filebox/blob/move/src/security/JsonTokenVerifier.java"
    click S3 "https://github.com/sprinting/filebox/blob/move/src/security/JsonWebToken.java"
    click S4 "https://github.com/sprinting/filebox/blob/move/src/security/DashboardManager.java"
    click S5 "https://github.com/sprinting/filebox/blob/move/src/security/UploadManager.java"

    %% Click Event for Data Access Component
    click DA "https://github.com/sprinting/filebox/blob/move/src/security/SQLManager.java"

    %% Click Events for Testing Suite
    click T1 "https://github.com/sprinting/filebox/blob/move/src/tests/BCryptTest.java"
    click T2 "https://github.com/sprinting/filebox/blob/move/src/tests/StringTest.java"
    click T3 "https://github.com/sprinting/filebox/blob/move/src/tests/TestLoginManager.java"
    click T4 "https://github.com/sprinting/filebox/blob/move/src/tests/TokenManager.java"

    %% Click Event for Example/Reference Implementation
    click E1 "https://github.com/sprinting/filebox/blob/move/src/examples/ExampleFileUploader.java"
```
