# maru33luc/nodejs---fkstore- architecture

> Architecture diagram of the GitHub repository maru33luc/nodejs---fkstore-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/maru33luc/nodejs---fkstore-
- Repository: https://github.com/maru33luc/nodejs---fkstore-

## Overview

##### Main Components
- Client/Frontend: Represented by static assets (HTML templates, CSS files, JavaScript files, and images) under the “public” folder. This is where browser interactions occur.
- Server/Backend: The main entry point (app.js) using Express. It houses controllers (in src/controllers), middleware (in src/middlewares), and route definitions (in src/routes) that determine how HTTP requests are processed.
- Views: The EJS templates found under src/views (and its subdirectories for admin, auth, shop, etc.) which are used by the backend to render dynamic HTML pages.
- Data Layer: Instead of a traditional database, FunkoShop uses JSON files stored in the “data” folder (carts.js, db.js, users.js) to persist information.
- External Services/Utilities: While not connected to external APIs per se, the use of libraries such as Bcrypt, Express Validator, and possibly others (like glide.js for frontend interactions) represent key technology dependencies.

##### Relationships and Interactions
- Controller Processing: Within the server block, add components for controllers (like adminController.js, authController.js, mainController.js, shopController.js) that process incoming requests, decide business logic, and choose which view to render.
- Middleware: Indicate usage of middleware (ensuring authentication, admin authorization, and input validation) that intercepts requests before reaching the controllers.
- Data Services: Connect the controllers to service components (cartServices.js, funkoServices.js, userServices.js) that interact with the JSON data files (data/carts.js, data/db.js, data/users.js) to read and update state.

##### Architectural Patterns & Design Principles
- MVC Pattern: The separation of concerns is evident with Controllers managing logic, Views handling presentation with EJS, and a simplistic model/data access through JSON files.
- Layered Structure: Distinct layers (routes, middleware, controllers, services, and data) help in maintaining the clean separation of logic.
- Modular Routing: The project clearly separates routes based on functionality (adminRoutes, authRoutes, mainRoutes, shopRoutes).

##### Technical Stack & Key Technologies
- Backend: Node.js with Express for request handling.
- Template Engine: EJS for dynamic HTML rendering.
- Frontend: Static assets (CSS, JavaScript, images) are managed under the public directory.
- Dependencies: Bcrypt for secure password handling, Express Validator for input checks.
- Data Storage: JSON-based persistence (data files).

##### Putting It All Together
- Start at the Browser level, linking to the endpoint definitions (like /login, /register, /admin, /shop, etc.).
- How controllers then invoke the services to manipulate JSON data.

## Diagram (Mermaid)

```mermaid
graph TD
    Client["Client / Browser"]:::frontend
    Assets["Static Assets (public)"]:::frontend
    Server["Express Server (app.js)"]:::backend
    Routes["Routes (src/routes)"]:::backend
    Middlewares["Middlewares (src/middlewares)"]:::backend
    Controllers["Controllers (src/controllers)"]:::backend
    Services["Services (src/services)"]:::backend
    Views["Views (src/views)"]:::backend
    Data["Data Storage (data/)"]:::data

    Client -->|"HTTP Request"| Server
    Client -->|"Load Assets"| Assets
    Server -->|"Delegates Routing"| Routes
    Routes -->|"Apply Middleware"| Middlewares
    Middlewares -->|"Process Request"| Controllers
    Controllers -->|"Invoke Services"| Services
    Services -->|"Access Data"| Data
    Services -->|"Return Data"| Controllers
    Controllers -->|"Render View"| Views
    Views -->|"Generate HTML"| Server
    Server -->|"Send Response"| Client

    click Assets "https://github.com/maru33luc/nodejs---fkstore-/tree/main/public/"
    click Server "https://github.com/maru33luc/nodejs---fkstore-/blob/main/app.js"
    click Routes "https://github.com/maru33luc/nodejs---fkstore-/tree/main/src/routes"
    click Middlewares "https://github.com/maru33luc/nodejs---fkstore-/tree/main/src/middlewares"
    click Controllers "https://github.com/maru33luc/nodejs---fkstore-/tree/main/src/controllers"
    click Services "https://github.com/maru33luc/nodejs---fkstore-/tree/main/src/services"
    click Views "https://github.com/maru33luc/nodejs---fkstore-/tree/main/src/views"
    click Data "https://github.com/maru33luc/nodejs---fkstore-/tree/main/data/"

    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef data fill:#F4A460,stroke:#000,stroke-width:2px;
```
