This project was originally developed as a required challenge for Escola DNC. It has since been completely refactored, modernized, and containerized following software engineering best practices.
This is a RESTful API built with Node.js, Express, and MongoDB. It manages a complete e-commerce backend workflow including Customers, Products, Inventory, and Sales. The code structure strictly adheres to the MVC (Model-View-Controller) architecture, ensuring clean separation of concerns and maintainability. All internal code, database schemas, and endpoints are implemented in English, while end-user-facing messages (such as UI translations and generic validation errors) remain in Portuguese.
- Products: Full CRUD operations for products.
- Inventory: Automatic inventory creation for new products and seamless deduction upon successful sales.
- Customers: Management of customer profiles with embedded address documents.
- Sales: Transactional workflow that validates inventory, calculates totals, updates statuses, and deducts items from inventory stocks automatically.
- Node.js
- Express.js
- MongoDB with Mongoose
- Docker & Docker Compose
src/
├── config/ # Database and environment configurations
├── controllers/ # Request handlers and business logic
├── models/ # Mongoose schema definitions
├── routes/ # Express route declarations
└── app.js # Entry point and middleware setup
Make sure you have Docker and Docker Compose installed.
- Clone the repository and navigate into the project root directory.
- Build and start the containers using Docker Compose:
docker-compose up --build
- The API will be available at
http://localhost:3000and it will automatically connect to a MongoDB instance running in the background.
If you prefer to run the application locally without Docker, ensure you have Node.js and a local instance of MongoDB running.
- Install dependencies:
npm install
- Create a
.envfile in the root directory and set your MongoDB URI:PORT=3000 MONGODB_URI=mongodb://localhost:27017/dncommerce
- Start the application:
npm start
You can use the provided bash script to quickly verify all endpoints:
chmod +x tests/test_api_bash.sh
./tests/test_api_bash.sh(A PowerShell script is also provided in the tests directory for Windows users).