An open API service indexing awesome lists of open source software.

https://github.com/faizkhairi/microservices-demo

Production-grade microservices platform with Nuxt 4 + NestJS โ€” 7 services demonstrating enterprise architecture patterns
https://github.com/faizkhairi/microservices-demo

api-gateway bullmq docker docker-compose enterprise enterprise-architecture event-driven message-queue microservices nestjs nuxt postgresql prisma redis typescript

Last synced: 2 months ago
JSON representation

Production-grade microservices platform with Nuxt 4 + NestJS โ€” 7 services demonstrating enterprise architecture patterns

Awesome Lists containing this project

README

          

# Microservices Demo

![CI](https://github.com/faizkhairi/microservices-demo/actions/workflows/ci.yml/badge.svg)

**Production-grade microservices platform** demonstrating enterprise architecture patterns with **Nuxt 4 + NestJS**.

Built by [Faiz Khairi](https://github.com/faizkhairi) to showcase scalable system design, message-driven architecture, and modern DevOps practices.

---

## ๐Ÿ—๏ธ Architecture

**7-Service Microservices Platform:**

```
Frontend (Nuxt 4)
โ†“
API Gateway (NestJS) โ€” Routing, Auth, Rate Limiting
โ†“
โ”Œโ”€โ”€โ”ดโ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ†“ โ†“ โ†“ โ†“ โ†“
Auth User Task Notification Queue Worker
:4001 :4002 :4003 :4004 (Background)
โ†“ โ†“ โ†“ โ†“
Auth User Task Notification
DB DB DB DB
```

### Services

| Service | Port | Responsibility |
|---------|------|----------------|
| **Frontend** | 3000 | Nuxt 4 web app with Shadcn-vue |
| **API Gateway** | 4000 | Single entry point, JWT validation, rate limiting |
| **Auth Service** | 4001 | JWT authentication, refresh tokens, bcrypt password hashing |
| **User Service** | 4002 | User profiles and account management |
| **Task Service** | 4003 | Task CRUD + BullMQ job publishing |
| **Notification Service** | 4004 | Email + in-app notifications |
| **Queue Worker** | โ€” | Background job processing with BullMQ |

### Infrastructure

- **4 PostgreSQL databases** (one per service โ€” microservices pattern)
- **Redis** for message queue (BullMQ)
- **Mailpit** for email testing (dev)
- **Docker Compose** orchestrating 12 containers

---

## ๐Ÿš€ Quick Start

### Prerequisites

- [Docker](https://www.docker.com/get-started) 20.10+
- [Docker Compose](https://docs.docker.com/compose/install/) 2.0+
- [Node.js](https://nodejs.org/) 20+ (for local development)
- [pnpm](https://pnpm.io/) 8+ (optional)

### Run the Full Stack

```bash
# Clone the repository
git clone https://github.com/faizkhairi/microservices-demo.git
cd microservices-demo

# Copy environment variables
cp .env.example .env

# Start all services with Docker Compose
docker compose up --build

# Services will be available at:
# - Frontend: http://localhost:3000
# - API Gateway: http://localhost:4000
# - Mailpit UI: http://localhost:8025 (email testing)
```

**First-time setup:** Docker will build all 7 services + databases. This takes ~5-10 minutes.

---

## ๐Ÿ“ฆ Tech Stack

### Frontend
- **Nuxt 4** โ€” Vue 3 SSR framework
- **Shadcn-vue** โ€” Copy-paste UI components
- **Tailwind CSS** โ€” Utility-first styling
- **Pinia** โ€” State management
- **Axios** โ€” HTTP client with JWT interceptor

### Backend
- **NestJS** โ€” Enterprise Node.js framework
- **Prisma ORM** โ€” Type-safe database client
- **PostgreSQL 16** โ€” Production-grade relational DB
- **Passport + JWT** โ€” Authentication strategy
- **BullMQ + Redis** โ€” Job queue for async processing
- **Nodemailer** โ€” SMTP email sending

### DevOps
- **Docker** โ€” Containerization
- **Docker Compose** โ€” Multi-container orchestration
- **GitHub Actions** โ€” CI/CD pipeline
- **Mailpit** โ€” Email testing (catches all emails in dev)

---

## ๐Ÿ› ๏ธ Development

### Run Services Individually

Each service can be run independently for development:

```bash
# Auth Service
cd services/auth-service
npm install
npm run dev # Runs on port 4001

# User Service
cd services/user-service
npm install
npm run dev # Runs on port 4002

# Frontend
cd frontend
npm install
npm run dev # Runs on port 3000
```

### Database Migrations

```bash
# Auth Service migrations
cd services/auth-service
npx prisma migrate dev --name init
npx prisma generate

# User Service migrations
cd services/user-service
npx prisma migrate dev --name init
npx prisma generate

# Task Service migrations
cd services/task-service
npx prisma migrate dev --name init
npx prisma generate

# Notification Service migrations
cd services/notification-service
npx prisma migrate dev --name init
npx prisma generate
```

---

## ๐Ÿงช Testing

```bash
# Run all tests
npm test

# Run tests for specific service
cd services/auth-service
npm test

# E2E tests (Playwright)
cd frontend
npm run test:e2e
```

---

## ๐Ÿ“– Documentation

- [Architecture Design](./ARCHITECTURE.md) โ€” Detailed system design
- [API Gateway](./services/api-gateway/README.md) โ€” Routing and authentication
- [Auth Service](./services/auth-service/README.md) โ€” JWT authentication
- [User Service](./services/user-service/README.md) โ€” Profile management
- [Task Service](./services/task-service/README.md) โ€” Task CRUD + queue
- [Notification Service](./services/notification-service/README.md) โ€” Email + in-app notifications
- [Queue Worker](./services/queue-worker/README.md) โ€” Background jobs

---

## ๐Ÿ”‘ Key Features

### Microservices Architecture
- โœ… **Database per service** โ€” Each service owns its data (no shared DB)
- โœ… **API Gateway pattern** โ€” Centralized routing, auth, rate limiting
- โœ… **Service decomposition** โ€” Clear domain boundaries (auth, users, tasks, notifications)

### Message-Driven Architecture
- โœ… **BullMQ + Redis** โ€” Async job processing
- โœ… **Event-driven** โ€” Task creation triggers notification job
- โœ… **Decoupled services** โ€” Task Service doesn't directly call Notification Service

### Security
- โœ… **JWT authentication** โ€” Stateless auth with 15-minute access tokens
- โœ… **Refresh tokens** โ€” 7-day expiration for secure re-authentication
- โœ… **Bcrypt password hashing** โ€” Industry-standard (salt rounds: 10)
- โœ… **Rate limiting** โ€” 100 req/min per IP at API Gateway
- โœ… **Owner-only access** โ€” Users can only access their own data

### DevOps
- โœ… **Docker Compose** โ€” One-command local environment
- โœ… **Health checks** โ€” Every service has `/health` endpoint
- โœ… **Structured logging** โ€” Winston/Pino with correlation IDs
- โœ… **CI/CD pipeline** โ€” GitHub Actions builds all services

---

## ๐ŸŒ Deployment

### Local Development
```bash
docker compose up
```

### Staging/Production

**Option 1: Docker Compose on VPS**
```bash
# On server (Ubuntu/Debian)
docker compose -f docker-compose.prod.yml up -d

# Services use production environment variables
# PostgreSQL, Redis, and services run in containers
```

**Option 2: Kubernetes (EKS/GKE/AKS)**
```bash
# Deploy to Kubernetes
kubectl apply -f k8s/

# Each service runs as a separate deployment
# RDS for PostgreSQL, ElastiCache for Redis
```

**Frontend Deployment:**
- Netlify (recommended) โ€” Nuxt SSR with Nitro
- Vercel โ€” Alternative for Next.js-like SSR
- Self-hosted with Nginx

---

## ๐Ÿ“Š Data Flow Examples

### User Registration
```
1. User submits form (frontend)
โ†“
2. POST /auth/register โ†’ API Gateway
โ†“
3. API Gateway โ†’ Auth Service
โ†“
4. Auth Service creates user in auth_db
โ†“
5. Returns success โ†’ frontend redirects to login
```

### Create Task (with async notification)
```
1. User creates task (frontend)
โ†“
2. POST /tasks โ†’ API Gateway (validates JWT)
โ†“
3. API Gateway โ†’ Task Service
โ†“
4. Task Service:
- Saves task to task_db
- Publishes "task.created" job to BullMQ
โ†“
5. Queue Worker (background):
- Picks up job from Redis
- Calls Notification Service
โ†“
6. Notification Service:
- Saves notification to notification_db
- Sends email via Mailpit
```

---

## ๐Ÿงฐ Why This Stack?

| Technology | Reason |
|-----------|--------|
| **Nuxt 4** | SSR + Vue 3, production-ready, matches boilerplate |
| **NestJS** | Enterprise-grade, TypeScript-first, modular architecture |
| **PostgreSQL** | ACID compliance, production-grade, one DB per service |
| **Prisma** | Type-safe ORM, auto-migrations, excellent DX |
| **BullMQ** | Industry-standard Node.js job queue, Redis-backed |
| **Docker** | Consistent environments, easy orchestration |

---

## ๐ŸŽฏ What This Demonstrates

โœ… **Microservices expertise** โ€” Service decomposition, API Gateway, database per service
โœ… **Message-driven architecture** โ€” BullMQ job queues for async processing
โœ… **Modern stack mastery** โ€” Nuxt 4, NestJS, Prisma, PostgreSQL, Redis
โœ… **DevOps capabilities** โ€” Docker multi-container orchestration
โœ… **Enterprise patterns** โ€” JWT auth, rate limiting, structured logging
โœ… **Scalability** โ€” Each service can scale independently

---

## ๐Ÿ“ License

MIT License โ€” See [LICENSE](./LICENSE) for details.

---

## ๐Ÿ‘ค Author

**Faiz Khairi**
- GitHub: [@faizkhairi](https://github.com/faizkhairi)
- LinkedIn: [linkedin.com/in/faizkhairi](https://www.linkedin.com/in/faizkhairi/)
- Website: [faizkhairi.github.io](https://faizkhairi.github.io)

---

## โญ Support

If you find this project helpful, please give it a star! โญ

Built with โค๏ธ to showcase production-grade microservices architecture.