# saifullah-dev/react-file-manager architecture

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

- Interactive diagram: https://gitdiagram.com/saifullah-dev/react-file-manager
- Repository: https://github.com/saifullah-dev/react-file-manager

## Overview

##### Project type and purpose
- It’s an open-source React.js package (“@cubone/react-file-manager”) that provides a file-manager UI.
- A “backend” directory contains a sample Node/Express (with Swagger) implementation persisting metadata in MongoDB and storing uploads on disk.

##### Main components
a. Frontend (React component + consumer app)
- FileManager component (src/FileManager/*)
- Context Providers (ClipboardContext, FilesContext, etc.)
- API layer (src/api/*.js)
- Utilities/hooks (useFileIcons, useShortcutHandler, etc.)
b. Backend API (Node + Express + Swagger)
- Entry point: server.js
- Routes: fileSystem.routes.js
- Controllers: uploadFile, getItems, deleteItem, renameItem, etc.
- Middlewares: multer (file uploads), error handler
- Models: FileSystem.model.js (MongoDB schema)
- Configuration: db.config.js, .env variables
- Swagger docs (swagger.js, swagger-output.json)
c. Database
- MongoDB (“fileManagerDB”) for folder/file metadata
d. File Storage
- Local disk “backend/public/uploads” for binary file storage
e. Optional External Services
- Custom file-preview base URL (filePreviewPath prop)
- Any external storage/CDN if user swaps in their own backend

##### Relationships & data flow
- User interacts with React UI → UI dispatches action via context or toolbar/context menu
- UI calls a src/api/*.js endpoint (e.g. uploadFileAPI) → HTTP request to Express server
- Express route → middleware (multer for multipart uploads or JSON parsing) → controller
- Controller logic → Model layer (Mongoose) to read/write metadata in MongoDB
- For uploads: also writes file to local disk
- Controller responds to client → UI updates via onSuccess callback and context state

##### Architectural patterns & design principles
- Frontend
- Component-based design (FileManager, Buttons, Modal, ContextMenu)
- Context API for global state (files list, navigation, clipboard)
- Hooks for reusable logic (keyboard shortcuts, outside-click)
- Separation of concerns: UI <→> API modules <→> contexts
- Backend
- MVC-style: routes → controllers → models
- Middleware for cross-cutting concerns (error handling, file parsing)
- Environment-based configuration (.env)
- API documentation via Swagger

- Clear, human-readable labels (e.g., “FileManager Component”, “Express Server: server.js”)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client (Frontend)"
        direction TB
        FMComp["FileManager Component"]:::frontend
        FMCompDir["FileManager Directory"]:::frontend
        FMCompIndex["FileManager Index"]:::frontend
        subgraph "Context Providers"
            direction TB
            Clipboard["ClipboardContext"]:::frontend
            FilesCtx["FilesContext"]:::frontend
            NavCtx["FileNavigationContext"]:::frontend
            LayoutCtx["LayoutContext"]:::frontend
            SelectionCtx["SelectionContext"]:::frontend
            TransProv["TranslationProvider"]:::frontend
        end
        subgraph "API Layer"
            direction TB
            BaseAPI["api.js"]:::frontend
            CreateFolderAPI["createFolderAPI.js"]:::frontend
            DeleteAPI["deleteAPI.js"]:::frontend
            DownloadAPI["downloadFileAPI.js"]:::frontend
            FileTransferAPI["fileTransferAPI.js"]:::frontend
            GetAllFilesAPI["getAllFilesAPI.js"]:::frontend
            RenameAPI["renameAPI.js"]:::frontend
        end
        subgraph "Hooks & Utilities"
            direction TB
            HooksDir["Hooks Directory"]:::frontend
            UtilsDir["Utils Directory"]:::frontend
        end
    end

    %% Server Side
    subgraph "Server (Backend)"
        direction TB
        Express["Express Server: server.js"]:::backend
        EnvExample["Env Example: .env.example"]:::backend
        subgraph "Configuration"
            direction TB
            DBConfig["db.config.js"]:::backend
        end
        subgraph "Routes"
            direction TB
            Routes["fileSystem.routes.js"]:::backend
        end
        subgraph "Middlewares"
            direction TB
            Multer["multer.middleware.js"]:::backend
            ErrorHandler["errorHandler.middleware.js"]:::backend
        end
        subgraph "Controllers"
            direction TB
            UploadCtrl["uploadFile.controller.js"]:::backend
            GetItemsCtrl["getItems.controller.js"]:::backend
            DeleteCtrl["deleteItem.controller.js"]:::backend
            RenameCtrl["renameItem.controller.js"]:::backend
            CreateFolderCtrl["createFolder.controller.js"]:::backend
            CopyItemCtrl["copyItem.controller.js"]:::backend
            MoveItemCtrl["moveItem.controller.js"]:::backend
            DownloadFileCtrl["downloadFile.controller.js"]:::backend
        end
        subgraph "Models"
            direction TB
            FSModel["FileSystem.model.js"]:::backend
        end
        subgraph "Swagger"
            direction TB
            SwaggerSetup["swagger.js"]:::backend
            SwaggerOutput["swagger-output.json"]:::backend
        end
    end

    %% Database and Storage
    DB[(MongoDB)]:::db
    Storage[/Local File Storage/]:::storage
    External["Optional External Services"]:::external

    %% Data Flows
    FMComp -->|"uses Context"| Clipboard
    FMComp --> FilesCtx
    FMComp --> NavCtx
    FMComp --> LayoutCtx
    FMComp --> SelectionCtx
    FMComp --> TransProv
    FMComp --> BaseAPI
    BaseAPI -->|HTTP REST| Express
    CreateFolderAPI --> BaseAPI
    DeleteAPI --> BaseAPI
    DownloadAPI --> BaseAPI
    FileTransferAPI --> BaseAPI
    GetAllFilesAPI --> BaseAPI
    RenameAPI --> BaseAPI
    HooksDir --> FMComp
    UtilsDir --> FMComp

    Express -->|routes| Routes
    Routes -->|middleware| Multer
    Routes -->|middleware| ErrorHandler
    Routes -->|controller call| UploadCtrl
    Routes --> GetItemsCtrl
    Routes --> DeleteCtrl
    Routes --> RenameCtrl
    Routes --> CreateFolderCtrl
    Routes --> CopyItemCtrl
    Routes --> MoveItemCtrl
    Routes --> DownloadFileCtrl

    UploadCtrl --> FSModel
    GetItemsCtrl --> FSModel
    DeleteCtrl --> FSModel
    RenameCtrl --> FSModel
    CreateFolderCtrl --> FSModel
    CopyItemCtrl --> FSModel
    MoveItemCtrl --> FSModel
    DownloadFileCtrl --> FSModel

    UploadCtrl -->|writes| Storage
    DownloadFileCtrl -->|reads| Storage

    FSModel -->|CRUD| DB
    DBConfig --> FSModel
    Express --> SwaggerSetup
    SwaggerSetup --> SwaggerOutput

    BaseAPI <-->|custom preview URL| External

    %% Click Events
    click FMComp "https://github.com/saifullah-dev/react-file-manager/blob/main/frontend/src/FileManager/FileManager.jsx"
    click FMCompDir "https://github.com/saifullah-dev/react-file-manager/tree/main/frontend/src/FileManager"
    click FMCompIndex "https://github.com/saifullah-dev/react-file-manager/blob/main/frontend/src/FileManager/index.js"
    click Clipboard "https://github.com/saifullah-dev/react-file-manager/blob/main/frontend/src/contexts/ClipboardContext.jsx"
    click FilesCtx "https://github.com/saifullah-dev/react-file-manager/blob/main/frontend/src/contexts/FilesContext.jsx"
    click NavCtx "https://github.com/saifullah-dev/react-file-manager/blob/main/frontend/src/contexts/FileNavigationContext.jsx"
    click LayoutCtx "https://github.com/saifullah-dev/react-file-manager/blob/main/frontend/src/contexts/LayoutContext.jsx"
    click SelectionCtx "https://github.com/saifullah-dev/react-file-manager/blob/main/frontend/src/contexts/SelectionContext.jsx"
    click TransProv "https://github.com/saifullah-dev/react-file-manager/blob/main/frontend/src/contexts/TranslationProvider.jsx"
    click BaseAPI "https://github.com/saifullah-dev/react-file-manager/blob/main/frontend/src/api/api.js"
    click CreateFolderAPI "https://github.com/saifullah-dev/react-file-manager/blob/main/frontend/src/api/createFolderAPI.js"
    click DeleteAPI "https://github.com/saifullah-dev/react-file-manager/blob/main/frontend/src/api/deleteAPI.js"
    click DownloadAPI "https://github.com/saifullah-dev/react-file-manager/blob/main/frontend/src/api/downloadFileAPI.js"
    click FileTransferAPI "https://github.com/saifullah-dev/react-file-manager/blob/main/frontend/src/api/fileTransferAPI.js"
    click GetAllFilesAPI "https://github.com/saifullah-dev/react-file-manager/blob/main/frontend/src/api/getAllFilesAPI.js"
    click RenameAPI "https://github.com/saifullah-dev/react-file-manager/blob/main/frontend/src/api/renameAPI.js"
    click HooksDir "https://github.com/saifullah-dev/react-file-manager/tree/main/frontend/src/hooks"
    click UtilsDir "https://github.com/saifullah-dev/react-file-manager/tree/main/frontend/src/utils"
    click Express "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/server.js"
    click EnvExample "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/.env.example"
    click Routes "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/app/routes/fileSystem.routes.js"
    click Multer "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/app/middlewares/multer.middleware.js"
    click ErrorHandler "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/app/middlewares/errorHandler.middleware.js"
    click UploadCtrl "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/app/controllers/uploadFile.controller.js"
    click GetItemsCtrl "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/app/controllers/getItems.controller.js"
    click DeleteCtrl "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/app/controllers/deleteItem.controller.js"
    click RenameCtrl "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/app/controllers/renameItem.controller.js"
    click CreateFolderCtrl "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/app/controllers/createFolder.controller.js"
    click CopyItemCtrl "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/app/controllers/copyItem.controller.js"
    click MoveItemCtrl "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/app/controllers/moveItem.controller.js"
    click DownloadFileCtrl "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/app/controllers/downloadFile.controller.js"
    click FSModel "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/app/models/FileSystem.model.js"
    click DBConfig "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/app/config/db.config.js"
    click SwaggerSetup "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/swagger.js"
    click SwaggerOutput "https://github.com/saifullah-dev/react-file-manager/blob/main/backend/swagger-output.json"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef backend fill:#d4edda,stroke:#333,stroke-width:1px
    classDef db fill:#fff3cd,stroke:#333,stroke-width:1px
    classDef storage fill:#e2e3e5,stroke:#333,stroke-width:1px
    classDef external fill:#d1ecf1,stroke:#333,stroke-width:1px
```
