Skip to content

Repository files navigation

Sequelize + MySQL + Docker Project

This project demonstrates MySQL database and Sequelize ORM usage with Docker Compose.

Requirements

  • Node.js
  • Docker & Docker Compose

Installation

  1. Clone the repository:
git clone <repository-url>
cd node-sequelize-boilerplate
  1. Install dependencies:
npm install
  1. Set up environment variables:
cp .env.example .env
cp config/config.example.json config/config.json

Edit the .env and config/config.json files with your database credentials.

  1. Start MySQL database with Docker:
docker compose up -d
  1. Run database migrations:
npx sequelize-cli db:migrate
  1. Run database seeders (optional):
npx sequelize-cli db:seed:all
  1. Start the application:
npm start

Sequelize Commands

Run migration:

npx sequelize-cli db:migrate

Undo migration:

npx sequelize-cli db:migrate:undo

Create new model:

npx sequelize-cli model:generate --name ModelName --attributes field1:string,field2:integer

Create seed:

npx sequelize-cli seed:generate --name demo-user

Docker Compose Information

  • Container: my_mysql
  • Port: 3306
  • Database: mydb
  • User: myuser
  • Password: mypassword
  • Root Password: rootpassword

API Documentation

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

Project Architecture

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

File Structure

├── 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

Future Enhancements

The following features are planned for future development:

Caching Layer

  • 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

Technology Upgrades

  • 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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages