# amrmuhamedd/e-commerce-nestjs architecture

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

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

## Overview

##### Main Components

A. Core Application Layer
- NestJS Application Container
- Authentication Module
- Products Module
- API Gateway (Swagger Integration)

B. External Systems
- MongoDB Database
- JWT Authentication Service

##### Detailed Component Breakdown

A. Authentication Module (auth/)
- Following components:
- AuthController
- AuthService
- JWT Strategy
- Local Strategy
- Guards (JWT & Local)
- Role-based Access Control
- User Model

B. Products Module (products/)
- Components:
- ProductsController
- ProductsService
- Product Model
- Cart Model
- DTOs
- Interfaces

**[Client Applications]**
- ↕
**[API Gateway (Swagger)] → [Authentication Middleware]**
- ↕
**[NestJS Application]**
- [Auth Module]─────┐
- →[JWT Service] │
- ↕
- [Products Module] │

- [Guards/RBAC]────┘
- ↕
**[MongoDB Database]**

##### Key Relationships to Highlight

a. Authentication Flow:
- Client → API Gateway → Auth Module → JWT Service
- Role-based access control for different endpoints
- JWT token validation flow

b. Product Management Flow:
- Admin routes for product CRUD operations
- User routes for viewing products and cart management
- Data persistence flow to MongoDB

##### Important Details

a. Security Layer:
- JWT implementation
- Role-based access (User vs Admin)
- Guard implementation points

b. Data Flow:
- Request/Response cycle
- Database interactions
- DTOs and data transformation points

##### Technical Stack Indicators

- NestJS framework version
- MongoDB connection
- Swagger API documentation
- JWT authentication
- Mongoose ORM

Remember to emphasize:
##### The role-based access control system's integration points

This will provide a clear understanding of the system's architecture while maintaining the necessary technical detail for implementation and maintenance.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        CL[Client Applications]
    end

    subgraph Gateway
        AG["API Gateway/Swagger"]
        AM[Authentication Middleware]
    end

    subgraph NestJS["NestJS Application Container"]
        APP["App Module"]
        
        subgraph Auth["Authentication Module"]
            AC["Auth Controller"]
            AS["Auth Service"]
            JSTS["JWT Strategy"]
            LST["Local Strategy"]
            GRD["Guards"]
            RBAC["Role-based Access Control"]
            UM["User Model"]
            ADTO["Auth DTOs"]
        end

        subgraph Products["Products Module"]
            PC["Products Controller"]
            PS["Products Service"]
            PM["Product Model"]
            CM["Cart Model"]
            PDTO["Product DTOs"]
            PI["Product Interfaces"]
        end
    end

    subgraph External["External Services"]
        JWT["JWT Service"]
        DB[(MongoDB Database)]
    end

    %% Relationships
    CL --> AG
    AG --> AM
    AM --> APP
    
    AC --> AS
    AS --> JWT
    AS --> DB
    
    PC --> PS
    PS --> DB
    
    %% Click events
    click APP "https://github.com/amrmuhamedd/e-commerce-nestjs/blob/main/src/app.module.ts"
    click AG "https://github.com/amrmuhamedd/e-commerce-nestjs/blob/main/src/swagger.ts"
    click AC "https://github.com/amrmuhamedd/e-commerce-nestjs/blob/main/src/auth/auth.controller.ts"
    click AS "https://github.com/amrmuhamedd/e-commerce-nestjs/blob/main/src/auth/auth.service.ts"
    click JSTS "https://github.com/amrmuhamedd/e-commerce-nestjs/blob/main/src/auth/strategy/jwt.stratgy.ts"
    click LST "https://github.com/amrmuhamedd/e-commerce-nestjs/blob/main/src/auth/strategy/local.sratgy.ts"
    click GRD "https://github.com/amrmuhamedd/e-commerce-nestjs/tree/main/src/auth/guards/"
    click RBAC "https://github.com/amrmuhamedd/e-commerce-nestjs/tree/main/src/auth/roles/"
    click UM "https://github.com/amrmuhamedd/e-commerce-nestjs/blob/main/src/auth/model/users.ts"
    click ADTO "https://github.com/amrmuhamedd/e-commerce-nestjs/tree/main/src/auth/dto/"
    click PC "https://github.com/amrmuhamedd/e-commerce-nestjs/blob/main/src/products/products.controller.ts"
    click PS "https://github.com/amrmuhamedd/e-commerce-nestjs/blob/main/src/products/products.service.ts"
    click PM "https://github.com/amrmuhamedd/e-commerce-nestjs/blob/main/src/products/models/products.ts"
    click CM "https://github.com/amrmuhamedd/e-commerce-nestjs/blob/main/src/products/models/cart.ts"
    click PDTO "https://github.com/amrmuhamedd/e-commerce-nestjs/tree/main/src/products/products.Dto/"
    click PI "https://github.com/amrmuhamedd/e-commerce-nestjs/blob/main/src/products/products.interface/products.interface.ts"

    %% Styling
    classDef client fill:#f9f,stroke:#333
    classDef gateway fill:#purple,stroke:#333
    classDef nestjs fill:#blue,stroke:#333
    classDef auth fill:#orange,stroke:#333
    classDef products fill:#blue,stroke:#333
    classDef external fill:#green,stroke:#333

    class CL client
    class AG,AM gateway
    class APP nestjs
    class AC,AS,JSTS,LST,GRD,RBAC,UM,ADTO auth
    class PC,PS,PM,CM,PDTO,PI products
    class JWT,DB external
```
