# manrajak/file_trans architecture

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

- Interactive diagram: https://gitdiagram.com/manrajak/file_trans
- Repository: https://github.com/manrajak/file_trans

## Overview

##### Project Type and Purpose
- Full-stack web application for secure file upload, sharing, and download
- Client: React + Redux (UI, state management)
- Server: Node.js + Express (REST API, business logic)
- Data stores: MongoDB Atlas (metadata), AWS S3 (file storage)
- External services: SMTP (Gmail via Nodemailer), optional QR-code service

##### Main Architectural Components
a. Frontend (Client)
– React components (pages, dashboards, auth guards)
– Redux Toolkit slices & thunks (authSlice, fileSlice)
– Axios instance (HTTP client)
– Tailwind CSS for styling
b. Backend (Server)
– Express app (app.js, index.js)
– MVC pattern:
- Controllers (user.controller.js, file.controller.js)
- Models (user.models.js, file.models.js)
- Routes (user.routes.js, file.routes.js)
– Middlewares (auth.middlewares.js for JWT, upload.middlewares.js for parsing multipart/form-data)
– Config modules (s3.js for AWS SDK, db/index.js for MongoDB connection)
– Constants (constant.js for app-wide settings)
c. Data Stores & External Services
– MongoDB Atlas (user & file metadata)
– AWS S3 bucket (actual file blobs)
– Gmail SMTP via Nodemailer (email notifications)
– (Optional) QR-code generation library

##### Interactions & Data Flow
- User opens React UI → Redux state manages session → Axios sends HTTP requests to Express API
- Authentication flow:
– Login/Signup request → user.controller → MongoDB → JWT issued → stored in client (localStorage)
– Protected routes in React check JWT, RequireAuth middleware on server validates token
- File upload flow:
– Client selects file → UploadPage component dispatches fileThunk → Axios multipart POST to `/api/files/upload`
– upload.middleware parses file → file.controller calls s3.upload → file metadata saved in MongoDB → returns short URL
- File download flow:
– User navigates to share link → Express route fetches S3 URL or streams file → Express updates download count → client triggers browser download
- Email notification flow:
– file.controller calls Nodemailer service → Gmail SMTP sends link to recipient

