# pv2k3/ecomweb architecture

> Architecture diagram of the GitHub repository pv2k3/ecomweb, 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/pv2k3/ecomweb
- Repository: https://github.com/pv2k3/ecomweb

## Overview

##### Main Components

A. Frontend Layer:
- Client-Side Views (EJS Templates)
- Static Assets (CSS, Images)
- Client-Side Scripts

B. Backend Layer:
- Express Server
- Authentication Middleware
- Controllers
- Services
- Routes

C. Database Layer:
- MongoDB Database
- Mongoose Models

##### Component Relationships and Structure

**[Client Layer] → [Application Layer] → [Data Layer]**

Detail each layer as follows:

A. Client Layer (Top):
- Main Views (home, store, admin, account)
- Partials (navbar, footer, etc.)
- CSS Files
- Images

B. Application Layer (Middle):
- Surrounding components:
1. Routes Module:
- Admin Routes
- Buy Routes
- Image Routes
- Static Routes
2. Controllers Module:
- Main Controllers
- Helper Functions
3. Middleware:
- Authentication
- Authorization
4. Services:
- Auth Service

C. Data Layer (Bottom):
- MongoDB Database containing models:
- USER Model
- STOCK Model
- IMAGES Model

##### Flow Indicators

- HTTP Request flow from Client → Server
- Authentication flow through Middleware
- Data flow between Controllers and Database
- Response flow back to Client

##### Technical Stack Indicators

- Node.js/Express
- MongoDB/Mongoose
- EJS Template Engine
- JWT Authentication
- Cookie Parser
- Multer (for image handling)

##### Additional Notes

- Clear separation between admin and user functionalities
- Where password encryption happens
- Routes that require authentication
- Image upload/storage flow

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Views["Views (EJS)"]
        click Views "https://github.com/pv2k3/ecomweb/blob/main/views/*.ejs"
        StaticAssets["Static Assets"]
        
        subgraph ViewComponents
            Nav["Navigation"]
            click Nav "https://github.com/pv2k3/ecomweb/blob/main/views/partials/navbar.ejs"
            Footer["Footer"]
            click Footer "https://github.com/pv2k3/ecomweb/blob/main/views/partials/footer.ejs"
            Store["Store Components"]
            click Store "https://github.com/pv2k3/ecomweb/blob/main/views/partials/storeSwitchItemType.ejs"
            UI["User Interface"]
            click UI "https://github.com/pv2k3/ecomweb/blob/main/views/partials/popupUserRecord.ejs"
            Track["Tracking"]
            click Track "https://github.com/pv2k3/ecomweb/blob/main/views/partials/tracker.ejs"
        end
        
        subgraph Assets
            CSS["CSS Files"]
            click CSS "https://github.com/pv2k3/ecomweb/tree/main/css/"
            Images["Images"]
            click Images "https://github.com/pv2k3/ecomweb/tree/main/img/"
        end
        
        Views --> ViewComponents
        StaticAssets --> Assets
    end

    subgraph Application
        Server["Express Server"]
        click Server "https://github.com/pv2k3/ecomweb/blob/main/index.js"
        
        subgraph Routes
            AdminR["Admin Routes"]
            click AdminR "https://github.com/pv2k3/ecomweb/blob/main/routes/adminRoutes.js"
            BuyR["Buy Routes"]
            click BuyR "https://github.com/pv2k3/ecomweb/blob/main/routes/buyroutes.js"
            ImageR["Image Routes"]
            click ImageR "https://github.com/pv2k3/ecomweb/blob/main/routes/imageRoutes.js"
            StaticR["Static Routes"]
            click StaticR "https://github.com/pv2k3/ecomweb/blob/main/routes/staticRoutes.js"
            MainR["Main Routes"]
            click MainR "https://github.com/pv2k3/ecomweb/blob/main/routes/routes.js"
        end
        
        subgraph Controllers
            MainC["Main Controller"]
            click MainC "https://github.com/pv2k3/ecomweb/blob/main/controller/controllers.js"
            HelperC["Helper Functions"]
            click HelperC "https://github.com/pv2k3/ecomweb/blob/main/controller/helper.js"
        end
        
        subgraph Security
            AuthMid["Auth Middleware"]
            click AuthMid "https://github.com/pv2k3/ecomweb/blob/main/middleware/auth.js"
            AuthServ["Auth Service"]
            click AuthServ "https://github.com/pv2k3/ecomweb/blob/main/services/auth.js"
        end
        
        Server --> Routes
        Routes --> Controllers
        Controllers --> Security
    end

    subgraph Database
        DBConn["Database Connection"]
        click DBConn "https://github.com/pv2k3/ecomweb/blob/main/connection.js"
        
        subgraph Models
            UserM["User Model"]
            click UserM "https://github.com/pv2k3/ecomweb/blob/main/models/USER.js"
            StockM["Stock Model"]
            click StockM "https://github.com/pv2k3/ecomweb/blob/main/models/STOCK.js"
            ImagesM["Images Model"]
            click ImagesM "https://github.com/pv2k3/ecomweb/blob/main/models/IMAGES.js"
        end
        
        DBConn --> Models
    end

    Client --> Application
    Application --> Database

    classDef client fill:#3498db,stroke:#2980b9,color:white
    classDef server fill:#2ecc71,stroke:#27ae60,color:white
    classDef security fill:#f1c40f,stroke:#f39c12,color:black
    classDef database fill:#9b59b6,stroke:#8e44ad,color:white
    classDef middleware fill:#95a5a6,stroke:#7f8c8d,color:white

    class Views,StaticAssets,ViewComponents,Assets client
    class Server,Routes,Controllers server
    class Security security
    class DBConn,Models database
    class AuthMid middleware
```
