# sgvcode/challenge-funkoshop-23568-fullstack architecture

> Architecture diagram of the GitHub repository sgvcode/challenge-funkoshop-23568-fullstack, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sgvcode/challenge-funkoshop-23568-fullstack
- Repository: https://github.com/sgvcode/challenge-funkoshop-23568-fullstack

## Overview

##### Project type and purpose
- This is a full-stack NodeJS e-commerce web application (“Funkoshop”) that uses Express.js on the backend with server-side rendered EJS templates, a MySQL (or compatible SQL) database, and a static front-end asset folder (`public_html`).

##### File structure
- Top-level:
- index.js – Express entry point
- src/ – server-side MVC code (config, models, services, controllers, routes, middlewares, utils, views)
- public_html/ – static front-end assets (CSS, JS, images)
- sgvero_funkoshop.sql – database schema/seed
- MVC Pattern:
- routes → controllers → services → models → database
- views are EJS templates under src/views
- Middlewares handle auth, validation, file uploads, sessions.
- Config holds database connection.
- package.json & vercel.json indicate deployment on Vercel.

##### Insights from README
- It’s an integrator challenge, demonstrating browsing, login/register, cart, shop pages with dynamic routes.

##### Elements
- Clear labels: Browser, Static Server, Express App, Router, Controllers, Services, Models, DB.
- Browser → Static Server
- Browser → Express App → Router → Controller → Service → Model → DB
- Rectangles for code components (Router, Controller, Service, Model)

##### Detail guidance
- Middle lane: Express application subdivided into middleware, routing, controllers, services, models.
- Bottom: Database.
- Blue for request flow
- Green for business logic
- Orange for data layer

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client and Static Assets
    Browser["Client Browser"]:::external
    Static["Static Assets Server\n(public_html/)"]:::static
    Browser -->|"Request CSS, JS, Images"| Static
    Static -->|"Serve Static Files"| Browser

    %% Express Application Entry
    Browser -->|"HTTP Request"| Express
    Express["Express App\n(index.js)"]:::server

    %% Middleware Layer
    subgraph "Middleware Layer"
        AuthMW["Authentication Middleware"]:::middleware
        UploadMW["File Upload Middleware"]:::middleware
        ValidationMW["Validation Middleware"]:::middleware
        SessionMW["Session Handling"]:::middleware
    end
    Express --> AuthMW
    Express --> UploadMW
    Express --> ValidationMW
    Express --> SessionMW
    AuthMW --> RouterLayer
    UploadMW --> RouterLayer
    ValidationMW --> RouterLayer
    SessionMW --> RouterLayer

    %% Routing Layer
    subgraph RouterLayer["Routing Layer"]
        AdminRoute["Admin Routes"]:::router
        AuthRoute["Authentication Routes"]:::router
        MainRoute["Main/Public Routes"]:::router
        ShopRoute["Shop Routes"]:::router
    end
    RouterLayer --> ControllerLayer

    %% Controller Layer
    subgraph ControllerLayer["Controller Layer"]
        AdminController["Admin Controllers"]:::controller
        AuthController["Authentication Controllers"]:::controller
        MainController["Main Controllers"]:::controller
        ShopController["Shop Controllers"]:::controller
    end
    AdminRoute --> AdminController
    AuthRoute --> AuthController
    MainRoute --> MainController
    ShopRoute --> ShopController

    ControllerLayer --> ServiceLayer
    ControllerLayer --> EJS

    %% View Renderer
    EJS["EJS View Renderer\n(src/views/)"]:::view
    EJS -->|"Render HTML"| Browser

    %% Service Layer
    subgraph ServiceLayer["Service Layer"]
        CategoryService["Category Service"]:::service
        ItemService["Item Service"]:::service
        LicenceService["Licence Service"]:::service
    end
    AdminController --> CategoryService
    AuthController --> LicenceService
    MainController --> ItemService
    ShopController --> ItemService

    ServiceLayer --> ModelLayer

    %% Model Layer
    subgraph ModelLayer["Data Access Layer (Models)"]
        CategoryModel["Category Model"]:::model
        ItemModel["Item Model"]:::model
        LicenceModel["Licence Model"]:::model
    end
    CategoryService --> CategoryModel
    ItemService --> ItemModel
    LicenceService --> LicenceModel

    ModelLayer --> Database

    %% Database
    Database["MySQL Database\n(sgvero_funkoshop.sql)"]:::db
    Database -->|"SQL Result"| ModelLayer

    %% Click Events
    click Static "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/tree/main/public_html/"
    click Express "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/index.js"
    click AuthMW "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/middlewares/login.js"
    click UploadMW "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/middlewares/uploadFiles.js"
    click ValidationMW "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/middlewares/validator.js"
    click SessionMW "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/utils/session.js"
    click AdminRoute "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/routes/adminRoutes.js"
    click AuthRoute "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/routes/authRoutes.js"
    click MainRoute "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/routes/mainRoutes.js"
    click ShopRoute "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/routes/shopRoutes.js"
    click AdminController "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/controllers/adminControllers.js"
    click AuthController "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/controllers/authControllers.js"
    click MainController "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/controllers/mainControllers.js"
    click ShopController "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/controllers/shopControllers.js"
    click CategoryService "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/services/categoryService.js"
    click ItemService "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/services/itemServices.js"
    click LicenceService "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/services/licenceService.js"
    click CategoryModel "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/models/categoryModel.js"
    click ItemModel "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/models/itemModel.js"
    click LicenceModel "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/src/models/licenceModel.js"
    click EJS "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/tree/main/src/views/"
    click Database "https://github.com/sgvcode/challenge-funkoshop-23568-fullstack/blob/main/sgvero_funkoshop.sql"

    %% Styles
    classDef external fill:#add8e6,stroke:#333,stroke-width:1px
    classDef static fill:#f0f0f0,stroke:#333,stroke-width:1px
    classDef server fill:#87cefa,stroke:#333,stroke-width:1px
    classDef middleware fill:#ffe4b5,stroke:#333,stroke-width:1px
    classDef router fill:#ffd966,stroke:#333,stroke-width:1px
    classDef controller fill:#b2fab4,stroke:#333,stroke-width:1px
    classDef service fill:#98df8a,stroke:#333,stroke-width:1px
    classDef model fill:#98dfff,stroke:#333,stroke-width:1px
    classDef view fill:#dda0dd,stroke:#333,stroke-width:1px
    classDef db fill:#f4a261,stroke:#333,stroke-width:1px
```
