E-commerce API
E-commerce REST API built as a learning and portfolio project, focused on backend organization, data validation, and relational persistence.
✦ The problem
An e-commerce workflow needs to keep users, catalog, orders, and stock consistent. This API brings these operations together through organized endpoints and applies core rules on the server instead of trusting values sent by the client.
✦ What it is
A REST API built with NestJS and Fastify, using PostgreSQL for persistence and Prisma for data access. Modules are separated by domain, and services depend on repository contracts to keep business logic separate from persistence implementation.
✦ Features
- ▸CRUD for users, categories, and products
- ▸Filter products by category and partial name
- ▸Create and retrieve orders, with optional user filtering
- ▸Server-side total calculation and unit-price snapshot at purchase time
- ▸Stock deduction when creating an order and restoration on cancellation
- ▸Data and environment validation with Zod
- ▸Password hashing with Argon2 and global exception handling
✦ Key endpoints
Main operations available in the API, grouped by resource. Check the interactive documentation for parameters and response formats.
Users
POST /users · GET /users · GET /users/:id · PUT /users/:id · DELETE /users/:id
Categories
POST /categories · GET /categories · GET /categories/:id · PATCH /categories/:id · DELETE /categories/:id
Products
POST /products · GET /products · GET /products/:id · PATCH /products/:id · DELETE /products/:id
Orders
POST /orders · GET /orders · GET /orders/:id · PATCH /orders/:id/cancel
✦ Business rules
Order totals are calculated on the server, unit prices are preserved at purchase time, and stock changes are handled within transactions. Stock is restored only when an order is successfully cancelled, preventing duplicate restocking.
✦ Architecture
The application is organized into domain modules and uses the Repository pattern to separate services from persistence. Order operations use transactions to keep order and stock data consistent.
✦ Current scope
The project does not implement authentication or authorization. It was built to demonstrate backend concepts and should not be used in production with real data without the necessary protections.