Mimo is a backend application for an e-commerce platform, built using Node.js, Express, and MongoDB. This backend handles key functionalities such as products, orders, users, and payments.
Before starting, ensure you have the following installed:
- Node.js - Version 20+ recommended
- TypeScript - Version 5+ recommended
- MongoDB - NoSQL database
- npm - Node.js package manager
- Clone the repository to your local environment:
git clone https://github.com/DaniOmer/mimo-backend.git
cd mimo-backend
- Install project dependencies:
npm install
-
Create a
.env
file in the root directory to configure environment variables. See examples in the.env.example
file. -
Build the development environment database:
docker compose -f compose.yaml build
- Start the development environment database:
docker compose -f compose.yaml up -d
- Start the application:
npm run start
The Mimo project is organized by components. Each component represents a core entity or feature of the application, such as products, orders, users, and payments.
mimo-backend/
├── dist/ # Contains the compiled JavaScript code
│ ├── apps/ # Compiled application-specific modules
│ ├── config/ # Compiled configuration files
│ ├── libraries/ # Compiled reusable libraries
│ ├── index.js # Compiled application entry point
│ └── ... # Other compiled files
├── src/ # Main source code (TypeScript)
│ ├── apps/ # Application-specific modules
│ │ ├── users/ # Users module
│ │ │ ├── api/ # Routes and controllers
│ │ │ │ ├── routes.ts
│ │ │ │ └── userController.ts
│ │ │ ├── domain/ # Business logic for users
│ │ │ │ └── userService.ts
│ │ │ ├── data-access/ # Data access (models, repositories)
│ │ │ ├── userModel.ts
│ │ │ └── userRepository.ts
│ │ ├── products/ # Products module
│ │ │ ├── api/
│ │ │ │ └── productController.ts
│ │ │ ├── domain/
│ │ │ │ └── productService.ts
│ │ │ ├── data-access/
│ │ │ ├── productModel.ts
│ │ │ └── productRepository.ts
│ │ ├── payments/ # Payments module
│ │ ├── api/
│ │ │ └── paymentController.ts
│ │ ├── domain/
│ │ │ └── paymentService.ts
│ │ ├── data-access/
│ │ └── paymentModel.ts
│ ├── config/ # Configuration files
│ │ ├── db.ts # MongoDB connection configuration
│ │ └── config.ts # Other global settings
│ ├── libraries/ # Reusable cross-component libraries
│ │ ├── logger/ # Log management
│ │ │ └── logger.ts
│ │ ├── authenticator/ # Authentication and JWT management
│ │ └── authMiddleware.ts
│ ├── tests/ # Unit and integration tests
│ ├── index.ts # Application entry point
│ ├── .env # Environment variables
│ └── README.md # Project documentation
├── docs/ # Detailed project documentation
│ ├── api_routes.md # API route documentation
│ └── *.md # Other detailed documentation
├── .gitignore # Git ignore file for untracked files
├── package.json # Main project dependencies and scripts
└── tsconfig.json # TypeScript configuration
Testing is an essential part of the development process to ensure code quality, functionality, and stability. This project uses Jest as the testing framework and ts-jest for TypeScript support.
-
Unit Tests:
Test individual functions or methods in isolation to ensure they work as expected. Unit tests are located in files with the.unit.test.ts
suffix. -
Integration Tests:
Test the interaction between multiple modules or components, such as API endpoints or database queries. Integration tests are located in files with the.integration.test.ts
suffix.
-
To run all tests (unit and integration):
npm run test:all
-
To run unit tests only:
npm run test:unit
-
To run integration tests only:
npm run test:integration
This project tracks test coverage to ensure critical parts of the codebase are adequately tested. After running tests, coverage reports are generated in the ./coverage
directory. To view coverage reports:
-
Run tests with coverage enabled:
npm run test
-
Open the generated
covearge/lcov-report/index.html
file in a browser for a detailed view.
Tests are written in the __tests__
directories within each module. For example:
- Unit tests for the
users
module are insrc/apps/users/__tests__/userService.unit.test.ts
. - Integration tests for the
products
module are insrc/apps/products/__tests__/productController.integration.test.ts
.
Each test file follows a structured approach:
- Setup: Mock dependencies or initialize required data.
- Execution: Call the function or API endpoint under test.
- Assertions: Verify the result matches expectations.
- Mockingoose: Used for mocking Mongoose models in unit tests.
- MongoDB Memory Server: Provides an in-memory MongoDB instance for integration tests.
-
Run a specific unit test file:
npx jest src/apps/users/__tests__/userService.unit.test.ts
-
Run tests with verbose output:
npm run test -- --verbose
Contributions are welcome! If you find any bugs or have suggestions for improvements, feel free to create an issue or submit a pull request.
This project is licensed under the MIT License.