Ensure you have Node.js version 20 or later installed for this project. This guide assumes you're using Node.js 20.
Begin by installing the project dependencies. Open your terminal and execute:
$ npm installThis project utilizes Docker for database services. Ensure Docker and Docker Compose are installed on your machine.
To start your local database server with Docker, run:
$ docker-compose up -dConfigure your environment variables for the project. Below is an example .env file:
PORT=3000
MONGO_URL=mongodb://mongo-user:123456@localhost:27017
MONGO_DB_NAME=mystore
JWT_SECRET=secretDue to time constraints, Swagger documentation was not implemented for this project. The primary aim is to explore design patterns and adhere to best coding practices.
Access the application through the following endpoints:
- User Registration: http://localhost:3000/api/auth/register
- User Login: http://localhost:3000/api/auth/login
- Authentication Endpoint: http://localhost:3000/api/auth
In developing this backend in Node.js, I've focused on building a clean architecture, incorporating a wide range of design patterns and adhering to the best programming practices. I have rigorously followed the SOLID principles to ensure the code is modular, extensible, and easily maintainable. The patterns and techniques I've implemented are versatile, designed to be applicable across a wide variety of software projects, from scripts to frontend and backend applications. Below, I detail the key components of the architecture I've designed:
I've based the backend architecture on DDD, allowing me to structure the system in a way that accurately reflects the complexities and boundaries of the business domain, facilitating the scalability and adaptability of the system.
I've adopted the MVC pattern in the presentation layer to separate the business logic from the user interface, improving code organization and supporting the separation of responsibilities.
I've used this pattern to standardize the HTTP responses from the server, ensuring consistency and predictability in the communication interfaces.
I've applied this pattern to all integrations with external dependencies, allowing me to abstract away from concrete implementations. Combined with DDD, this facilitates the substitution or modification of libraries and external services without significantly impacting the codebase.
I've implemented decorators for elegant error handling and method binding, adding additional behaviors to classes and methods in a declarative manner.
I've centralized the business logic into use cases, allowing me to clearly define the system's operations and simplify its maintenance.
I've defined DTOs to map and validate incoming data, ensuring that only valid and relevant data is processed.
I've introduced an abstraction layer between the database and the backend to minimize the impact of database schema changes on the system, promoting code stability and flexibility.
I normalize the data between the database and the backend to facilitate consistent and coherent data transformation and integration.
This abstraction layer provides me with the flexibility to easily switch database technologies, supporting agile technological evolution.
To avoid hidden couplings and enhance the system's modularity, I've implemented dependency injection, which improves the testability of the code.
These elements are the backbone of the backend I've developed, ensuring a well-structured system that is both powerful and easy to evolve. With this approach, I am committed to software development excellence, prioritizing quality, scalability, and sustainability of the project.
](https://res.cloudinary.com/runyshark1/image/upload/v1707709939/33Ho_ucktq0.gif)