# kuzma02/secured-file-share architecture

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

- Interactive diagram: https://gitdiagram.com/kuzma02/secured-file-share
- Repository: https://github.com/kuzma02/secured-file-share

## Overview

##### Project type and purpose
- This is a full-stack web application (“Secured File Share”) built with the MERN stack (MongoDB, Express.js, React, Node.js).
- Purpose: allow users to upload/download files securely with end-to-end encryption, password protection, brute-force protection, input sanitization, and email notifications.

##### File structure
- Root:
- app.js – entry point for the Express server
- routes/main.js – defines REST endpoints (upload, download, history, etc.)
- controllers/ – implements business logic (main.js handles file operations; sendEmail.js handles Mailjet integration)
- db/connect.js – MongoDB connection setup
- models/File.js – Mongoose schema for file metadata
- package.json & .env – server dependencies and config
- client/:
- index.html, vite.config.js, tailwind.config.js – front-end build/config
- src/: React code (pages, components, assets)
- package.json – React, Vite, Clerk (authentication), Tailwind CSS
- uploads/ (created at runtime) – local file storage for encrypted payloads

##### README for additional insights
- Security measures: Helmet, express-mongo-sanitize, xss-clean, rate-limiting
- External services: Clerk for authentication, Mailjet for transactional emails
- Deployment: Node.js server and Vite dev server

##### Main components and their interactions
a. Front-End (React/Vite)
- Pages/components under client/src
- Responsible for UI: upload forms, password prompts, file history, download pages
- Auth flow via Clerk (VITE_CLERK_PUBLISHABLE_KEY)
b. API Layer (Express.js server)
- app.js configures middleware (CORS, security headers, rate-limit, sanitizers)
- routes/main.js delegates to controllers
- controllers/main.js: handle encryption/decryption, file I/O, input validation
- controllers/sendEmail.js: integrate with Mailjet API to send download links
c. Data Layer
- MongoDB (db/connect.js + models/File.js) stores file metadata (owner, filename, encryption key hash, password hash, expiration)
- File System (“uploads/” directory) stores encrypted binaries
d. External Services
- Clerk (Auth provider) for user identity management
- Mailjet API for email notifications

Relationships & data flow:
1. User (Browser) ↔ Clerk (OAuth/webhooks)
2. Browser → Express API (/api/upload, /api/request-download)
3. Express → MongoDB (CRUD on File metadata)
4. Express → File System (read/write encrypted files)
5. Express → Mailjet (send download password/email link)
6. Browser ← Express API (download streams, history data)

##### Architectural patterns and design principles
- Layered MVC-style structure:
Presentation (React UI) ↔ Controllers (Express) ↔ Models (Mongoose)
- Security-first: centralized middleware for sanitization, rate-limiting, headers
- Single codebase separation: “client” folder vs. server root
- RESTful API design

