# 14fabyzz/backend-inventorypro architecture

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

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

## Overview

##### Project Type and Purpose
- This is a RESTful backend API for a technology store (“Tienda de Tecnología”) built with Node.js and TypeScript.
- It provides endpoints for authentication, user management, product management, and user profiles.

##### Key Architectural Components
a. Client Layer
- External clients (web browsers, mobile apps, Postman) interact via HTTP(S).
b. API Gateway / Web Server
- app.ts: Initializes the Express server, loads middleware, and mounts routes.
c. Routes Layer
- routes/*.ts: Defines HTTP endpoints for /auth, /users, /products, /profile, /register.
d. Middleware Layer
- middleware/VerifyToken.ts: Validates JWTs on protected routes.
e. Controller Layer
- controllers/*-controller.ts: Orchestrates request handling, invokes services, returns HTTP responses.
f. Service Layer
- services/*Services.ts: Encapsulates business logic (e.g., hashing passwords, token generation, CRUD operations).
g. Repository Layer
- repositories/*Repository.ts: Direct data-access logic; communicates with the database via the configured ORM/driver.
h. Data Transfer Objects (DTOs)
i. Helpers
- Helpers/generateHash.ts & generateToken.ts: Utility functions for password hashing and JWT creation.
j. Configuration
- config/config-db.ts: Sets up DB connection (credentials from .env).
k. Database
- External relational DB (MySQL/PostgreSQL) accessed via ORM (e.g., Sequelize).

##### Relationships & Data Flows
- Client → API Gateway (Express)
- API Gateway → Route Handler → [VerifyToken] (if protected) → Controller
- Controller → Service → Repository → Database
- Repository → Service → Controller → API Gateway → Client

##### Architectural Patterns & Principles
- Layered (n-tier) architecture separating transport, presentation, business logic, and data access.
- Dependency inversion via passing DTOs between layers.
- Single Responsibility: each folder/module has a clear concern.
- JWT-based stateless authentication.

##### Technologies & Frameworks
- Node.js, Express, TypeScript
- JWT (Helpers/generateToken, middleware/VerifyToken)
- ORM/Database driver configured in config-db.ts
- npm scripts / tsc watch mode for compilation

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Layer
    Client["External Clients"]:::external

    %% Transport Layer
    subgraph "Transport Layer"
        direction TB
        API["app.ts (Express Server)"]:::transport
        AuthRoute["routes/auth.ts"]:::transport
        UsersRoute["routes/users.ts"]:::transport
        ProductsRoute["routes/products.ts"]:::transport
        ProfileRoute["routes/profile.ts"]:::transport
        RegisterRoute["routes/register.ts"]:::transport
        VerifyToken["VerifyToken Middleware"]:::transport
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        AuthController["auth-controller.ts"]:::logic
        UsersController["users-controller.ts"]:::logic
        ProductController["product-controller.ts"]:::logic
        ProfileController["profile-controller.ts"]:::logic
        RegisterController["register-controller.ts"]:::logic
        UserService["UserServices.ts"]:::logic
        ProductService["productServices.ts"]:::logic
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        UserRepo["UserRepository.ts"]:::data
        ProdRepo["productRepository.ts"]:::data
        AuthDto["AuthDto.ts"]:::data
        UserDto["UserDto.ts"]:::data
        ProdDto["productoDto.ts"]:::data
        HashUtil["generateHash.ts"]:::data
        TokenUtil["generateToken.ts"]:::data
        ConfigDB["config-db.ts"]:::data
    end

    %% Database
    Database["Database"]:::db

    %% Config .env
    Env[".env Variables"]:::external

    %% Connections
    Client -->|"HTTP Request"| API

    API --> AuthRoute
    API --> UsersRoute
    API --> ProductsRoute
    API --> ProfileRoute
    API --> RegisterRoute

    AuthRoute -->|"Public Endpoint"| AuthController
    RegisterRoute -->|"Public Endpoint"| RegisterController

    UsersRoute --> VerifyToken
    ProductsRoute --> VerifyToken
    ProfileRoute --> VerifyToken

    VerifyToken -->|"Validates Token"| UsersController
    VerifyToken -->|"Validates Token"| ProductController
    VerifyToken -->|"Validates Token"| ProfileController

    AuthController -->|"Calls Service"| UserService
    RegisterController -->|"Calls Service"| UserService
    UsersController -->|"Calls Service"| UserService
    ProductController -->|"Calls Service"| ProductService
    ProfileController -->|"Calls Service"| UserService

    UserService -->|"Uses DTO"| AuthDto
    UserService -->|"Uses DTO"| UserDto
    ProductService -->|"Uses DTO"| ProdDto

    UserService -->|"Uses Helper"| HashUtil
    UserService -->|"Uses Helper"| TokenUtil

    UserService -->|"Calls Repo"| UserRepo
    ProductService -->|"Calls Repo"| ProdRepo

    UserRepo -->|"DB Query"| Database
    ProdRepo -->|"DB Query"| Database

    ConfigDB --> Database
    Env --> ConfigDB

    %% Click Events
    click API "https://github.com/14fabyzz/backend-inventorypro/blob/main/app.ts"
    click AuthRoute "https://github.com/14fabyzz/backend-inventorypro/blob/main/routes/auth.ts"
    click UsersRoute "https://github.com/14fabyzz/backend-inventorypro/blob/main/routes/users.ts"
    click ProductsRoute "https://github.com/14fabyzz/backend-inventorypro/blob/main/routes/products.ts"
    click ProfileRoute "https://github.com/14fabyzz/backend-inventorypro/blob/main/routes/profile.ts"
    click RegisterRoute "https://github.com/14fabyzz/backend-inventorypro/blob/main/routes/register.ts"
    click VerifyToken "https://github.com/14fabyzz/backend-inventorypro/blob/main/middleware/VerifyToken.ts"
    click AuthController "https://github.com/14fabyzz/backend-inventorypro/blob/main/controllers/auth-controller.ts"
    click UsersController "https://github.com/14fabyzz/backend-inventorypro/blob/main/controllers/users-controller.ts"
    click ProductController "https://github.com/14fabyzz/backend-inventorypro/blob/main/controllers/product-controller.ts"
    click ProfileController "https://github.com/14fabyzz/backend-inventorypro/blob/main/controllers/profile-controller.ts"
    click RegisterController "https://github.com/14fabyzz/backend-inventorypro/blob/main/controllers/register-controller.ts"
    click UserService "https://github.com/14fabyzz/backend-inventorypro/blob/main/services/UserServices.ts"
    click ProductService "https://github.com/14fabyzz/backend-inventorypro/blob/main/services/productServices.ts"
    click UserRepo "https://github.com/14fabyzz/backend-inventorypro/blob/main/repositories/UserRepository.ts"
    click ProdRepo "https://github.com/14fabyzz/backend-inventorypro/blob/main/repositories/productRepository.ts"
    click AuthDto "https://github.com/14fabyzz/backend-inventorypro/blob/main/Dto/AuthDto.ts"
    click UserDto "https://github.com/14fabyzz/backend-inventorypro/blob/main/Dto/UserDto.ts"
    click ProdDto "https://github.com/14fabyzz/backend-inventorypro/blob/main/Dto/productoDto.ts"
    click HashUtil "https://github.com/14fabyzz/backend-inventorypro/blob/main/Helpers/generateHash.ts"
    click TokenUtil "https://github.com/14fabyzz/backend-inventorypro/blob/main/Helpers/generateToken.ts"
    click ConfigDB "https://github.com/14fabyzz/backend-inventorypro/blob/main/config/config-db.ts"

    %% Styles
    classDef external fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef transport fill:#90EE90,stroke:#333,stroke-width:1px
    classDef logic fill:#FFFF99,stroke:#333,stroke-width:1px
    classDef data fill:#FFA500,stroke:#333,stroke-width:1px
    classDef db fill:#FF6347,stroke:#333,stroke-width:1px
```
