# dinexh/filesharingsystem architecture

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

- Interactive diagram: https://gitdiagram.com/dinexh/filesharingsystem
- Repository: https://github.com/dinexh/filesharingsystem

## Overview

##### Project Type and Purpose
- This is a full-stack file-sharing web application.
- Frontend: React single-page app (SPA) providing authentication, upload/download UI, file browsing, theming.
- Backend: Spring Boot REST API that handles auth (JWT), file operations, user management, sharing logic, email notifications.
- Persistence: MySQL stores user and file metadata; filesystem “uploads” directory stores physical file blobs.
- External service: SMTP server for sharing notifications.

##### Main Components
a. Client (React SPA)
- Pages: auth (login/signup/reset), dashboard (home, files, shared, profile, settings, upload), home.
- Components: Header, Sidebar, FilesList, PDFViewer, ShareModal, ProfileForm, etc.
- Contexts: AuthContext, ThemeContext.
- Utilities: fileUtils.
b. API Layer (Spring Boot Controllers)
- AuthController, FileController, UserController, PasswordResetController.
c. Service Layer
- Business logic: UserService, FileService, EmailService, CustomUserDetailsService.
d. Persistence Layer
- Repositories using Spring Data JPA: UserRepository, FileRepository, FileShareRepository, StarredFileRepository.
- Entities: User, File, FileShare, StarredFile.
e. Security
- Stateless JWT filter chain: JwtAuthenticationFilter, JwtAuthenticationEntryPoint, JwtTokenProvider, SecurityConfig.
f. Database
- MySQL storing tables for users, files, shares, starred files.
g. File Storage
- Local filesystem directory (“uploads”) with UUID-renamed files.
h. External SMTP Service
- Configured via Spring Mail for notifications.

##### Relationships and Data Flows
- Browser ↔ React UI: user actions trigger API calls via fetch/axios.
- React UI ↔ Spring Boot API: HTTPS requests carrying JWT in Authorization header after login.
- Spring Boot Controllers delegate to Service layer.
- Service layer
- calls Repository layer (JPA) → MySQL
- reads/writes file blobs on filesystem
- uses JwtTokenProvider for token generation/validation
- invokes EmailService → SMTP server
- Security filter intercepts incoming requests to validate JWT and inject SecurityContext.

##### Architectural Patterns & Principles
- Layered architecture (Controller → Service → Repository).
- MVC-style separation in backend.
- Stateless REST with JWT for scalability.
- Single Page Application (SPA) architecture in frontend.
- Context API for global state (auth, theme).
- Responsiveness and theming on client.