##### Essential details to capture
- Separation of concerns: UI vs. API vs. Data
- Security middleware chain in Express
- End-to-end encryption flow (client encrypts → server stores encrypted → client decrypts)
- Password protection and validation logic
- External auth (Clerk) and email service (Mailjet) integration points

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["Browser"]:::external
        Clerk["Clerk (Auth)"]:::external
        subgraph "React App"
            direction TB
            Main["main.jsx"]:::frontend
            App["App.jsx"]:::frontend
            subgraph "Pages"
                direction TB
                Landing["Landing.jsx"]:::frontend
                ApplicationLayout["ApplicationLayout.jsx"]:::frontend
                ApplicationPage["ApplicationPage.jsx"]:::frontend
                FileDownload["FileDownload.jsx"]:::frontend
                FileHistory["FileHistory.jsx"]:::frontend
                UserProfile["UserProfilePage.jsx"]:::frontend
            end
            subgraph "Components"
                direction TB
                UploadForm["UploadForm.jsx"]:::frontend
                AdvancedPasswordInput["AdvancedPasswordInput.jsx"]:::frontend
                FilePreview["FilePreview.jsx"]:::frontend
                ProgressBar["ProgressBar.jsx"]:::frontend
                CopyBtn["CopyToClipboardBtn.jsx"]:::frontend
                ApplicationTabs["ApplicationTabs.jsx"]:::frontend
                OtherComps["Shared Components"]:::frontend
            end
        end
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        APIServer["app.js"]:::backend
        Middleware["Security Middleware\n(Helmet, sanitizers,\nrate-limit)"]:::backend
        Routes["routes/main.js"]:::backend
        subgraph "Controllers"
            direction TB
            FileCtrl["controllers/main.js"]:::backend
            EmailCtrl["controllers/sendEmail.js"]:::backend
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MongoConn["db/connect.js"]:::data
        FileModel["models/File.js"]:::data
        MongoDB["MongoDB Atlas"]:::data
        UploadFS["uploads/"]:::data
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Mailjet["Mailjet API"]:::external
    end

    %% Data Flows & Interactions
    Browser -->|uses UI| App
    Browser -->|auth requests| Clerk
    Clerk -->|auth tokens| Browser
    Browser -->|API calls| APIServer
    APIServer -->|passes through| Middleware
    Middleware -->|routes to| Routes
    Routes -->|calls| FileCtrl
    Routes -->|calls| EmailCtrl
    FileCtrl -->|uses connection| MongoConn
    MongoConn -->|defines schema| FileModel
    FileModel -->|reads/writes| MongoDB
    FileCtrl -->|stores/files| UploadFS
    EmailCtrl -->|sends email| Mailjet
    APIServer -->|responses| Browser

    %% Click Events
    click Main "https://github.com/kuzma02/secured-file-share/blob/main/client/src/main.jsx"
    click App "https://github.com/kuzma02/secured-file-share/blob/main/client/src/App.jsx"
    click Landing "https://github.com/kuzma02/secured-file-share/blob/main/client/src/pages/Landing.jsx"
    click ApplicationLayout "https://github.com/kuzma02/secured-file-share/blob/main/client/src/pages/ApplicationLayout.jsx"
    click ApplicationPage "https://github.com/kuzma02/secured-file-share/blob/main/client/src/pages/ApplicationPage.jsx"
    click FileDownload "https://github.com/kuzma02/secured-file-share/blob/main/client/src/pages/FileDownload.jsx"
    click FileHistory "https://github.com/kuzma02/secured-file-share/blob/main/client/src/pages/FileHistory.jsx"
    click UserProfile "https://github.com/kuzma02/secured-file-share/blob/main/client/src/pages/UserProfilePage.jsx"
    click UploadForm "https://github.com/kuzma02/secured-file-share/blob/main/client/src/components/UploadForm.jsx"
    click AdvancedPasswordInput "https://github.com/kuzma02/secured-file-share/blob/main/client/src/components/AdvancedPasswordInput.jsx"
    click FilePreview "https://github.com/kuzma02/secured-file-share/blob/main/client/src/components/FilePreview.jsx"
    click ProgressBar "https://github.com/kuzma02/secured-file-share/blob/main/client/src/components/ProgressBar.jsx"
    click CopyBtn "https://github.com/kuzma02/secured-file-share/blob/main/client/src/components/CopyToClipboardBtn.jsx"
    click ApplicationTabs "https://github.com/kuzma02/secured-file-share/blob/main/client/src/components/ApplicationTabs.jsx"
    click OtherComps "https://github.com/kuzma02/secured-file-share/tree/main/client/src/components/"
    click APIServer "https://github.com/kuzma02/secured-file-share/blob/main/app.js"
    click Routes "https://github.com/kuzma02/secured-file-share/blob/main/routes/main.js"
    click FileCtrl "https://github.com/kuzma02/secured-file-share/blob/main/controllers/main.js"
    click EmailCtrl "https://github.com/kuzma02/secured-file-share/blob/main/controllers/sendEmail.js"
    click MongoConn "https://github.com/kuzma02/secured-file-share/blob/main/db/connect.js"
    click FileModel "https://github.com/kuzma02/secured-file-share/blob/main/models/File.js"

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