##### Architectural Patterns & Design Principles
– Separation of Concerns: UI vs. State vs. API vs. Database vs. Storage
– Layered Architecture:
1. Presentation (React)
2. Application (Redux, Axios)
3. API (Express routes/controllers)
4. Service/Integration (AWS SDK, Nodemailer)
5. Persistence (MongoDB)
– JWT-based authentication (stateless, token in header)
– RESTful API design (CRUD endpoints for users/files)
– Cloud-native storage handling (S3 abstraction via config module)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Layer
    User["User Browser"]:::user

    %% Frontend Layer
    subgraph "Frontend (UI Layer)"
        direction TB
        ReactComp["React Components"]:::frontend
        AuthGuard1["RequireAuth.jsx"]:::frontend
        AuthGuard2["NotRequireAuth.jsx"]:::frontend
        DashboardComp["Dashboard Components"]:::frontend
        OtherUI["Other UI Components"]:::frontend
        Axios["Axios HTTP Client"]:::frontend
        ReduxStore["Redux Store"]:::frontend
        AuthSlice["Auth Slice & Thunks"]:::frontend
        FileSlice["File Slice & Thunks"]:::frontend
        Tailwind["Tailwind CSS Config"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express API)" 
        direction TB
        EntryIndex["index.js"]:::backend
        App["app.js"]:::backend
        subgraph Controllers
            direction TB
            UserCtrl["user.controller.js"]:::backend
            FileCtrl["file.controller.js"]:::backend
        end
        subgraph Models
            direction TB
            UserModel["user.models.js"]:::backend
            FileModel["file.models.js"]:::backend
        end
        subgraph Routes
            direction TB
            UserRoutes["user.routes.js"]:::backend
            FileRoutes["file.routes.js"]:::backend
        end
        subgraph Middlewares
            direction TB
            AuthMiddleware["auth.middlewares.js"]:::backend
            UploadMiddleware["upload.middlewares.js"]:::backend
        end
        ConfigS3["AWS S3 Config (s3.js)"]:::backend
        DBConn["MongoDB Connection (db/index.js)"]:::backend
        Constants["Application Constants"]:::backend
    end

    %% Data & External Services
    MongoDB["MongoDB Atlas"]:::database
    S3["AWS S3 Storage"]:::storage
    SMTP["Gmail SMTP (Nodemailer)"]:::external
    QRService["QR-Code Service"]:::external

    %% Connections
    User -->|"interacts"| ReactComp
    ReactComp -->|"uses"/api/*| Axios
    ReactComp -->|guards| AuthGuard1
    ReactComp -->|guards| AuthGuard2
    ReactComp -->|renders| DashboardComp
    ReactComp -->|renders| OtherUI
    ReactComp -->|dispatch| ReduxStore
    ReduxStore -->|has slices| AuthSlice
    ReduxStore -->|has slices| FileSlice
    ReactComp -->|styles via| Tailwind

    Axios -->|HTTP requests| EntryIndex
    EntryIndex -->|uses| App
    App -->|registers routes| UserRoutes
    App -->|registers routes| FileRoutes
    UserRoutes -->|calls| UserCtrl
    FileRoutes -->|calls| FileCtrl
    App -->|uses middleware| AuthMiddleware
    FileRoutes -->|uses middleware| UploadMiddleware

    UserCtrl -->|CRUD| UserModel
    FileCtrl -->|CRUD| FileModel
    FileCtrl -->|uploads to| S3
    FileCtrl -->|saves metadata| MongoDB
    FileCtrl -->|sends email| SMTP
    FileCtrl -->|generates QR| QRService
    UserCtrl -->|reads/writes| MongoDB

    ConfigS3 -->|configures| S3
    DBConn -->|connects to| MongoDB
    Constants -->|provides| App

    %% Click Events
    click ReactComp "https://github.com/manrajak/file_trans/tree/main/client/src/components"
    click AuthGuard1 "https://github.com/manrajak/file_trans/blob/main/client/src/components/Auth/RequireAuth.jsx"
    click AuthGuard2 "https://github.com/manrajak/file_trans/blob/main/client/src/components/Auth/NotRequireAuth.jsx"
    click DashboardComp "https://github.com/manrajak/file_trans/tree/main/client/src/components/Dashboard"
    click OtherUI "https://github.com/manrajak/file_trans/tree/main/client/src/components"
    click Axios "https://github.com/manrajak/file_trans/blob/main/client/src/config/axiosInstance.js"
    click ReduxStore "https://github.com/manrajak/file_trans/blob/main/client/src/redux/store.js"
    click AuthSlice "https://github.com/manrajak/file_trans/blob/main/client/src/redux/slice/auth/authSlice.js"
    click FileSlice "https://github.com/manrajak/file_trans/blob/main/client/src/redux/slice/file/fileSlice.js"
    click Tailwind "https://github.com/manrajak/file_trans/blob/main/client/tailwind.config.js"
    click EntryIndex "https://github.com/manrajak/file_trans/blob/main/server/src/index.js"
    click App "https://github.com/manrajak/file_trans/blob/main/server/src/app.js"
    click UserCtrl "https://github.com/manrajak/file_trans/blob/main/server/src/controllers/user.controller.js"
    click FileCtrl "https://github.com/manrajak/file_trans/blob/main/server/src/controllers/file.controller.js"
    click UserModel "https://github.com/manrajak/file_trans/blob/main/server/src/models/user.models.js"
    click FileModel "https://github.com/manrajak/file_trans/blob/main/server/src/models/file.models.js"
    click UserRoutes "https://github.com/manrajak/file_trans/blob/main/server/src/routes/user.routes.js"
    click FileRoutes "https://github.com/manrajak/file_trans/blob/main/server/src/routes/file.routes.js"
    click AuthMiddleware "https://github.com/manrajak/file_trans/blob/main/server/src/middlewares/auth.middlewares.js"
    click UploadMiddleware "https://github.com/manrajak/file_trans/blob/main/server/src/middlewares/upload.middlewares.js"
    click ConfigS3 "https://github.com/manrajak/file_trans/blob/main/server/src/config/s3.js"
    click DBConn "https://github.com/manrajak/file_trans/blob/main/server/src/db/index.js"
    click Constants "https://github.com/manrajak/file_trans/blob/main/server/src/constant.js"

    %% Styles
    classDef user fill:#E0F7FA,stroke:#006064
    classDef frontend fill:#E3F2FD,stroke:#1E88E5
    classDef backend fill:#E8F5E9,stroke:#43A047
    classDef database fill:#FFF3E0,stroke:#FB8C00
    classDef storage fill:#FFF9C4,stroke:#FDD835
    classDef external fill:#F3E5F5,stroke:#8E24AA
```