##### Technologies & Frameworks
- Frontend: React, Context API, CSS modules, create-react-app tooling (webpack).
- Backend: Spring Boot, Spring MVC, Spring Security, Spring Data JPA, Maven, Java 11.
- Database: MySQL.
- File storage: Local filesystem.
- Email: Spring Mail (SMTP).
- Security: JWT.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "React SPA" 
        direction TB
        Browser["Browser"]:::frontend
        subgraph "Pages" 
            direction TB
            AuthPage["Auth Pages"]:::frontend
            DashboardPage["Dashboard Pages"]:::frontend
            HomePage["Home Page"]:::frontend
            ResetPage["Reset Password"]:::frontend
        end
        subgraph "Components"
            direction TB
            Header["Header"]:::frontend
            Sidebar["Sidebar"]:::frontend
            FilesList["FilesList"]:::frontend
            ShareModal["ShareModal"]:::frontend
            ProfileForm["ProfileForm"]:::frontend
            UploadArea["UploadArea"]:::frontend
            ProtectedRoute["ProtectedRoute"]:::frontend
        end
        subgraph "Contexts & Utils"
            direction TB
            AuthContext["AuthContext"]:::frontend
            ThemeContext["ThemeContext"]:::frontend
            FileUtils["fileUtils"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Spring Boot API" 
        direction TB
        SecurityFilter["JwtAuthenticationFilter & EntryPoint"]:::backend
        subgraph "Controllers"
            direction TB
            AuthController["AuthController"]:::backend
            FileController["FileController"]:::backend
            UserController["UserController"]:::backend
            PasswordResetController["PasswordResetController"]:::backend
        end
        subgraph "Services"
            direction TB
            UserService["UserService"]:::backend
            FileService["FileService"]:::backend
            EmailService["EmailService"]:::backend
            CustomUserDetailsService["CustomUserDetailsService"]:::backend
        end
        subgraph "Repositories"
            direction TB
            UserRepo["UserRepository"]:::backend
            FileRepo["FileRepository"]:::backend
            FileShareRepo["FileShareRepository"]:::backend
            StarredFileRepo["StarredFileRepository"]:::backend
        end
        subgraph "Security & Config"
            direction TB
            JwtTokenProvider["JwtTokenProvider"]:::backend
            SecurityConfig["SecurityConfig"]:::backend
            WebConfig["WebConfig"]:::backend
            BackendApp["BackendApplication"]:::backend
        end
    end

    %% External Systems
    MySQL["MySQL Database"]:::external
    FileStorage["File Storage (uploads)"]:::external
    SMTP["SMTP Email Service"]:::external

    %% Data Flows
    Browser -->|HTTPS + JWT| SecurityFilter
    SecurityFilter --> AuthController
    SecurityFilter --> FileController
    SecurityFilter --> UserController
    SecurityFilter --> PasswordResetController
    AuthController -->|calls| UserService
    FileController -->|calls| FileService
    UserController -->|calls| UserService
    PasswordResetController -->|calls| UserService
    UserService -->|JPA| UserRepo
    FileService -->|JPA| FileRepo
    FileService -->|JPA| FileShareRepo
    FileService -->|JPA| StarredFileRepo
    FileService -->|File I/O| FileStorage
    FileService -->|uses| JwtTokenProvider
    EmailService -->|SMTP send| SMTP
    UserService -->|uses| EmailService
    UserService -->|uses| CustomUserDetailsService

    %% Click Events Frontend
    click AuthPage "https://github.com/dinexh/filesharingsystem/blob/main/client/src/pages/auth/page.js"
    click DashboardPage "https://github.com/dinexh/filesharingsystem/blob/main/client/src/pages/dashboard/page.js"
    click HomePage "https://github.com/dinexh/filesharingsystem/blob/main/client/src/pages/home/page.js"
    click ResetPage "https://github.com/dinexh/filesharingsystem/blob/main/client/src/pages/reset-password/page.js"
    click Header "https://github.com/dinexh/filesharingsystem/blob/main/client/src/components/Dashboard/Header.js"
    click Sidebar "https://github.com/dinexh/filesharingsystem/blob/main/client/src/components/Dashboard/Sidebar.js"
    click FilesList "https://github.com/dinexh/filesharingsystem/blob/main/client/src/components/Files/FilesList.js"
    click ShareModal "https://github.com/dinexh/filesharingsystem/blob/main/client/src/components/Files/ShareModal.js"
    click ProfileForm "https://github.com/dinexh/filesharingsystem/blob/main/client/src/components/Profile/ProfileForm.js"
    click UploadArea "https://github.com/dinexh/filesharingsystem/blob/main/client/src/components/Upload/UploadArea.js"
    click ProtectedRoute "https://github.com/dinexh/filesharingsystem/blob/main/client/src/components/Auth/ProtectedRoute.js"
    click AuthContext "https://github.com/dinexh/filesharingsystem/blob/main/client/src/context/AuthContext.js"
    click ThemeContext "https://github.com/dinexh/filesharingsystem/blob/main/client/src/context/ThemeContext.js"
    click FileUtils "https://github.com/dinexh/filesharingsystem/blob/main/client/src/utils/fileUtils.js"

    %% Click Events Backend
    click AuthController "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/controller/AuthController.java"
    click FileController "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/controller/FileController.java"
    click UserController "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/controller/UserController.java"
    click PasswordResetController "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/controller/PasswordResetController.java"
    click UserService "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/service/UserService.java"
    click FileService "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/service/FileService.java"
    click EmailService "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/service/EmailService.java"
    click CustomUserDetailsService "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/service/CustomUserDetailsService.java"
    click UserRepo "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/repository/UserRepository.java"
    click FileRepo "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/repository/FileRepository.java"
    click FileShareRepo "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/repository/FileShareRepository.java"
    click StarredFileRepo "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/repository/StarredFileRepository.java"
    click JwtTokenProvider "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/security/JwtTokenProvider.java"
    click SecurityConfig "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/security/SecurityConfig.java"
    click WebConfig "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/config/WebConfig.java"
    click BackendApp "https://github.com/dinexh/filesharingsystem/blob/main/backend/src/main/java/com/filesharing/backend/BackendApplication.java"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef backend fill:#D0FFD0,stroke:#333,stroke-width:1px
    classDef external fill:#FFE0B2,stroke:#333,stroke-width:1px
```
