A production-ready microservices boilerplate for building modern applications with authentication, featuring:
- Backend: Microservices architecture with Node.js + Fastify + TypeScript + Prisma + PostgreSQL
- Frontend: React Native + Expo + Zustand + TypeScript
- Microservices: REST API and Event Queue services with shared domain logic
- Authentication: JWT-based auth with secure error handling
- State Management: Zustand for performant React state
- Database: PostgreSQL with Prisma ORM
- Error Handling: Centralized error management with user-friendly messages
- Docker: Full containerization with microservices support for development and production
- DevOps: Automated scripts for microservices deployment and development workflow
boilerplate/
βββ .gitignore # Root project gitignore
βββ docker-compose.yml # Development environment
βββ docker-compose.prod.yml # Production environment
βββ package.json # Workspace configuration
βββ scripts/ # Development scripts
β βββ setup.sh # Initial project setup
β βββ docker-dev.sh # Development environment manager
β βββ docker-prod.sh # Production deployment manager
βββ backend/ # Microservices Backend
β βββ .gitignore # Backend-specific ignores
β βββ .dockerignore # Docker build optimization
β βββ Dockerfile # Multi-stage production build (supports multiple services)
β βββ controllers/ # Microservices (rest-api, event-queue)
β β βββ rest-api/ # REST API microservice
β β βββ event-queue/ # Event Queue microservice
β βββ domain/ # Shared business logic (auth, user)
β βββ utils/ # Shared utilities (db, jwt, errors)
β βββ prisma/ # Database schema and migrations
βββ mobile/ # React Native/Expo app
βββ .gitignore # Mobile-specific ignores
βββ assets/ # App icons and images
βββ app/ # Expo Router screens
βββ src/ # Application source code
βββ store/ # Zustand stores
βββ hooks/ # Custom React hooks
βββ services/ # API services
βββ components/ # UI and feature components
βββ utils/ # Helper functions
The easiest way to get started is using Docker:
# Clone the repository
git clone <your-repo-url>
cd boilerplate
# Run the setup script
./scripts/setup.sh
# Start the development environment
./scripts/docker-dev.sh startAccess your services:
- π REST API: http://localhost:8080
- π Event Queue: Background service (no HTTP interface)
- ποΈ Database: localhost:5432
- π± Mobile:
cd mobile && npm start
Useful commands:
./scripts/docker-dev.sh logs # View logs
./scripts/docker-dev.sh status # Check service status
./scripts/docker-dev.sh stop # Stop servicesIf you prefer manual setup without Docker:
- Node.js 18+
- PostgreSQL database
- Docker & Docker Compose (for containerized setup)
- Expo CLI (
npm install -g @expo/cli) - Git
-
Navigate to backend directory:
cd backend -
Install dependencies:
npm install
-
Set up environment variables:
cp .env.example .env
Update
.envwith your database URL and JWT secret. -
Set up database:
npm run db:push npm run db:generate
-
Start development server:
npm run dev
The REST API will be running at http://localhost:8080
This boilerplate supports a microservices architecture with multiple services sharing domain logic:
- Purpose: HTTP API endpoints for client applications
- Port: 8080
- Features: Authentication, user management, RESTful endpoints
- Health Check: HTTP endpoint at
/
- Purpose: Background event processing and task queue
- Port: No HTTP interface (background service)
- Features: Asynchronous event processing, background jobs
- Health Check: Process monitoring
Both services share:
- Domain Logic (
domain/): Business logic for auth and user management - Utilities (
utils/): Database connections, JWT handling, error management - Database: Same PostgreSQL instance and schema
Start specific services:
# Start all services
./scripts/docker-dev.sh start
# Start only REST API
./scripts/docker-dev.sh start --only-rest-api
# Start only Event Queue
./scripts/docker-dev.sh start --only-event-queue
# View service-specific logs
./scripts/docker-dev.sh logs rest-api
./scripts/docker-dev.sh logs event-queue-
Navigate to mobile directory:
cd mobile -
Install dependencies:
npm install
-
Update API URL in
src/services/api.tsto match your backend URL -
Start Expo development server:
npm start
-
Use Expo Go app to scan QR code or run on simulator:
npm run ios # iOS simulator npm run android # Android emulator
- β Microservices Architecture - Scalable service separation with shared domain logic
- β TypeScript - Full type safety across all services
- β Fastify - High-performance web framework for REST API
- β Prisma ORM - Type-safe database access shared across services
- β JWT Authentication - Secure token-based auth
- β Centralized Error Handling - Consistent error responses
- β Input Validation - TypeBox schema validation
- β Request/Response Logging - Structured logging with Pino
- β CORS Configuration - Cross-origin resource sharing
- β Environment Configuration - Type-safe config management
- β Database Migrations - Version-controlled schema changes
- β Event Processing - Background task processing with Event Queue service
- β Service Independence - Deploy and scale services independently
- β React Native + Expo - Cross-platform mobile development
- β Expo Router - File-based navigation
- β Zustand State Management - Lightweight, performant state
- β TypeScript - Full type safety
- β Form Validation - Client-side input validation
- β Error Handling - User-friendly error messages
- β Loading States - Responsive UI feedback
- β Persistent Storage - Zustand persistence
- β Custom Hooks - Reusable logic patterns
- β Component Library - Consistent UI components
This boilerplate includes complete Docker containerization for both development and production environments:
- Multi-stage Dockerfile for optimized production builds
- Development setup with hot reload and debugging support
- Production configuration with security best practices
- Automated scripts for easy environment management
- Database persistence with Docker volumes
- Health checks and monitoring
# Quick start (with setup)
./scripts/setup.sh
./scripts/docker-dev.sh start
# Or manually
docker-compose up -d| Service | URL | Description |
|---|---|---|
| REST API | http://localhost:8080 | Fastify HTTP API server |
| Event Queue | Background Service | Event processing service (no HTTP interface) |
| Database | localhost:5432 | PostgreSQL database |
| Redis | localhost:6379 | Optional caching (--with-redis) |
| PgAdmin | http://localhost:8081 | Optional DB admin (--with-pgadmin) |
# Start services
./scripts/docker-dev.sh start # All microservices
./scripts/docker-dev.sh start --only-rest-api # REST API only
./scripts/docker-dev.sh start --only-event-queue # Event Queue only
./scripts/docker-dev.sh start --with-redis # Include Redis
./scripts/docker-dev.sh start --with-pgadmin # Include PgAdmin
# Monitor services
./scripts/docker-dev.sh logs # All logs
./scripts/docker-dev.sh logs rest-api # REST API logs only
./scripts/docker-dev.sh logs event-queue # Event Queue logs only
./scripts/docker-dev.sh status # Service status
./scripts/docker-dev.sh health # Health check all services
# Development utilities
./scripts/docker-dev.sh shell # Microservice container shell
./scripts/docker-dev.sh db # Database shell
./scripts/docker-dev.sh restart --build # Restart with rebuild
# Cleanup
./scripts/docker-dev.sh stop # Stop services
./scripts/docker-dev.sh clean # Remove everything# Create production environment file
cp .env.example .env
# Edit .env with production values (JWT_SECRET, DB_PASSWORD, etc.)
# Deploy to production
./scripts/docker-prod.sh deploy# Deploy with additional services
./scripts/docker-prod.sh deploy --with-nginx # Include Nginx reverse proxy
./scripts/docker-prod.sh deploy --with-redis # Include Redis caching
./scripts/docker-prod.sh deploy --only-rest-api # Deploy only REST API
./scripts/docker-prod.sh deploy --only-event-queue # Deploy only Event Queue
# Monitor production
./scripts/docker-prod.sh status # Service status
./scripts/docker-prod.sh logs # All logs
./scripts/docker-prod.sh logs rest-api # REST API logs
./scripts/docker-prod.sh logs event-queue # Event Queue logs
# Database operations
./scripts/docker-prod.sh backup # Create backup
./scripts/docker-prod.sh restore # Restore from backup
# Independent scaling
./scripts/docker-prod.sh scale rest-api=3 event-queue=1 # Scale services independently- Hot reload for backend development
- Volume mounts for live code updates
- Debug logging enabled
- Development database with easy access
- Optimized builds with multi-stage Dockerfile
- Security hardening (read-only filesystem, non-root user)
- Resource limits and health checks
- Automatic restarts and logging configuration
Create a .env file in the root directory:
# Database Configuration
DB_USER=postgres
DB_PASSWORD=your-strong-password
DB_NAME=auth_boilerplate
# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key
# Redis Configuration (optional)
REDIS_PASSWORD=your-redis-password
# Logging
LOG_LEVEL=infoThis boilerplate implements Docker best practices:
- Multi-stage builds for smaller production images
- Non-root user for security
- Health checks for service monitoring
- Layer caching optimization
- Security scanning ready configuration
- Resource limits in production
- Proper logging configuration
- Port conflicts: Change ports in docker-compose.yml
- Database connection: Ensure database is healthy before backend starts
- File permissions: Scripts should be executable (
chmod +x scripts/*.sh) - Memory issues: Increase Docker memory limits
# Check container status
docker ps
# View container logs
docker logs auth_boilerplate_backend
# Access container
docker exec -it auth_boilerplate_backend sh
# Check Docker resources
docker system df
docker system prune # Cleanup unused resourcesRoot Level:
npm run setup- Initial project setupnpm run dev- Start Docker development environmentnpm run dev:logs- View development logsnpm run dev:stop- Stop development environmentnpm run prod:deploy- Deploy to production
Backend:
npm run dev- Start development server (defaults to REST API)npm run dev:rest-api- Start REST API development servernpm run dev:event-queue- Start Event Queue development servernpm run build- Build all services for productionnpm run start- Start production server (defaults to REST API)npm run start:rest-api- Start REST API production servernpm run start:event-queue- Start Event Queue production servernpm run db:generate- Generate Prisma clientnpm run db:push- Push schema to databasenpm run db:migrate- Run database migrations
Mobile:
npm start- Start Expo development servernpm run ios- Run on iOS simulatornpm run android- Run on Android emulatornpm run web- Run in web browsernpm run lint- Run ESLint
Docker Commands:
./scripts/docker-dev.sh start- Start development environment./scripts/docker-prod.sh deploy- Deploy to productiondocker-compose up -d- Start services manuallydocker-compose logs -f- View all logs
This project uses:
- ESLint for code linting
- TypeScript for type checking
- Prettier for code formatting (recommended)
Testing setup is not included in this boilerplate but can be easily added:
Backend Testing:
- Jest + Supertest for API testing
- Prisma test database setup
Mobile Testing:
- Jest + React Native Testing Library
- Detox for E2E testing
The backend can be deployed to any Node.js hosting platform:
- Railway
- Vercel
- Heroku
- DigitalOcean App Platform
- AWS/GCP/Azure
- Use EAS Build for app store deployment
- Expo Updates for over-the-air updates
- See Expo deployment docs for details
- JWT tokens are stored securely using AsyncStorage
- Password hashing using bcrypt with salt rounds
- Input validation on both client and server
- CORS properly configured
- Environment variables for sensitive data
- SQL injection prevention with Prisma
- 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) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Fastify
- Database powered by Prisma
- Mobile development with Expo
- State management by Zustand
- Type safety with TypeScript