# ishaangautam9595/advertisement-backend architecture

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

- Interactive diagram: https://gitdiagram.com/ishaangautam9595/advertisement-backend
- Repository: https://github.com/ishaangautam9595/advertisement-backend

## Overview

##### Main Components

A. API Layer
- Routes into a "Routes Layer" showing endpoints for:
- Authentication (/auth)
- Users (/user)
- Products (/product)
- Categories (/category)
- SubCategories (/subcategory)
- Locations (/location)
- Roles (/role)

B. Middleware Layer
- Two key middleware components:
- Authentication middleware (auth.js)
- Validation middleware (validator.js)

C. Controller Layer
- Controllers that handle business logic:
- AuthController
- UserController
- ProductController
- CategoryController
- SubCategoryController
- LocationController
- RoleController

D. Model Layer
- Database models:
- User
- Product
- ProductDetails
- Category
- SubCategory
- Location
- Order
- OrderItems
- PasswordReset
- UserAddress
- Role

E. Helper Services
- NodeMailer service for email functionality

- Client Requests (Top)
- ↓
- Routes Layer
- ↓
- Middleware Layer
- ↓
- Controllers Layer
- ↓
- Models Layer (Database Interaction)

##### Component Relationships

- Client → Routes
- Routes → Middleware
- Middleware → Controllers
- Controllers → Models
- Controllers ↔ Helper Services

##### Additional Elements

- A File Storage component for the 'uploads' directory
- Email service integration via NodeMailer
- Authentication flow with special emphasis on the auth middleware
- Database relationships between models (especially for orders-products, categories-subcategories)

##### Technical Details

- Node.js/Express.js as the main framework
- Database system (likely MongoDB based on the model structure)
- File upload system for the uploads directory
- Email service integration through NodeMailer

##### Notes

- A note about the seeding process (referencing the seeders directory)
- Configuration requirements
- Error handling flow
- Validation points in the system

## Diagram (Mermaid)

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

    subgraph Routes
        AR["/auth"]:::route
        UR["/user"]:::route
        PR["/product"]:::route
        CR["/category"]:::route
        SR["/subcategory"]:::route
        LR["/location"]:::route
        RR["/role"]:::route
    end

    subgraph Middleware
        AM[Auth Middleware]:::middleware
        VM[Validation Middleware]:::middleware
    end

    subgraph Controllers
        AC[Auth Controller]:::controller
        UC[User Controller]:::controller
        PC[Product Controller]:::controller
        CC[Category Controller]:::controller
        SC[SubCategory Controller]:::controller
        LC[Location Controller]:::controller
        RC[Role Controller]:::controller
    end

    subgraph Models
        UM[User]:::model
        PM[Product]:::model
        PDM[ProductDetails]:::model
        CM[Category]:::model
        SCM[SubCategory]:::model
        LM[Location]:::model
        OM[Order]:::model
        OIM[OrderItems]:::model
        PRM[PasswordReset]:::model
        UAM[UserAddress]:::model
        RM[Role]:::model
    end

    subgraph Services
        ES[Email Service]:::service
        FS[File Storage]:::service
    end

    %% Relationships
    CL --> AR & UR & PR & CR & SR & LR & RR
    AR & UR & PR & CR & SR & LR & RR --> AM & VM
    AM & VM --> AC & UC & PC & CC & SC & LC & RC
    AC --> UM & PRM & ES
    UC --> UM & UAM
    PC --> PM & PDM & FS
    CC --> CM
    SC --> SCM
    LC --> LM
    RC --> RM
    OM --> OIM
    OIM --> PM
    CM --> SCM
    SCM --> PM

    %% Click Events
    click AR "https://github.com/ishaangautam9595/advertisement-backend/blob/master/routes/auth.js"
    click UR "https://github.com/ishaangautam9595/advertisement-backend/blob/master/routes/user.js"
    click PR "https://github.com/ishaangautam9595/advertisement-backend/blob/master/routes/product.js"
    click CR "https://github.com/ishaangautam9595/advertisement-backend/blob/master/routes/category.js"
    click SR "https://github.com/ishaangautam9595/advertisement-backend/blob/master/routes/subCategory.js"
    click LR "https://github.com/ishaangautam9595/advertisement-backend/blob/master/routes/location.js"
    click RR "https://github.com/ishaangautam9595/advertisement-backend/blob/master/routes/role.js"
    click AM "https://github.com/ishaangautam9595/advertisement-backend/blob/master/middelware/auth.js"
    click VM "https://github.com/ishaangautam9595/advertisement-backend/blob/master/middelware/validator.js"
    click AC "https://github.com/ishaangautam9595/advertisement-backend/blob/master/controllers/auth.js"
    click UC "https://github.com/ishaangautam9595/advertisement-backend/blob/master/controllers/user.js"
    click PC "https://github.com/ishaangautam9595/advertisement-backend/blob/master/controllers/product.js"
    click CC "https://github.com/ishaangautam9595/advertisement-backend/blob/master/controllers/category.js"
    click SC "https://github.com/ishaangautam9595/advertisement-backend/blob/master/controllers/subCategory.js"
    click LC "https://github.com/ishaangautam9595/advertisement-backend/blob/master/controllers/location.js"
    click RC "https://github.com/ishaangautam9595/advertisement-backend/blob/master/controllers/role.js"
    click UM "https://github.com/ishaangautam9595/advertisement-backend/blob/master/models/user.js"
    click PM "https://github.com/ishaangautam9595/advertisement-backend/blob/master/models/product.js"
    click PDM "https://github.com/ishaangautam9595/advertisement-backend/blob/master/models/productdetails.js"
    click CM "https://github.com/ishaangautam9595/advertisement-backend/blob/master/models/category.js"
    click SCM "https://github.com/ishaangautam9595/advertisement-backend/blob/master/models/subCategory.js"
    click LM "https://github.com/ishaangautam9595/advertisement-backend/blob/master/models/locations.js"
    click OM "https://github.com/ishaangautam9595/advertisement-backend/blob/master/models/orders.js"
    click OIM "https://github.com/ishaangautam9595/advertisement-backend/blob/master/models/ordersitems.js"
    click PRM "https://github.com/ishaangautam9595/advertisement-backend/blob/master/models/passwordreset.js"
    click UAM "https://github.com/ishaangautam9595/advertisement-backend/blob/master/models/useraddress.js"
    click RM "https://github.com/ishaangautam9595/advertisement-backend/blob/master/models/role.js"
    click ES "https://github.com/ishaangautam9595/advertisement-backend/blob/master/helper/nodemailer.js"
    click FS "https://github.com/ishaangautam9595/advertisement-backend/tree/master/uploads"

    %% Styling
    classDef route fill:#90EE90
    classDef middleware fill:#FFE5B4
    classDef controller fill:#87CEEB
    classDef model fill:#FFA07A
    classDef service fill:#DDA0DD

    %% Legend
    subgraph Legend
        R[Routes]:::route
        M[Middleware]:::middleware
        C[Controllers]:::controller
        DB[Models]:::model
        S[Services]:::service
    end
```
