# abhishekmohan7171/simple-cloud-storage-aws-s3 architecture

> Architecture diagram of the GitHub repository abhishekmohan7171/simple-cloud-storage-aws-s3, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhishekmohan7171/simple-cloud-storage-aws-s3
- Repository: https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3

## Overview

##### Main Components
- Web Server & API Layer: Represented by the main server (server.js) that sets up the Express app (app.js) and exposes various endpoints.
- Controllers: These handle business logic for authentication, file operations, folder operations, analytics, and search. Each controller (e.g., auth.controller.js, file.controller.js) should be included as a separate module.
- Middleware: Highlight middleware functions such as JWT authentication (auth.js) and access tracking (accessTracker.js) which intercept and process HTTP requests.
- Data Models: Include the Mongoose models (User, File, Folder, FileAccess) which manage the data structure and interactions with MongoDB.
- Database: Represent MongoDB as the database where data persistence is handled.
- File Storage: Showcase the local "uploads" directory used for storing files. Also mention the Multer utility (utils/fileUpload.js) that facilitates file uploads.
- External Services: Optionally include external service interactions like email notifications (utils/emailSender.js) if they are integrated.
- Docker Components: Indicate the Docker file and docker-compose setup for containerizing the application.

##### Relationships and Interactions
- The client applications (or API consumers) send HTTP requests to the web server.
- The Express app (server.js/app.js) forwards these requests to the appropriate routers.
- Routers then delegate processing to various controllers which implement the business logic (file upload, authentication, analytics etc.).
- Controllers interact with Mongoose models to perform CRUD operations on the MongoDB database.
- For file operations (upload/download), controllers work with the file upload utility (utilizing Multer) to write or read files from the uploads directory.
- Middleware functions (for authentication, error handling, access logging) intercept requests before they reach controllers, ensuring security and tracking.
- Docker and Docker Compose files are used to build and deploy the entire stack, which may be represented to show container boundaries.

##### Key Architectural Patterns and Design Principles
- RESTful API Architecture: Indicate that the endpoints follow REST principles for file, folder, analytics, and authentication operations.
- Security Best Practices: Include JWT-based authentication, bcrypt password hashing, input validation and API rate limiting as notable features.
- Modular design: Each component (controllers, routes, models, middleware) is designed independently, supporting maintainability and extensibility.
- Containerization: Use Docker to encapsulate the environment and dependencies which can be illustrated as a deployment boundary.

##### Relevant Technologies, Frameworks, and Tools
- Backend: Node.js, Express.js
- Database: MongoDB with Mongoose
- Authentication: JSON Web Tokens (JWT) and bcrypt
- File Storage: Local filesystem combined with Multer for handling file uploads
- Containerization: Docker and Docker Compose
- Additional Utilities: Error response handling and email notification utilities

## Diagram (Mermaid)

