Monorift is an Express.js-based project designed with a modular monolith architecture. It aims to provide a structured and scalable foundation for building RESTful APIs using Node.js and TypeScript, emphasizing organization and maintainability through distinct modules and shared utilities.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
What things you need to install the software and how to install them:
A step-by-step series of examples that tell you how to get a development environment running:
-
Clone the repository
git clone https://github.com/bahirul/monorift.git cd monorift -
Install dependencies
npm install
-
Create configuration files The project uses
.envfor default settings and.production.envor.development.envfor environment-specific overrides. You can start by copying theexample.envor creating your own.Example
.env:APP_ID=monorift-app APP_ENV=development APP_PORT=50001 LOGGER_LEVEL=debug CORS_CREDENTIALS=true CORS_ORIGIN=*
To start the server in development mode with hot-reloading:
npm run devThe server will typically run on http://localhost:50002 (or the port specified in your configuration).
Execute console commands using npx tsx ./src/console.ts <command> or directly with the compiled JavaScript file in the dist directory.
Example:
node ./dist/console.js main/hello-worldOr:
npm run build
node ./dist/console.js main/hello-worldThe main API endpoint is available at http://localhost:50002/. You can access the main action by navigating to:
GET http://localhost:50002/
Response:
{
"status": "success",
"data": {
"message": "OK!"
}
}The project follows a structured folder layout to maintain clarity and organization. Below is an overview of the key directories and files:
├── src/
│ ├── app/
│ │ ├── config/
│ │ │ └── app.config.ts # Application configuration loading and interface
│ │ ├── modules/
│ │ │ └── main/
│ │ │ ├── cli/
│ │ │ │ └── hello.cli.ts # CLI command for "hello world"
│ │ │ ├── controllers/
│ │ │ │ │ └── main.controller.ts # Controller for main module API endpoints
│ │ │ └── routes/
│ │ │ └── main.route.ts # Routes definition for the main module
│ │ └── shared/
│ │ ├── middlewares/
│ │ │ ├── morgan.ts # HTTP request logging middleware (Morgan)
│ │ │ ├── malformed.ts # Middleware to catch malformed request errors
│ │ │ └── not.found.ts # Middleware for handling 404 Not Found errors
│ │ ├── services/
│ │ │ ├── logger.ts # Centralized Winston logger service
│ │ │ ├── logger.factory.ts # Logger factory for creating custom loggers
│ │ └── types/
│ │ ├── jsend.ts # JSend response format helpers
│ │ └── utils/
│ │ ├── error.message.ts # Error message formatting helpers
│ │ ├── config.parser.ts # Utility for parsing configuration values
│ │ └── path.alias.ts # Utility for resolving path aliases
│ ├── console.ts # Main entry point for CLI commands
│ ├── express.ts # Express application setup and middleware
│ └── http.ts # Main entry point for the HTTP server (Express app)
├── package.json # Project metadata and dependencies
├── tsconfig.json # TypeScript configuration
└── .example.env # Example env config file
└── tsconfig.json # TypeScript configuration for the project
└── eslint.config.mjs # ESLint configuration file
└── .prettierrc # Prettier configuration file
└── .gitignore # Git ignore file
For detailed documentation on various aspects of the project, refer to the following sections:
- Configuration: Learn how to configure the application using YAML files.
- Routing: Understand how routing is implemented in the application.
- Application Lifecycle: Explore the lifecycle of the application from startup to shutdown.
- Error Handling: Learn about the error handling mechanisms in the project.