# meereak/e-commerce architecture

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

- Interactive diagram: https://gitdiagram.com/meereak/e-commerce
- Repository: https://github.com/meereak/e-commerce

## Overview

##### Main Components

A. Client-Side Applications:
- Frontend (Next.js Customer Portal)
- Dashboard (Next.js Admin Portal)

B. Backend Services:
- Express.js API Server
- Authentication Service
- File Storage Service (AWS S3)

C. Database:
- MongoDB Database

**┌─ Client Layer ─────────────────────────────┐**
- ┌─ Frontend ─────┐    ┌─ Dashboard ─────┐ │
- Next.js        │    │ Next.js         │ │
- Pages        │    │ - Product Mgmt  │ │
- Components   │    │ - User Mgmt     │ │
- Auth Flow    │    │ - Blog Mgmt     │ │
- ┘    └────────────────-┘ │
- ┬──────────────┬──────────┘

**┌──────────────────▼──────────────▼──────────┐**
- API Gateway / Load Balancer                 │
- ┬──────────────────────────┘

**┌──────────────────▼──────────────────────────┐**
- Backend Services Layer                       │
- ┌─────────────────────────────────────────┐ │
- Express.js API Server                   │ │
- Controllers                         │ │
- User                             │ │
- Product                          │ │
- Blog                             │ │
- Order                            │ │
- Services                           │ │
- Repositories                       │ │
- Middleware                         │ │
- ┘ │
- ┬──────────────────────────┘

**┌──────────────────▼──────────────────────────┐**
- External Services Layer                      │
- ┌─ AWS S3 ─────┐   ┌─ Authentication ────┐  │
- Image Storage│   │ JWT/OAuth           │  │
- ┘   └──────────────────── ┘  │
- ┬──────────────────────────┘

**┌──────────────────▼──────────────────────────┐**
- Data Layer                                   │
- ┌─ MongoDB ────────────────────────────┐    │
- Collections:                         │    │
- Users                            │    │
- Products                         │    │
- Categories                       │    │
- Orders                           │    │
- Blogs                           │    │
- Comments                        │    │
- ┘    │
- ┘

##### Key Relationships to Highlight

- Frontend/Dashboard → Backend API communication
- Backend → MongoDB data flow
- Image upload flow through S3
- Authentication flow
- Service layer interactions

##### Important Implementation Details

- MVC pattern in the backend
- Repository pattern used
- Validation layers
- Error handling flow
- Security middleware positions

##### Additional Notes

- Notes about scalability points
- Authentication boundaries
- Stateless vs stateful components
- Caching layers if implemented

##### Specific Features to Emphasize

