# 14fabyzz/inventorymaster architecture

> Architecture diagram of the GitHub repository 14fabyzz/inventorymaster, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/14fabyzz/inventorymaster
- Repository: https://github.com/14fabyzz/inventorymaster

## Overview

##### Project Type and Purpose
- This is a Node.js/TypeScript REST‑API backend for an online tech store.
- It exposes endpoints for authentication, user management, product management, and profile operations.
- Uses Express (via app.ts), environment‑configurable database connectivity, JWT for auth, and a layered code structure (routes → controllers → services → repositories).

##### File Structure
- Top‑level entry: app.ts initializes Express, loads middleware, mounts routes.
- config/config‑db.ts handles DB connection parameters (driven by .env).
- routes/*.ts define HTTP endpoints grouped by resource (auth, users, products, profile, register).
- controllers/*Controller.ts contain request handlers and validation.
- services/*Services.ts implement business logic.
- repositories/*Repository.ts perform CRUD against the database.
- Helpers/ generateHash and generateToken encapsulate password hashing and JWT creation.
- middleware/VerifyToken.ts secures protected routes.

##### README for Additional Insights
- Requires Node.js v20+, environment variables for DB credentials.
- Build step (tsc -w) + runtime command (node ./dist/app).
- No front‑end delivered here—this service will be consumed by a separate UI or API client.

##### Main Components & Their Interactions
a. API Client (e.g., Web UI or Postman)
↘ sends HTTP requests to →
b. Express Server (app.ts)
– Global middleware (VerifyToken, JSON parser)
– Mounted Routers (routes/auth, users, products, register, profile)
↘ route match →
c. Controller Layer
– Accepts req/res, calls into →
d. Service Layer
– Implements business rules, calls →
e. Repository (Data Access)
– Executes SQL/ORM calls against the Database
f. Database (MySQL/Postgres, as configured in config‑db.ts)
g. Helpers & Shared Utilities
– generateHash (password security)
– generateToken (JWT signing)
h. External Dependencies
– Environment (ENV) for credentials
– npm packages (Express, JWT, bcrypt, ORM)

##### Architectural Patterns & Design Principles
- Layered (Onion) Architecture: keeps controllers thin, services focused, repositories isolated.
- Dependency Injection (manual wiring in app.ts) to decouple modules.
- Middleware pattern for cross‑cutting concerns (authentication).
- Clear separation of concerns: routing vs. control vs. business vs. data.

##### Final Checklist
[ ] Clear component labels matching folder names
[ ] Call out environment (.env) and external libraries (JWT, bcrypt)
[ ] Note any asynchronous flows or error handlers if relevant

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Global entities
    Client["API Client"]:::client
    Server["Express Server\n(app.ts)"]:::server
    Config["Env & DB Config\n(config/config-db.ts)"]:::config

    %% Routing Layer
    subgraph "Routing Layer"
        direction TB
        AuthRoute["Auth Routes\n(routes/auth.ts)"]:::routing
        UsersRoute["Users Routes\n(routes/users.ts)"]:::routing
        ProductsRoute["Products Routes\n(routes/products.ts)"]:::routing
        ProfileRoute["Profile Routes\n(routes/profile.ts)"]:::routing
        RegisterRoute["Register Routes\n(routes/register.ts)"]:::routing
    end

    %% Middleware
    VerifyToken["VerifyToken Middleware\n(middleware/VerifyToken.ts)"]:::helper

    %% Controller Layer
    subgraph "Controller Layer"
        direction TB
        AuthController["Auth Controller\n(controllers/auth-controller.ts)"]:::controller
        UsersController["Users Controller\n(controllers/users-controller.ts)"]:::controller
        ProductController["Product Controller\n(controllers/product-controller.ts)"]:::controller
        ProfileController["Profile Controller\n(controllers/profile-controller.ts)"]:::controller
        RegisterController["Register Controller\n(controllers/register-controller.ts)"]:::controller
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        UserService["User Services\n(services/UserServices.ts)"]:::service
        ProductService["Product Services\n(services/productServices.ts)"]:::service
    end

    %% Repository Layer
    subgraph "Repository Layer"
        direction TB
        UserRepo["User Repository\n(repositories/UserRepository.ts)"]:::repo
        ProductRepo["Product Repository\n(repositories/productRepository.ts)"]:::repo
    end

    %% DTO Definitions
    subgraph "DTO Definitions"
        direction TB
        AuthDto["Auth DTO\n(Dto/AuthDto.ts)"]:::helper
        UserDto["User DTO\n(Dto/UserDto.ts)"]:::helper
        ProductoDto["Producto DTO\n(Dto/productoDto.ts)"]:::helper
    end

    %% Helpers
    subgraph "Helpers & Utilities"
        direction TB
        Hash["generateHash\n(Helpers/generateHash.ts)"]:::helper
        Token["generateToken\n(Helpers/generateToken.ts)"]:::helper
    end

    %% Database
    Database["Database\n(MySQL/Postgres)"]:::db

    %% Connections
    Client -->|HTTP| Server
    Server -->|mounts routers| AuthRoute
    Server --> UsersRoute
    Server --> ProductsRoute
    Server --> ProfileRoute
    Server --> RegisterRoute
    Server -->|uses config| Config

    AuthRoute -->|calls| AuthController
    UsersRoute --> UsersController
    ProductsRoute --> ProductController
    ProfileRoute --> ProfileController
    RegisterRoute --> RegisterController

    AuthRoute -->|middleware| VerifyToken
    UsersRoute --> VerifyToken
    ProductsRoute --> VerifyToken
    ProfileRoute --> VerifyToken

    AuthController -->|calls| UserService
    UsersController --> UserService
    ProductController --> ProductService
    ProfileController --> UserService
    RegisterController --> UserService

    UserService -->|CRUD| UserRepo
    ProductService --> ProductRepo

    UserRepo -->|SQL| Database
    ProductRepo -->|SQL| Database

    AuthController -->|uses| Token
    RegisterController -->|uses| Hash
    UserService -->|uses| Hash
    AuthController --> AuthDto
    UsersController --> UserDto
    ProductController --> ProductoDto

    Config -->|provides connection| UserRepo
    Config --> ProductRepo

    %% Click Events
    click Server "https://github.com/14fabyzz/inventorymaster/blob/main/app.ts"
    click Config "https://github.com/14fabyzz/inventorymaster/blob/main/config/config-db.ts"
    click AuthRoute "https://github.com/14fabyzz/inventorymaster/blob/main/routes/auth.ts"
    click UsersRoute "https://github.com/14fabyzz/inventorymaster/blob/main/routes/users.ts"
    click ProductsRoute "https://github.com/14fabyzz/inventorymaster/blob/main/routes/products.ts"
    click ProfileRoute "https://github.com/14fabyzz/inventorymaster/blob/main/routes/profile.ts"
    click RegisterRoute "https://github.com/14fabyzz/inventorymaster/blob/main/routes/register.ts"
    click AuthController "https://github.com/14fabyzz/inventorymaster/blob/main/controllers/auth-controller.ts"
    click UsersController "https://github.com/14fabyzz/inventorymaster/blob/main/controllers/users-controller.ts"
    click ProductController "https://github.com/14fabyzz/inventorymaster/blob/main/controllers/product-controller.ts"
    click ProfileController "https://github.com/14fabyzz/inventorymaster/blob/main/controllers/profile-controller.ts"
    click RegisterController "https://github.com/14fabyzz/inventorymaster/blob/main/controllers/register-controller.ts"
    click UserService "https://github.com/14fabyzz/inventorymaster/blob/main/services/UserServices.ts"
    click ProductService "https://github.com/14fabyzz/inventorymaster/blob/main/services/productServices.ts"
    click UserRepo "https://github.com/14fabyzz/inventorymaster/blob/main/repositories/UserRepository.ts"
    click ProductRepo "https://github.com/14fabyzz/inventorymaster/blob/main/repositories/productRepository.ts"
    click AuthDto "https://github.com/14fabyzz/inventorymaster/blob/main/Dto/AuthDto.ts"
    click UserDto "https://github.com/14fabyzz/inventorymaster/blob/main/Dto/UserDto.ts"
    click ProductoDto "https://github.com/14fabyzz/inventorymaster/blob/main/Dto/productoDto.ts"
    click Hash "https://github.com/14fabyzz/inventorymaster/blob/main/Helpers/generateHash.ts"
    click Token "https://github.com/14fabyzz/inventorymaster/blob/main/Helpers/generateToken.ts"
    click VerifyToken "https://github.com/14fabyzz/inventorymaster/blob/main/middleware/VerifyToken.ts"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000,color:#000
    classDef server fill:#98FB98,stroke:#000,color:#000
    classDef config fill:#D3D3D3,stroke:#000,color:#000
    classDef routing fill:#E0FFE0,stroke:#000,color:#000
    classDef controller fill:#CCFF99,stroke:#000,color:#000
    classDef service fill:#FFFF99,stroke:#000,color:#000
    classDef repo fill:#FFD580,stroke:#000,color:#000
    classDef db fill:#FF9999,stroke:#000,color:#000
    classDef helper stroke-dasharray: 5 5,fill:#F0F0F0,stroke:#000,color:#000
```
