express-mongo-boilerplate-generator
Version:
A production-ready boilerplate generator for Express.js and MongoDB with service layer architecture and Joi validation
154 lines (111 loc) ⢠3.92 kB
Markdown
# Express MongoDB Boilerplate Generator
A powerful CLI tool to generate production-ready Express.js and MongoDB applications with service layer architecture, Joi validation, and industry best practices.
## š Installation
```bash
npm install -g express-mongo-boilerplate-generator
```
Or use with npx (recommended):
```bash
npx express-mongo-boilerplate-generator create my-app
```
## ā” Quick Start
### Create a new project:
```bash
create-express-mongo-app create my-awesome-api
```
### Interactive mode:
```bash
create-express-mongo-app init
```
## ⨠Features
- ā
**Service Layer Architecture** - Clean separation of concerns
- ā
**Joi Validation** - Robust request validation
- ā
**JWT Authentication** - Secure token-based auth
- ā
**MongoDB with Mongoose** - Modern ODM
- ā
**Organized Enums** - Centralized constants
- ā
**Error Handling** - Custom error classes
- ā
**Docker Support** - Ready for containerization
- ā
**Testing Setup** - Jest with in-memory MongoDB
- ā
**ESLint & Prettier** - Code quality tools
- ā
**Security** - Helmet, CORS, Rate limiting
## š Generated Project Structure
```
my-app/
āāā src/
ā āāā controllers/ # HTTP request handlers
ā āāā services/ # Business logic layer
ā āāā routes/ # API endpoints
ā āāā models/ # Mongoose schemas
ā āāā validators/ # Joi validation schemas
ā āāā middleware/ # Custom middleware
ā āāā utils/
ā ā āāā enums/ # Enum constants
ā āāā app.js # Express app setup
ā āāā server.js # Server entry point
āāā __tests__/ # Test files
āāā .env # Environment variables
āāā .env.example # Environment template
āāā docker-compose.yml # Docker compose config
āāā Dockerfile # Docker configuration
āāā package.json
āāā README.md
```
## š ļø CLI Options
```bash
create-express-mongo-app create <project-name> [options]
Options:
-g, --git Initialize git repository
-i, --install Install dependencies automatically
-h, --help Display help
-V, --version Output version number
```
## š Requirements
- Node.js >= 14.0.0
- npm >= 6.0.0
- MongoDB (local or Atlas)
## šļø Architecture
The generated boilerplate follows **Service Layer Architecture**:
- **Routes** ā Define endpoints
- **Controllers** ā Handle HTTP only
- **Services** ā Business logic & DB operations
- **Validators** ā Joi request validation
- **Models** ā Mongoose schemas
- **Enums** ā Centralized constants
## š§ Usage Example
After generating your project:
```bash
# Navigate to project
cd my-awesome-api
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env
# Start development server
npm run dev
```
Your API will be running at `http://localhost:3000`
## š What's Included
- User authentication system
- JWT token management
- Request validation with Joi
- Error handling middleware
- MongoDB connection management
- Pagination support
- Security best practices
- Docker configuration
- Testing setup
- ESLint configuration
## š License
MIT
## šØāš» Author
**Usama Talib**
- Email: talibusama1234@gmail.com
- GitHub: [@usamatalib](https://github.com/Usama123talib)
## š¤ Contributing
Issues and pull requests are welcome!
## š Links
- [GitHub Repository](https://github.com/Usama123talib/express-mongo-boilerplate)
- [NPM Package](https://www.npmjs.com/package/express-mongo-boilerplate-generator)
- [Report Issues](https://github.com/Usama123talib/express-mongo-boilerplate/issues)
---
Made with ā¤ļø by Usama Talib