A robust Node.js backend application built with Express, PostgreSQL, Redis, and Docker for blockchain-related operations.
- Express.js - Fast, unopinionated web framework
- PostgreSQL - Reliable relational database with Sequelize ORM
- Redis - High-performance caching and session storage
- Docker - Containerized development and production environments
- Swagger/OpenAPI - Interactive API documentation
- JWT Authentication - Secure user authentication
- Rate Limiting - API protection against abuse
- Security Headers - Comprehensive security middleware
- Logging & Monitoring - Request tracking and performance monitoring
- Testing Suite - Jest testing framework with coverage
- Code Quality - ESLint and Prettier integration
- CI/CD Pipeline - GitHub Actions automation
- Node.js (v18.0.0 or higher)
- Docker & Docker Compose (for containerized development)
- Git (for version control)
git clone https://github.com/UNKLAB-ID/backend-blockchain.git
cd backend-blockchainCreate environment files from examples:
cp .env.example .env
cp .env.development .env.developmentEdit the environment files with your configuration:
# .env (for local development without Docker)
NODE_ENV=development
PORT=3000
DB_HOST=localhost
DB_PORT=5432
DB_NAME=backend_blockchain
DB_USER=postgres
DB_PASSWORD=your_password
REDIS_HOST=localhost
REDIS_PORT=6379
JWT_SECRET=your-super-secret-jwt-keynpm install# Start all services (PostgreSQL, Redis, API, Management Tools)
make dev
# Or using npm scripts
npm run docker:devThis will start:
- API Server - http://localhost:3000
- PostgreSQL - localhost:5432
- Redis - localhost:6379
- PgAdmin - http://localhost:8080 ([email protected] / admin123)
- Redis Commander - http://localhost:8081
- Swagger Docs - http://localhost:3000/api-docs
# Development
make dev # Start development environment
make build-dev # Build and start development environment
make down-dev # Stop development environment
make logs-dev # View development logs
# Production
make prod # Start production environment
make build-prod # Build and start production environment
make down-prod # Stop production environment
make logs-prod # View production logs
# Utilities
make clean # Clean Docker resources
make health # Check application health
make deploy-prod # Full production deployment with health check- app - Node.js application with hot reload
- postgres - PostgreSQL database
- redis - Redis cache
- pgadmin - Database management interface
- redis-commander - Redis management interface
- app - Optimized Node.js application
- nginx - Reverse proxy with SSL support
Install and start PostgreSQL and Redis locally, then:
# Create database
createdb backend_blockchain
# Start Redis
redis-servernpm run db:migratenpm run devCreate production environment file:
cp .env.production .env.productionConfigure production variables:
# .env.production
NODE_ENV=production
PORT=3000
DB_HOST=your-prod-db-host.amazonaws.com
DB_NAME=backend_blockchain_prod
DB_USER=your_db_user
DB_PASSWORD=strong_production_password
DB_SSL=true
REDIS_HOST=your-redis-host.amazonaws.com
REDIS_PASSWORD=redis_password
JWT_SECRET=super-strong-production-jwt-secret
CORS_ORIGIN=https://yourdomain.com# Build and start production environment
make build-prod
# Or using docker-compose directly
docker-compose -f docker-compose.prod.yml up --build -dmake health
# Or manually
curl http://localhost:3000/api/health- Multi-stage Docker build for optimized image size
- Nginx reverse proxy with rate limiting and security headers
- SSL/TLS support (certificate configuration required)
- Resource limits and auto-restart policies
- Health checks for all services
- Structured logging with rotation
- External database support (AWS RDS, etc.)
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Welcome message and API info |
| GET | /api |
API information and endpoints |
| GET | /api/health |
Comprehensive health check |
| GET | /api/health/simple |
Simple health check for load balancers |
| GET | /api/v1/users |
Get users (example endpoint) |
| GET | /api/v1/users/:id |
Get user by ID (example endpoint) |
Interactive API documentation is available at:
- Development: http://localhost:3000/api-docs
- Production: Disabled for security (contact support)
API uses JWT Bearer token authentication:
Authorization: Bearer <your-jwt-token>- Global: 100 requests per 15 minutes
- API endpoints: 100 requests per 15 minutes
- Auth endpoints: 5 requests per 15 minutes
- Health checks: 30 requests per minute
# Run all tests
npm test
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watchMinimum coverage requirements:
- Branches: 70%
- Functions: 70%
- Lines: 70%
- Statements: 70%
# Check code style
npm run lint
# Fix auto-fixable issues
npm run lint:fix# Format code with Prettier
npm run formatThe project includes ESLint and Prettier configurations:
- ESLint:
.eslintrc.js - Prettier:
.prettierrc.js
The project uses Sequelize ORM with PostgreSQL:
# Run migrations
npm run db:migrate
# Rollback migrations
npm run db:migrate:undo
# Run seeders
npm run db:seed
# Rollback seeders
npm run db:seed:undo
# Create new migration
npx sequelize-cli migration:generate --name your-migration-name
# Create new model
npx sequelize-cli model:generate --name User --attributes email:string,username:string- Development: Docker PostgreSQL container
- Production: External managed database (AWS RDS recommended)
- Test: In-memory or separate test database
| Variable | Description | Required | Default |
|---|---|---|---|
NODE_ENV |
Environment (development/production/test) | Yes | development |
PORT |
Server port | No | 3000 |
DB_HOST |
Database host | Yes | localhost |
DB_PORT |
Database port | No | 5432 |
DB_NAME |
Database name | Yes | - |
DB_USER |
Database user | Yes | - |
DB_PASSWORD |
Database password | Yes | - |
DB_SSL |
Enable SSL for database | No | false |
REDIS_HOST |
Redis host | Yes | localhost |
REDIS_PORT |
Redis port | No | 6379 |
REDIS_PASSWORD |
Redis password | No | - |
JWT_SECRET |
JWT signing secret | Yes | - |
JWT_EXPIRES_IN |
JWT expiration time | No | 7d |
CORS_ORIGIN |
CORS allowed origin | No | http://localhost:3000 |
LOG_LEVEL |
Logging level | No | info |
- Application health:
/api/health - Database connectivity: Included in health check
- Redis connectivity: Included in health check
- Simple health:
/api/health/simple(for load balancers)
- Request/Response logging with sanitization
- Performance monitoring for slow requests
- Error tracking with stack traces
- Request ID tracing for debugging
- Health check endpoints for load balancers
- Performance metrics headers
- Resource usage monitoring
- Error logging and alerting
- Helmet.js - Security headers
- CORS - Cross-origin resource sharing
- Rate limiting - Request throttling
- Input validation - Request validation
- JWT authentication - Secure user auth
- SQL injection protection - Sequelize ORM
- XSS protection - Built-in headers
- Request size limiting - Payload size control
- Environment Variables: Never commit secrets to repository
- HTTPS: Use SSL/TLS in production
- Strong Passwords: Use strong database and JWT secrets
- Regular Updates: Keep dependencies updated
- Security Audits: Run
npm auditregularly
The project includes automated CI/CD pipeline:
- Testing: Automated tests on Node.js 18.x and 20.x
- Linting: Code quality checks
- Security: Dependency vulnerability scanning
- Docker Build: Container image building and testing
- Deployment: Automated deployment to staging/production
- Pull Requests: Run tests and linting
- Push to develop: Deploy to staging
- Push to main: Deploy to production (with manual approval)
# Clean Docker resources
make clean
# Rebuild from scratch
make build-dev# Check database logs
make logs-dev | grep postgres
# Restart services
make down-dev && make dev# Kill processes on ports
sudo lsof -ti:3000 | xargs kill -9
sudo lsof -ti:5432 | xargs kill -9
sudo lsof -ti:6379 | xargs kill -9# Fix Docker permissions
sudo chown -R $USER:$USER .Enable debug logging:
DEBUG=* npm run dev- Documentation: Check this README and inline code comments
- API Docs: Visit
/api-docsin development - Issues: Create GitHub issues for bugs
- Discussions: Use GitHub discussions for questions
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new features
- Ensure all tests pass
- Submit a pull request
This project is licensed under the ISC License - see the LICENSE file for details.
- v1.0.0 - Initial release with Express, PostgreSQL, Redis, Docker setup
- API v1 - Current API version with JWT auth and rate limiting
Happy Coding! π