How 14fabyzz/backend-inventorypro works
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