backend-architecture-generator
Version:
Generate production-ready Node.js backend architectures - choose between monolithic or microservices patterns with API Gateway, Docker, databases, and more
326 lines (244 loc) β’ 7.1 kB
Markdown
# Node Backend Generator π
[](https://www.npmjs.com/package/node-backend-generator)
[](https://www.npmjs.com/package/node-backend-generator)
[](https://opensource.org/licenses/MIT)
[](https://nodejs.org/)
A powerful CLI tool to generate professional, production-ready **Node.js backend templates** in seconds.
Choose your database, architecture, and features β and get a complete backend with best practices baked in.
## β‘ Quick Overview
**Node Backend Generator** helps you **generate production-ready Node.js backends** in seconds.
Choose between **Monolithic or Microservices architecture**, with built-in features like authentication, Docker setup, Swagger docs, file uploads, and more.
## β¨ Key Features
- ποΈ **Architecture Choice** β Monolithic or Microservices
- ποΈ **Multiple Databases** β MongoDB, PostgreSQL, MySQL, or DB-less
- π **Built-in Auth** β JWT, bcrypt, refresh tokens
- π³ **Docker Ready** β Full containerization support
- π **Auto Documentation** β Swagger/OpenAPI
- π‘οΈ **Security** β Helmet, CORS, rate limiting
- π§ **Email Service** β Nodemailer with templates
- π **File Upload** β Multer with validation
- β‘ **Modern JavaScript** β ES Modules & CommonJS support
- π― **Production Ready** β Error handling, logging, environment config
## π Quick Start
### Using npx (Recommended β No Installation Needed)
```bash
npx node-backend-generator@latest
```
### Global Installation
```bash
npm install -g node-backend-generator
create-node-backend
```
### Local Installation
```bash
npm install node-backend-generator
npx create-node-backend
```
## π― Interactive Setup
The CLI guides you through:
```
? Project name: my-api
? Architecture:
β― Monolithic
Microservices
? Database:
β― MongoDB (Mongoose)
PostgreSQL (Prisma)
MySQL (Sequelize)
None
? Features:
β Authentication | β Docker | β API Docs
β File Upload | β Email | β Rate Limiting
```
## π Generated Project Structure
```
my-api/
βββ src/
β βββ controllers/ # Business logic
β βββ models/ # Database models
β βββ routes/ # API endpoints
β βββ middlewares/ # Auth, validation
β βββ config/ # DB, environment
βββ docker-compose.yml # Full stack setup
βββ package.json # Scripts & dependencies
βββ .env # Environment config
```
## π§ Get Started
```bash
cd my-api
npm install
cp .env.example .env
npm run dev
```
Visit: [http://localhost:3000/api-docs](http://localhost:3000/api-docs) for API documentation.
## π³ Docker Setup
```bash
# Start everything
docker-compose up -d
# Scale microservices
docker-compose up -d --scale auth-service=2 --scale user-service=2
```
## π API Examples
### π Authentication
```bash
# Register
curl -X POST http://localhost:3000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"name":"John","email":"john@test.com","password":"secret"}'
# Login
curl -X POST http://localhost:3000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"john@test.com","password":"secret"}'
```
### π File Upload
```js
const formData = new FormData();
formData.append('file', file);
fetch('/api/upload/single', {
method: 'POST',
headers: { 'Authorization': 'Bearer token' },
body: formData
});
```
## π οΈ Customization
- **Add Routes:** Create under `src/routes/` + logic in `src/controllers/`
- **Add Models:** Define in `src/models/`
- **Add Middleware:** Add to `src/middlewares/` and import globally or per-route
## π€ Support
- π **Docs:** [http://localhost:3000/api-docs](http://localhost:3000/api-docs)
- π **Issues:** GitHub Issues
- π **License:** MIT License
<div align="center">
### Start building your next great API in seconds! π
Generated with β€οΈ by **Node Backend Generator**
</div>
## π§© Full Feature Reference (Detailed Section)
> For users who want the complete setup details, hereβs the expanded guide below β¬οΈ
### π§ Usage
```bash
npx node-backend-generator@latest
```
Follow the setup prompts, select your preferences, and your backend will be ready instantly.
### ποΈ Example Structure (Detailed)
```
my-awesome-api/
βββ server.js
βββ package.json
βββ .env
βββ .env.example
βββ .gitignore
βββ Dockerfile
βββ docker-compose.yml
βββ src/
β βββ config/
β βββ controllers/
β βββ models/
β βββ routes/
β βββ middlewares/
β βββ services/
β βββ utils/
βββ uploads/
βββ tests/
```
### π§° Available Scripts
```bash
npm start # Start production server
npm run dev # Development with nodemon
npm test # Run tests
npm run lint # Lint code
npm run lint:fix # Auto-fix lint issues
```
### π Authentication Usage
```json
POST /api/auth/register
{
"name": "John Doe",
"email": "john@example.com",
"password": "securepassword"
}
```
```json
POST /api/auth/login
{
"email": "john@example.com",
"password": "securepassword"
}
```
Add JWT token:
```
Authorization: Bearer <your_jwt_token_here>
```
### π§Ύ Environment Variables
```env
# Server
NODE_ENV=development
PORT=3000
# Database
MONGODB_URI=mongodb://localhost:27017/your-db
DATABASE_URL="mysql://root:password@localhost:3306/your-db"
# JWT
JWT_SECRET=your_super_secret_key
JWT_EXPIRES_IN=7d
# Email
SMTP_HOST=your-smtp-host
SMTP_PORT=587
SMTP_USER=your-email@domain.com
SMTP_PASS=your-password
```
### π§± Database Setup
**MongoDB (Mongoose)**
- Update `MONGODB_URI` in `.env`
- Done.
**MySQL / PostgreSQL (Sequelize)**
- Update `.env` credentials.
**Prisma**
```bash
npx prisma generate
npx prisma db push
```
### π³ Docker Support (Detailed)
```bash
docker-compose up -d
docker build -t my-backend .
docker run -p 3000:3000 my-backend
```
### π§ Email Example
```json
POST /api/email/test
{
"email": "test@example.com"
}
```
### π οΈ Extend Functionality
- **Controllers:** Add in `src/controllers`
- **Routes:** Add in `src/routes`
- **Middlewares:** Add in `src/middlewares`
## π License
MIT License β see [LICENSE](./LICENSE)
<div align="center">
β¨ **Happy Coding!** β¨
Built with β€οΈ by **Trina Dasgupta**
</div>