# hasan-py/mern_stack_project_ecommerce_hayroo architecture

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

- Interactive diagram: https://gitdiagram.com/hasan-py/mern_stack_project_ecommerce_hayroo
- Repository: https://github.com/hasan-py/mern_stack_project_ecommerce_hayroo

## Overview

##### Main Components

A. Frontend (Client-Side):
- React Application Structure
- Public-facing Shop Components
- Admin Dashboard Components
- Authentication Components
- Layout Components
- Context API State Management

B. Backend (Server-Side):
- Node.js/Express Server
- MongoDB Database
- Braintree Payment Integration
- Authentication Middleware
- API Routes
- Model Layer

**┌─────────────────────────────────────────────────────────────┐**
- Client Layer                           │
- ┬───────────────────────────┬────────────────┤
- Shop Module  │    Admin Module           │   Auth Module   │
- Home       │    - Dashboard            │   - Login      │
- Products   │    - Products Management  │   - Signup     │
- Cart       │    - Orders Management    │   - Protected  │
- Checkout   │    - Categories           │     Routes     │
- ┬───────┴──────────────┬────────────┴────────┬───────┘

- ▼                      ▼                     ▼
**┌─────────────────────────────────────────────────────────────┐**
- API Layer                           │
- ┬──────────────┬─────────────┬────────────────┤
- Products   │   Orders     │  Categories │    Users        │
- API       │    API       │    API      │     API        │
- ┬──────┴──────┬──────┴──────┬──────┴────────┬───────┘

- ▼             ▼             ▼               ▼
**┌─────────────────────────────────────────────────────────────┐**
- Server Layer                             │
- ┬──────────────┬─────────────┬────────────────┤
- Controllers│  Middleware  │   Models    │  Config         │
- ┬──────┴──────┬──────┴──────┬──────┴────────┬───────┘

- ▼             ▼             ▼               ▼
**┌─────────────────────────────────────────────────────────────┐**
- External Services                         │
- ┬───────────────────┬─────────────────┤
- MongoDB Database   │  Braintree Payment│  File Storage   │
- ┴───────────────────┴─────────────────┘

##### Important Details to Highlight

a. Frontend Architecture:
- Context API implementations (CategoryContext, ProductContext, etc.)
- Protected route mechanisms
- Component hierarchy
- State management flow

b. Backend Architecture:
- RESTful API endpoints
- Authentication middleware
- Database models
- External service integrations

##### Specific Implementation Notes

- Separation between admin and shop interfaces
- Authentication flow
- Demonstrate the order processing pipeline
- Product management workflow
- Integration with Braintree payment system

##### Deployment Architecture

A separate section showing:
- Frontend deployment (React build)
- Backend deployment (Render)
- MongoDB Atlas connection
- Environment variable management
- Static asset handling

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef server fill:#e67e22,stroke:#d35400,color:white
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    
    %% Client Layer
    subgraph ClientLayer
        Shop["Shop Module"]:::frontend
        Admin["Admin Module"]:::frontend
        Auth["Auth Module"]:::frontend
        
        %% Shop Components
        ShopHome["Home"]:::frontend
        ShopProducts["Products"]:::frontend
        ShopCart["Cart"]:::frontend
        ShopCheckout["Checkout"]:::frontend
        
        %% Admin Components
        AdminDash["Dashboard"]:::frontend
        AdminProducts["Products Management"]:::frontend
        AdminOrders["Orders Management"]:::frontend
        AdminCategories["Categories"]:::frontend
        
        %% Auth Components
        AuthLogin["Login"]:::frontend
        AuthSignup["Signup"]:::frontend
        AuthProtected["Protected Routes"]:::frontend
        
        %% Context Components
        ProductContext["Product Context"]:::frontend
        CategoryContext["Category Context"]:::frontend
        OrderContext["Order Context"]:::frontend
        HomeContext["Home Context"]:::frontend
    end
    
    %% API Layer
    subgraph APILayer
        ProductsAPI["Products API"]:::api
        OrdersAPI["Orders API"]:::api
        CategoriesAPI["Categories API"]:::api
        UsersAPI["Users API"]:::api
        AuthAPI["Auth API"]:::api
        PaymentAPI["Payment API"]:::api
    end
    
    %% Server Layer
    subgraph ServerLayer
        Controllers["Controllers"]:::server
        Middleware["Middleware"]:::server
        Models["Models"]:::server
        Config["Config"]:::server
    end
    
    %% External Services
    subgraph ExternalServices
        MongoDB[(MongoDB Database)]:::external
        Braintree["Braintree Payment"]:::external
        Storage["File Storage"]:::external
    end
    
    %% Relationships
    Shop --> ShopHome & ShopProducts & ShopCart & ShopCheckout
    Admin --> AdminDash & AdminProducts & AdminOrders & AdminCategories
    Auth --> AuthLogin & AuthSignup & AuthProtected
    
    ShopHome & ShopProducts & ShopCart & ShopCheckout --> ProductsAPI
    AdminProducts & AdminCategories --> CategoriesAPI
    AdminOrders --> OrdersAPI
    AuthLogin & AuthSignup --> AuthAPI
    ShopCheckout --> PaymentAPI
    
    ProductsAPI & OrdersAPI & CategoriesAPI & UsersAPI & AuthAPI & PaymentAPI --> Controllers
    Controllers --> Middleware
    Middleware --> Models
    Models --> MongoDB
    PaymentAPI --> Braintree
    
    %% Click Events
    click Shop "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/tree/master/client/src/components/shop"
    click Admin "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/tree/master/client/src/components/admin"
    click Auth "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/tree/master/client/src/components/shop/auth"
    click AdminProducts "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/tree/master/client/src/components/admin/products"
    click AdminOrders "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/tree/master/client/src/components/admin/orders"
    click AdminCategories "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/tree/master/client/src/components/admin/categories"
    click ProductContext "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/blob/master/client/src/components/admin/products/ProductContext.js"
    click CategoryContext "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/blob/master/client/src/components/admin/categories/CategoryContext.js"
    click OrderContext "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/blob/master/client/src/components/admin/orders/OrderContext.js"
    click HomeContext "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/blob/master/client/src/components/shop/home/HomeContext.js"
    click AuthAPI "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/blob/master/server/routes/auth.js"
    click ProductsAPI "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/blob/master/server/routes/products.js"
    click CategoriesAPI "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/blob/master/server/routes/categories.js"
    click OrdersAPI "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/blob/master/server/routes/orders.js"
    click UsersAPI "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/blob/master/server/routes/users.js"
    click PaymentAPI "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/blob/master/server/routes/braintree.js"
    click Config "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/blob/master/server/config/db.js"
    click Models "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/tree/master/server/models"
    click Controllers "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/tree/master/server/controller"
    click Middleware "https://github.com/hasan-py/MERN_Stack_Project_Ecommerce_Hayroo/tree/master/server/middleware"
```
