How wiliam-l/tiendaonline-backend works
Project type and purpose
• This is a monolithic RESTful backend for an online store (“TiendaOnline Backend”) built with Node.js and Express.
• It exposes API endpoints for authentication, user management, roles, products, categories, states and orders, persisting data in a SQL Server database via stored procedures.
File structure
• app/config: database connection, environment config
• app/routers: defines Express routes (one per resource)
• app/middleware: authentication (JWT), error handling
• app/controller: map HTTP request → business logic
• app/services: core operations, orchestrating models and utilities
• app/model: ORM-like representations of tables (category, product, order, user, etc.)
• app/utils: common helpers (file upload, password hashing, token creation, query/proc wrappers)
• index.js / .env_example / package.json at the root: entry point, env setup, dependencies
README for additional insights
• SQL script to create DB/schema and stored procedures
• Startup flow: on dev start, auto-create roles, states and an administrator operator
• API endpoints grouped by resource (/auth, /user, /api/order, /api/product, etc.)
Main components and their relationships
a. External Clients (Web, Mobile, Admin UI, Postman)
b. Load Balancer or reverse proxy (optional)
c. Node.js / Express API Server
• Configuration module
• Router layer
• Middleware layer (auth, error handling)
• Controller layer
• Service layer
• Data Access layer (models + stored-procedure wrappers)
• Utility modules (JWT, bcrypt, multer, file utils)
d. SQL Server Database (tables + stored procedures)
Data flow:
Client → HTTP(S) → Express Routers
└─> Middleware (JWT validation, error catching)
└─> Controllers (validate request, call service)
└─> Services (business rules, orchestrate utils)
└─> Data Access (invoke stored procedures via mssql)
└─> SQL Server DB
And reverse on the response path.
Architectural patterns and design principles
• Layered (Separation of Concerns): routers → middleware → controllers → services → data access
• Dependency inversion: controllers depend on abstracted services, not raw DB calls
• Single Responsibility: each directory/module has a distinct purpose
• Stateless authentication with JWTs
• File upload handling via multer utility
• Component labels (e.g., “ProductService”, “AuthMiddleware”)
• Call out important interactions:
• JWT token issuance/validation in auth middleware and utils
• File upload path via multer in utils
• Stored procedure calls in data access layer