A complete, production-ready Node.js/Express base project template with PostgreSQL, Redis, MinIO, and modern development tools. Use this as a starting point for any backend API project.
- Node.js 20+ with ES Modules
- Express.js framework with clean MVC architecture
- PostgreSQL 15 with Sequelize ORM and CLI migrations
- Redis for caching and session storage
- MinIO for object storage (file upload/download)
- Swagger/OpenAPI 3 for API documentation
- Internationalization (i18n) - Multi-language support
- Docker & Docker Compose for containerization
- Makefile for task automation
- GitHub Actions CI/CD pipeline
- ESLint & Prettier for code quality
- Jest for testing
- Rate limiting and security middleware
- Comprehensive logging system
- Input validation and error handling
backend/
βββ src/
β βββ config/ # Database, Redis, MinIO configuration
β βββ controllers/ # Request handlers
β βββ database/ # Migrations and seeders
β β βββ migrations/ # Database migrations
β β βββ seeders/ # Database seeders
β βββ docs/ # API documentation (Swagger)
β βββ i18n/ # Internationalization files
β βββ middlewares/ # Middlewares (auth, validation, etc.)
β βββ models/ # Sequelize models
β βββ routes/ # API routes
β βββ services/ # Business logic layer
β βββ scripts/ # Utility scripts
β βββ app.js # Main application file
βββ tests/ # Test files
βββ .github/workflows/ # GitHub Actions
βββ docker-compose.yml # Production Docker setup
βββ docker-compose.dev.yml # Development Docker setup
βββ Dockerfile
βββ README.md
- Node.js 20+
- Docker & Docker Compose
- PostgreSQL 15 (if running locally)
- Redis (if running locally)
- MinIO (if running locally)
# Clone repository
git clone <your-repository-url>
cd backend
# Copy and configure environment variables
cp .env.example .env
# Edit .env according to your needs
# Start all services (development mode)
make docker-up-dev
# View logs
make docker-logs
# Stop services
make docker-down# Start production setup
make docker-up
# View logs
make docker-logs
# Stop services
make docker-down# Install dependencies
npm install
# Configure environment variables
cp .env.example .env
# Edit .env for your local environment
# Start PostgreSQL, Redis, MinIO with Docker
docker-compose up -d postgres redis minio
# Run database migrations
make migrate
# Seed database with sample data (optional)
make seed
# Start development server
make dev# View all available commands
make help
# Setup project from scratch
make setup
# Start development server
make dev
# Run database migrations
make migrate
# Create new migration
make migration-create NAME=create-users
# Create new seeder
make seeder-create NAME=demo-users
# Run tests
make test
# Lint and format code
make lintThis project uses Sequelize CLI for database migrations and seeders.
# Create new migration
make migration-create NAME=create-users
make migration-create NAME=add-user-avatar
make migration-create NAME=create-products
# Create new seeder
make seeder-create NAME=demo-users
make seeder-create NAME=demo-products# Run all pending migrations
make migrate
# or
npm run migrate
# Rollback last migration
make migrate-undo
# or
npm run migrate:undo
# Check migration status
make db-status# Run all seeders
make seed
# or
npm run seed
# Rollback all seeders
make seed-undo
# or
npm run seed:undoThe project includes example models and migrations for reference:
example_items table:
id(INTEGER, AUTO INCREMENT, PRIMARY KEY)name(STRING, NOT NULL)description(TEXT)status(ENUM: 'active', 'inactive', 'draft')metadata(JSONB)created_at(DATETIME)updated_at(DATETIME)
API Documentation is automatically generated using Swagger/OpenAPI 3.
- Swagger UI:
http://localhost:3000/api-docs - Interactive API Testing: Test endpoints directly in Swagger UI
GET /health- Health check endpointGET /ping- Simple ping testGET /api/v1/examples- Get all examples (with pagination)POST /api/v1/examples- Create new exampleGET /api/v1/examples/:id- Get example by IDPUT /api/v1/examples/:id- Update exampleDELETE /api/v1/examples/:id- Delete example
The API supports multiple languages through the Accept-Language header:
# English responses
curl -H "Accept-Language: en" http://localhost:3000/api/v1/examples
# Vietnamese responses
curl -H "Accept-Language: vi" http://localhost:3000/api/v1/examples{
"success": true,
"message": "Examples retrieved successfully.",
"messageCode": "example.get_all.success",
"data": [...],
"error": null
}# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm test -- --coverage
# Using Makefile
make test
make test-coverage# Run ESLint
npm run lint
make lint
# Fix ESLint errors automatically
npm run lint:fix
make lint-fix
# Check Prettier formatting
npm run format:check
make format-check
# Format code with Prettier
npm run format
make formatWhen running with docker-compose.dev.yml, you can access:
- Adminer (PostgreSQL Admin): http://localhost:8080
- Redis Commander: http://localhost:8081
- MinIO Console: http://localhost:9001
Create a .env file and configure the following variables:
# Server
NODE_ENV=development
PORT=3000
HOST=0.0.0.0
# Database
DB_HOST=localhost
DB_PORT=5432
DB_NAME=app_db
DB_USER=postgres
DB_PASSWORD=postgres
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
# MinIO
MINIO_ENDPOINT=localhost
MINIO_PORT=9000
MINIO_ACCESS_KEY=minioadmin
MINIO_SECRET_KEY=minioadmin
MINIO_BUCKET_NAME=app-files
MINIO_USE_SSL=false
# JWT
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
JWT_EXPIRES_IN=24h
# API
API_VERSION=v1
API_PREFIX=/api
# Internationalization
DEFAULT_LANGUAGE=en
SUPPORTED_LANGUAGES=en,viThe project uses GitHub Actions to automatically:
- Run tests and linting
- Build Docker image
- Security scanning
- Deploy (configure secrets as needed)
To push images to Docker Hub, configure these secrets in GitHub:
DOCKER_USERNAMEDOCKER_PASSWORD
-
Server Setup:
# On production server git clone <your-repository-url> cd backend # Configure production environment cp .env.example .env.production # Edit .env.production with production values # Start production stack docker-compose up -d
-
Database Setup:
# Run migrations on production docker-compose exec backend npm run migrate
-
SSL/HTTPS Setup:
- Use reverse proxy (Nginx/Traefik)
- Configure SSL certificates (Let's Encrypt recommended)
- Application:
GET /health - Database: Checked in health endpoint
- Redis: Checked in health endpoint
- MinIO: Checked in health endpoint
# View real-time logs
docker-compose logs -f
# View logs for specific service
docker-compose logs -f backend- Helmet.js for security headers
- Rate limiting for API endpoints
- CORS configuration
- Input validation with middleware
- File upload restrictions and validation
- Environment-based configuration
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Create a Pull Request
- Follow ESLint and Prettier configurations
- Write tests for new features
- Follow conventional commit messages
- Update documentation when needed
- Ensure all tests pass before submitting PR
MIT License - see the LICENSE file for details.
-
Database connection error:
# Check PostgreSQL container docker-compose ps postgres docker-compose logs postgres -
Redis connection error:
# Check Redis container docker-compose ps redis docker-compose logs redis -
MinIO connection error:
# Check MinIO container docker-compose ps minio docker-compose logs minio -
Port already in use:
# Find process using port lsof -i :3000 # Or change PORT in .env file
# Run with debug logs
DEBUG=* npm run dev
# Run tests with debug
DEBUG=* npm test- GitHub Issues: Create an issue
- Documentation: Project Wiki
- Email: [email protected]
This is a base project template. To use it for your specific project:
- Clone the repository
- Update project name in
package.jsonand README - Configure environment variables for your needs
- Modify example models/controllers to match your domain
- Add your business logic to services and controllers
- Update i18n messages for your application
- Configure deployment settings for your infrastructure
The template provides a solid foundation with best practices, security, testing, and deployment ready to go!