- Shopping cart flow
- Order processing pipeline
- Blog system architecture
- Product management flow
- User authentication flow
- Image handling system

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef database fill:#9b59b6,stroke:#8e44ad,color:white
    classDef api fill:#e74c3c,stroke:#c0392b,color:white

    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        Frontend["Frontend Customer Portal"]:::frontend
        Dashboard["Admin Dashboard"]:::frontend
        
        subgraph FrontendComponents["Frontend Components"]
            direction TB
            CustomerUI["Customer UI"]:::frontend
            CustomerRoutes["Customer Routes"]:::frontend
            AuthPages["Authentication Pages"]:::frontend
            ShoppingCart["Shopping Cart"]:::frontend
        end

        subgraph DashboardComponents["Dashboard Components"]
            direction TB
            AdminUI["Admin UI"]:::frontend
            ProductMgmt["Product Management"]:::frontend
            UserMgmt["User Management"]:::frontend
            BlogMgmt["Blog Management"]:::frontend
        end
    end

    %% API Gateway
    Gateway["API Gateway / Load Balancer"]:::api

    %% Backend Layer
    subgraph BackendLayer["Backend Services Layer"]
        direction TB
        APIServer["Express.js API Server"]:::backend
        
        subgraph ServerComponents["Server Components"]
            direction TB
            Controllers["Controllers"]:::backend
            Services["Services"]:::backend
            Repositories["Repositories"]:::backend
            Middleware["Middleware"]:::backend
            ErrorHandling["Error Handling"]:::backend
            Validation["Validation Layer"]:::backend
            Routes["API Routes"]:::backend
        end

        subgraph Models["Data Models"]
            direction TB
            UserModel["User Model"]:::backend
            ProductModel["Product Model"]:::backend
            BlogModel["Blog Model"]:::backend
            OrderModel["Order Model"]:::backend
        end
    end

    %% External Services Layer
    subgraph ExternalLayer["External Services Layer"]
        S3["AWS S3 Storage"]:::external
        Auth["Authentication Service"]:::external
        FileUpload["File Upload Handler"]:::external
    end

    %% Data Layer
    subgraph DataLayer["Data Layer"]
        MongoDB[(MongoDB Database)]:::database
        
        subgraph Collections["Collections"]
            Users[("Users")]:::database
            Products[("Products")]:::database
            Categories[("Categories")]:::database
            Orders[("Orders")]:::database
            Blogs[("Blogs")]:::database
            Comments[("Comments")]:::database
        end
    end

    %% Relationships
    Frontend --> Gateway
    Dashboard --> Gateway
    Gateway --> APIServer
    APIServer --> MongoDB
    APIServer --> S3
    APIServer --> Auth
    S3 --> FileUpload

    %% Click Events
    click Frontend "https://github.com/MeeReak/E-commerce/tree/main/frontend"
    click CustomerUI "https://github.com/MeeReak/E-commerce/tree/main/frontend/src/components"
    click CustomerRoutes "https://github.com/MeeReak/E-commerce/tree/main/frontend/src/app"
    click AuthPages "https://github.com/MeeReak/E-commerce/tree/main/frontend/src/app/(auth)"
    click ShoppingCart "https://github.com/MeeReak/E-commerce/tree/main/frontend/src/app/(account)/shopping-cart"
    click Dashboard "https://github.com/MeeReak/E-commerce/tree/main/dashboard"
    click AdminUI "https://github.com/MeeReak/E-commerce/tree/main/dashboard/src/components"
    click ProductMgmt "https://github.com/MeeReak/E-commerce/tree/main/dashboard/src/app/product"
    click UserMgmt "https://github.com/MeeReak/E-commerce/tree/main/dashboard/src/app/user"
    click BlogMgmt "https://github.com/MeeReak/E-commerce/tree/main/dashboard/src/app/blog"
    click APIServer "https://github.com/MeeReak/E-commerce/tree/main/backend"
    click Controllers "https://github.com/MeeReak/E-commerce/tree/main/backend/src/controller"
    click Services "https://github.com/MeeReak/E-commerce/tree/main/backend/src/service"
    click Repositories "https://github.com/MeeReak/E-commerce/tree/main/backend/src/repository"
    click Middleware "https://github.com/MeeReak/E-commerce/tree/main/backend/src/middleware"
    click ErrorHandling "https://github.com/MeeReak/E-commerce/tree/main/backend/src/Error"
    click UserModel "https://github.com/MeeReak/E-commerce/blob/main/backend/src/model/user.model.ts"
    click ProductModel "https://github.com/MeeReak/E-commerce/blob/main/backend/src/model/product.model.ts"
    click BlogModel "https://github.com/MeeReak/E-commerce/blob/main/backend/src/model/blog.model.ts"
    click OrderModel "https://github.com/MeeReak/E-commerce/blob/main/backend/src/model/types/order.type.ts"
    click S3 "https://github.com/MeeReak/E-commerce/blob/main/backend/src/util/s3.ts"
    click FileUpload "https://github.com/MeeReak/E-commerce/blob/main/backend/src/util/upload.ts"
    click Validation "https://github.com/MeeReak/E-commerce/blob/main/backend/src/constant/common.validator.ts"
    click Routes "https://github.com/MeeReak/E-commerce/blob/main/backend/src/routes/routes.ts"
```