```mermaid
graph TD
    Client["Client (API Consumers)"]:::client
    Docker["Docker Container"]:::docker
    Express["Express Server"]:::server
    DBConfig["DB Config (config/db.js)"]:::config
    MongoDB["MongoDB"]:::database

    subgraph "File Storage"
        Uploads["uploads"]:::storage
        FileUpload["fileUpload.js"]:::storage
    end

    subgraph "Data Models"
        User["user.js"]:::models
        File["file.js"]:::models
        Folder["folder.js"]:::models
        FileAccess["fileAccess.js"]:::models
    end

    subgraph "Express Server Layer"
        ServerFile["server.js"]:::serverFile
        AppFile["app.js"]:::serverFile

        subgraph "Routes"
            AuthRoutes["auth.routes.js"]:::routes
            FileRoutes["file.routes.js"]:::routes
            FolderRoutes["folder.routes.js"]:::routes
            AnalyticsRoutes["analytics.routes.js"]:::routes
            SearchRoutes["search.routes.js"]:::routes
        end

        subgraph "Controllers"
            AuthCtrl["auth.controller.js"]:::controllers
            FileCtrl["file.controller.js"]:::controllers
            FolderCtrl["folder.controller.js"]:::controllers
            AnalyticsCtrl["analytics.controller.js"]:::controllers
            SearchCtrl["search.controller.js"]:::controllers
        end

        subgraph "Middleware"
            AuthMW["auth.js"]:::middleware
            AccessMW["accessTracker.js"]:::middleware
        end
    end

    Client -->|"HTTP_Request"| Express
    Docker -->|"Runs"| Express
    Express -->|"Configures_DB"| DBConfig

    AuthRoutes -->|"delegates"| AuthCtrl
    FileRoutes -->|"delegates"| FileCtrl
    FolderRoutes -->|"delegates"| FolderCtrl
    AnalyticsRoutes -->|"delegates"| AnalyticsCtrl
    SearchRoutes -->|"delegates"| SearchCtrl

    AuthMW -->|"preprocess"| AuthCtrl
    AccessMW -->|"logs"| FileCtrl

    AuthCtrl -->|"CRUD"| User
    FileCtrl -->|"CRUD"| File
    FolderCtrl -->|"CRUD"| Folder
    AnalyticsCtrl -->|"CRUD"| FileAccess
    SearchCtrl -->|"CRUD"| User

    User -->|"queries"| MongoDB
    File -->|"queries"| MongoDB
    Folder -->|"queries"| MongoDB
    FileAccess -->|"queries"| MongoDB

    FileCtrl -->|"FileOps"| FileUpload
    FileUpload -->|"manages"| Uploads

    Docker -->|"includes"| Dockerfile["dockerfile"]:::dockerFile
    Docker -->|"includes"| Compose["docker-compose.yml"]:::dockerFile

classDef client fill:#bbf,stroke:#333,stroke-width:2px;
classDef server fill:#f9d3b4,stroke:#333,stroke-width:2px;
classDef serverFile fill:#f9d3b4,stroke:#333,stroke-width:2px;
classDef routes fill:#cfe2f3,stroke:#333,stroke-width:2px;
classDef controllers fill:#d0e8c6,stroke:#333,stroke-width:2px;
classDef middleware fill:#f4cccc,stroke:#333,stroke-width:2px;
classDef models fill:#ead1dc,stroke:#333,stroke-width:2px;
classDef database fill:#fff2cc,stroke:#333,stroke-width:2px;
classDef storage fill:#d9ead3,stroke:#333,stroke-width:2px;
classDef config fill:#d0e0e3,stroke:#333,stroke-width:2px;
classDef docker fill:#ffe599,stroke:#333,stroke-width:2px;
classDef dockerFile fill:#c9daf8,stroke:#333,stroke-width:2px;

click ServerFile "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/server.js"
click AppFile "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/app.js"
click AuthRoutes "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/routes/auth.routes.js"
click FileRoutes "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/routes/file.routes.js"
click FolderRoutes "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/routes/folder.routes.js"
click AnalyticsRoutes "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/routes/analytics.routes.js"
click SearchRoutes "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/routes/search.routes.js"
click AuthCtrl "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/controllers/auth.controller.js"
click FileCtrl "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/controllers/file.controller.js"
click FolderCtrl "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/controllers/folder.controller.js"
click AnalyticsCtrl "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/controllers/analytics.controller.js"
click SearchCtrl "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/controllers/search.controller.js"
click AuthMW "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/middleware/auth.js"
click AccessMW "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/middleware/accessTracker.js"
click User "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/models/user.js"
click File "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/models/file.js"
click Folder "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/models/folder.js"
click FileAccess "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/models/fileAccess.js"
click DBConfig "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/config/db.js"
click Uploads "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/tree/main/uploads/"
click FileUpload "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/utils/fileUpload.js"
click Dockerfile "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/tree/main/dockerfile"
click Compose "https://github.com/abhishekmohan7171/simple-cloud-storage-aws-s3/blob/main/docker-compose.yml"
```
