This project demonstrates MySQL database and Sequelize ORM usage with Docker Compose.
- Node.js
- Docker & Docker Compose
- Clone the repository:
git clone <repository-url>
cd node-sequelize-boilerplate- Install dependencies:
npm install- Set up environment variables:
cp .env.example .env
cp config/config.example.json config/config.jsonEdit the .env and config/config.json files with your database credentials.
- Start MySQL database with Docker:
docker compose up -d- Run database migrations:
npx sequelize-cli db:migrate- Run database seeders (optional):
npx sequelize-cli db:seed:all- Start the application:
npm startnpx sequelize-cli db:migratenpx sequelize-cli db:migrate:undonpx sequelize-cli model:generate --name ModelName --attributes field1:string,field2:integernpx sequelize-cli seed:generate --name demo-user- Container:
my_mysql - Port:
3306 - Database:
mydb - User:
myuser - Password:
mypassword - Root Password:
rootpassword
This project provides comprehensive API documentation using Swagger UI. Once the server is running, you can access the interactive API documentation at:
Swagger UI: http://localhost:3000/api-docs
The API documentation includes:
- All available API endpoints
- Request/Response schemas
- Interactive API testing interface
- Complete CRUD operations for User and Post models
This project follows a modern layered architecture:
- Controllers: Handle HTTP requests/responses
- Services: Business logic layer
- DTOs: Data Transfer Objects for data transformation
- Models: Sequelize database models
- Middleware: Request validation, logging, error handling
- Routes: API endpoint definitions
├── config/
│ ├── config.json # Sequelize database settings (excluded from git)
│ ├── config.example.json # Template for database settings
│ ├── app.js # Express app configuration
│ ├── middleware.js # Middleware setup
│ └── routeConfig.js # Route configuration
├── controllers/ # Request/response handlers
├── services/ # Business logic layer
├── dto/ # Data Transfer Objects
├── models/ # Sequelize models
├── migrations/ # Database migration files
├── seeders/ # Test data files
├── middleware/ # Custom middleware
├── routes/ # API route definitions
├── docs/ # API documentation
├── docker-compose.yml # MySQL Docker settings
├── .env.example # Environment variables template
└── app.js # Main application entry point
The following features are planned for future development:
- In-Memory Caching: Implement caching for frequently accessed data
- Redis Integration: Add Redis for distributed caching and session management
- Query Result Caching: Cache database query results to improve performance
- TypeScript Migration: Convert the entire project to TypeScript for better type safety
- Enhanced Error Handling: Implement more granular error handling and logging
- Rate Limiting: Add API rate limiting for better security
- Authentication & Authorization: Implement comprehensive JWT-based authentication system
- JWT Authentication with secure token generation
- Refresh Token mechanism for secure token renewal
- User registration with password hashing (bcrypt)
- Login system with email/password validation
- Protected routes middleware
- Role-based access control (RBAC)
- Token blacklisting and revocation
- API Versioning: Add support for API versioning
- Automated Testing: Add comprehensive unit and integration tests