# harunagangx/mern-ecommerce-website architecture

> Architecture diagram of the GitHub repository harunagangx/mern-ecommerce-website, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/harunagangx/mern-ecommerce-website
- Repository: https://github.com/harunagangx/mern-ecommerce-website

## Overview

##### Main Components Identification
- Clients Frontend: This part of the project (located in the "clients" directory) covers all user-facing pages, such as home, product detail, cart, login, and order management. It uses React, Redux, React Router, and SCSS for styling.
- Admin Frontend: Separated into its (admin) directory, it provides specialized interfaces for managing products, categories, users, and orders. It also employs React, Redux, and custom component layouts.
- Backend Server: Found in the "server" directory, this is the core of the application. It is built with Node.js and Express.js, exposing RESTful API endpoints to manage products, orders, categories, users, and payments. It connects to MongoDB using Mongoose, integrates Stripe for payment processing, and contains middleware for authentication, error handling, and file uploads.
- Database: Although the database is not a dedicated directory in the codebase, MongoDB (accessed via Mongoose) is the persistent layer for data storage across users, orders, products, and categories.
- External Services: Include integration with Stripe for payment processing as noted in the README.

##### Relationship and Interaction Mapping
- The Backend interacts with the MongoDB database for all data persistence operations.
- Additionally, various middlewares (like authentication via JWT and file upload handling with Multer) support the backend service, so these can be noted as internal components of the server block.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly separate the concerns of the admin interface, client interface, and backend API.
- MVC (Model-View-Controller) pattern on the backend is implied by segregating controllers, models, and routes.
- Unidirectional Data Flow: In the frontends, connections between React components and Redux represent a predictable state flow.
- Modular Structure: The distinct folder paths (actions, reducers, pages, components) indicate a modular design; include these details to highlight how components interact within their layer.
- API Gateway: The server functions as a central hub that all frontends interact with.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients Frontend Subgraph
    subgraph "Clients Frontend"
        CFE("Clients Frontend"):::clientsStyle
        c1("Home (React,Redux,SCSS)"):::clientsStyle
        c2("Product Detail"):::clientsStyle
        c3("Cart"):::clientsStyle
        c4("Login"):::clientsStyle
        c5("Registration"):::clientsStyle
        c6("Order Processing"):::clientsStyle
        c7("Payment"):::clientsStyle
        c8("User Profile"):::clientsStyle
        CFE --> c1
        CFE --> c2
        CFE --> c3
        CFE --> c4
        CFE --> c5
        CFE --> c6
        CFE --> c7
        CFE --> c8
    end

    %% Admin Frontend Subgraph
    subgraph "Admin Frontend"
        AFE("Admin Frontend"):::adminStyle
        a1("Dashboard"):::adminStyle
        a2("Category Management"):::adminStyle
        a3("Product Management"):::adminStyle
        a4("User Management"):::adminStyle
        a5("Order Management"):::adminStyle
        AFE --> a1
        AFE --> a2
        AFE --> a3
        AFE --> a4
        AFE --> a5
    end

    %% Backend Server Subgraph
    subgraph "Backend Server"
        BE("Backend Server"):::backendStyle
        b1("Controllers (Express)"):::backendStyle
        b2("Routes (REST_API)"):::backendStyle
        b3("Models (Mongoose)"):::backendStyle
        b4("Middlewares (JWT,Multer)"):::backendStyle
        b5("Utilities"):::backendStyle
        pb("Payment Controller"):::backendStyle
        pr("Payment Route"):::backendStyle
        BE --> b1
        BE --> b2
        BE --> b3
        BE --> b4
        BE --> b5
        b1 --> pb
        b2 --> pr
    end

    %% External Components
    DB("((MongoDB))"):::databaseStyle
    EP("Stripe Payment Gateway"):::externalStyle

    %% Interactions between components
    CFE -->|"API_Calls/REST"| BE
    AFE -->|"API_Calls/REST"| BE
    BE -->|"CRUD_Operations"| DB
    BE -->|"Payment_Processing"| EP

    %% Click Events for Component Mapping
    click CFE "https://github.com/harunagangx/mern-ecommerce-website/tree/main/clients/"
    click AFE "https://github.com/harunagangx/mern-ecommerce-website/tree/main/admin/"
    click BE "https://github.com/harunagangx/mern-ecommerce-website/tree/main/server/"
    click pb "https://github.com/harunagangx/mern-ecommerce-website/blob/main/server/controllers/paymentController.js"
    click pr "https://github.com/harunagangx/mern-ecommerce-website/blob/main/server/routes/paymentRoute.js"

    %% Styles
    classDef clientsStyle fill:#d9e8ff,stroke:#333,stroke-width:2px;
    classDef adminStyle fill:#f9d6d5,stroke:#333,stroke-width:2px;
    classDef backendStyle fill:#e0f7dc,stroke:#333,stroke-width:2px;
    classDef databaseStyle fill:#ffe6b3,stroke:#333,stroke-width:2px;
    classDef externalStyle fill:#fce5cd,stroke:#333,stroke-width:2px;
```
