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

https://github.com/hassonor/microservices-jobber

microservices-jobber using: Node, TS, ES, Kibana,Postgresql,mysql,MongoDB, Cloudinary, RabbitMQ
https://github.com/hassonor/microservices-jobber

cloudinary elasticsearch hearbeat kibana microservices mongodb nodejs postgresql rabbitmq typescript

Last synced: 3 months ago
JSON representation

microservices-jobber using: Node, TS, ES, Kibana,Postgresql,mysql,MongoDB, Cloudinary, RabbitMQ

Awesome Lists containing this project

README

          

# πŸš€ Microservices Jobber Platform

![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![Node.js](https://img.shields.io/badge/node-%3E%3D20.x-brightgreen)
![TypeScript](https://img.shields.io/badge/typescript-%5E5.0.0-blue)
![Build](https://img.shields.io/badge/build-passing-success)

**A production-ready freelance marketplace built with microservices architecture**

[Features](#-features) β€’ [Quick Start](#-quick-start) β€’ [Architecture](#-architecture) β€’ [Documentation](#-documentation) β€’ [Contributing](#-contributing)

---

## πŸ“‹ Table of Contents

- [Overview](#-overview)
- [Features](#-features)
- [Tech Stack](#-tech-stack)
- [Architecture](#-architecture)
- [Quick Start](#-quick-start)
- [Project Structure](#-project-structure)
- [Services](#-services)
- [Development](#-development)
- [Testing](#-testing)
- [Deployment](#-deployment)
- [CI/CD](#-cicd)
- [Contributing](#-contributing)
- [License](#-license)

---

## 🌟 Overview

**Microservices Jobber** is a full-featured freelance marketplace platform demonstrating **production-grade microservices architecture**. Built with TypeScript, Node.js, and modern cloud-native technologies, this project serves as both a learning resource and a foundation for building scalable SaaS applications.

### Why This Project?

- βœ… **Production-Ready**: Real-world patterns, error handling, monitoring
- βœ… **Event-Driven**: RabbitMQ message queuing between services
- βœ… **Cloud-Native**: Docker, Kubernetes, horizontal scaling
- βœ… **Full Observability**: Elasticsearch, Kibana, Heartbeat monitoring
- βœ… **Educational**: Clear code, comprehensive documentation, best practices

---

## ✨ Features

### Core Functionality
- πŸ” **Authentication & Authorization**: JWT tokens, refresh tokens, 2FA support
- πŸ‘₯ **User Management**: Profiles, roles, permissions, email verification
- πŸ’Ό **Gig Management**: Create, browse, search, filter freelance services
- πŸ’¬ **Real-time Chat**: WebSocket-based messaging between users
- πŸ“¦ **Order Management**: Complete order lifecycle with payment integration
- ⭐ **Review System**: Ratings, reviews, reputation scores
- πŸ“§ **Notifications**: Email, in-app, push notifications
- πŸ” **Full-text Search**: Elasticsearch-powered gig and user search

### Technical Features
- 🎯 **API Gateway**: Centralized entry point with rate limiting
- πŸ”„ **Event-Driven Communication**: Async messaging with RabbitMQ
- πŸ’Ύ **Polyglot Persistence**: MongoDB, MySQL, PostgreSQL, Redis
- πŸ“Š **Monitoring**: Elasticsearch, Kibana, Heartbeat, APM
- πŸš€ **Horizontal Scaling**: Stateless services, Redis sessions
- 🐳 **Containerized**: Docker Compose for local, Kubernetes for production

---

## πŸ›  Tech Stack

### Backend Services (8 Microservices)
| Service | Technology | Database | Description |
|---------|-----------|----------|-------------|
| **Gateway** | Express.js, TypeScript | Redis | API Gateway with rate limiting |
| **Notification** | Express.js, TypeScript | MongoDB | Email and push notifications |
| **Auth** | Express.js, TypeScript | PostgreSQL | Authentication & authorization |
| **Users** | Express.js, TypeScript | MongoDB | User profiles and management |
| **Gig** | Express.js, TypeScript | MongoDB | Freelance service listings |
| **Chat** | Express.js, TypeScript | MongoDB | Real-time messaging |
| **Order** | Express.js, TypeScript | MySQL | Order processing & payments |
| **Review** | Express.js, TypeScript | PostgreSQL | Ratings and reviews |

### Infrastructure
- **Message Queue**: RabbitMQ
- **Cache**: Redis 7
- **Search**: Elasticsearch 8
- **Monitoring**: Kibana, Heartbeat
- **Containerization**: Docker, Docker Compose
- **Orchestration**: Kubernetes (production)

### Shared Libraries
- **@ohjobber/shared**: Common utilities, types, middlewares

---

## πŸ— Architecture

### High-Level Architecture Diagram

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Client Layer β”‚
β”‚ (Web App, Mobile App, Third-party) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ HTTPS
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ API Gateway β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚Rate Limit │─▢│Authentication│─▢│Request Routing β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β–Ό β–Ό β–Ό β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Auth β”‚ β”‚ User β”‚ β”‚ Gig β”‚ β”‚ Chat β”‚
β”‚ Service β”‚ β”‚ Service β”‚ β”‚ Service β”‚ β”‚ Service β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
β”‚ β”‚ β”‚ β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Order β”‚ β”‚ Review β”‚ β”‚ Notif β”‚ β”‚ Gateway β”‚
β”‚ Service β”‚ β”‚ Service β”‚ β”‚ Service β”‚ β”‚ API β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β–Ό β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ RabbitMQ β”‚ β”‚ Redis β”‚
β”‚ (Events) β”‚ β”‚ (Cache) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Data Layer (Polyglot) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ MongoDB β”‚ PostgreSQL β”‚
β”‚ MySQL β”‚ Elasticsearch β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Service Communication Patterns

1. **Synchronous**: HTTP/REST for request-response operations
2. **Asynchronous**: RabbitMQ events for fire-and-forget operations
3. **Caching**: Redis for sessions, rate limiting, frequently accessed data
4. **Search**: Elasticsearch for full-text search with denormalized data

---

## πŸš€ Quick Start

Get the entire platform running locally in **10 minutes**:

### Prerequisites

- **Node.js** >= 20.x
- **Docker** & **Docker Compose** >= 20.x
- **Git**

### Installation

```bash
# 1. Clone the repository
git clone https://github.com/hassonor/microservices-jobber.git
cd microservices-jobber

# 2. Start infrastructure services (takes 5-10 min for Elasticsearch)
cd volumes
docker-compose up -d redis mongodb mysql postgres rabbitmq elasticsearch

# 3. Create Kibana service token
docker exec -it bash
bin/elasticsearch-service-tokens create elastic/kibana jobber-kibana
# Copy the token and add to ELASTICSEARCH_SERVICEACCOUNT_TOKEN in docker-compose.yml

# 4. Start Kibana
docker-compose up -d kibana

# 5. Update heartbeat.yml with your IP address
# Replace in volumes/heartbeat.yml

# 6. Install dependencies for all services
npm install --workspaces

# 7. Start services (recommended order)
cd ../2-notification-service && npm run dev &
cd ../3-auth-service && npm run dev &
cd ../4-users-service && npm run dev &
cd ../5-gig-service && npm run dev &
cd ../6-chat-service && npm run dev &
cd ../7-order-service && npm run dev &
cd ../8-review-service && npm run dev &
cd ../1-gateway-service && npm run dev # Start gateway last
```

### Access Points

| Service | URL | Description |
|---------|-----|-------------|
| **API Gateway** | http://localhost:4000 | Main entry point |
| **Elasticsearch** | http://localhost:9200 | Search engine |
| **Kibana** | http://localhost:5601 | Monitoring dashboard |
| **RabbitMQ** | http://localhost:15672 | Message queue UI (guest/guest) |

---

## πŸ“ Project Structure

```
microservices-jobber/
β”œβ”€β”€ 1-gateway-service/ # API Gateway (port 4000)
β”‚ β”œβ”€β”€ src/
β”‚ β”‚ β”œβ”€β”€ controllers/ # Route handlers
β”‚ β”‚ β”œβ”€β”€ middleware/ # Auth, rate limiting, validation
β”‚ β”‚ β”œβ”€β”€ routes/ # API routes
β”‚ β”‚ └── server.ts # Express app setup
β”‚ β”œβ”€β”€ package.json
β”‚ └── tsconfig.json
β”‚
β”œβ”€β”€ 2-notification-service/ # Email & push notifications
β”‚ β”œβ”€β”€ src/
β”‚ β”‚ β”œβ”€β”€ queues/ # RabbitMQ consumers
β”‚ β”‚ β”œβ”€β”€ templates/ # Email templates
β”‚ β”‚ └── server.ts
β”‚ └── package.json
β”‚
β”œβ”€β”€ 3-auth-service/ # Authentication (port 4002)
β”‚ β”œβ”€β”€ src/
β”‚ β”‚ β”œβ”€β”€ controllers/ # Login, signup, refresh
β”‚ β”‚ β”œβ”€β”€ models/ # User model
β”‚ β”‚ β”œβ”€β”€ services/ # JWT, bcrypt logic
β”‚ β”‚ └── server.ts
β”‚ └── package.json
β”‚
β”œβ”€β”€ 4-users-service/ # User profiles (port 4003)
β”œβ”€β”€ 5-gig-service/ # Gig listings (port 4004)
β”œβ”€β”€ 6-chat-service/ # Messaging (port 4005)
β”œβ”€β”€ 7-order-service/ # Orders & payments (port 4006)
β”œβ”€β”€ 8-review-service/ # Ratings & reviews (port 4007)
β”‚
β”œβ”€β”€ volumes/ # Docker infrastructure
β”‚ β”œβ”€β”€ docker-compose.yaml # All infrastructure services
β”‚ └── heartbeat.yml # Elasticsearch monitoring
β”‚
β”œβ”€β”€ .cursorrules # AI coding assistant configuration
β”œβ”€β”€ .github/
β”‚ β”œβ”€β”€ dependabot.yml # Automated dependency updates
β”‚ └── workflows/ # CI/CD pipelines
└── README.md
```

---

## πŸ”§ Services

### 1. Gateway Service (Port 4000)
**Entry point for all client requests**

- Rate limiting (100 req/15min per IP)
- Authentication middleware
- Request validation
- Service routing
- CORS configuration

**Key Endpoints**:
```
POST /api/v1/auth/signup
POST /api/v1/auth/login
GET /api/v1/gigs/search
POST /api/v1/orders
```

### 2. Notification Service
**Async email and push notifications**

- Email templates (signup, order confirmation, etc.)
- SendGrid/Mailgun integration
- RabbitMQ consumer for notification events
- Notification history tracking

### 3. Auth Service (Port 4002)
**JWT-based authentication**

- User registration with email verification
- Login with refresh token rotation
- Password reset flow
- 2FA support (optional)

### 4. Users Service (Port 4003)
**User profile management**

- Profile CRUD operations
- Seller/buyer profiles
- Avatar upload (Cloudinary)
- Activity history

### 5. Gig Service (Port 4004)
**Freelance service listings**

- Create/update/delete gigs
- Full-text search (Elasticsearch)
- Category filtering
- Image uploads (Cloudinary)

### 6. Chat Service (Port 4005)
**Real-time messaging**

- WebSocket connections
- Message persistence (MongoDB)
- Conversation history
- Typing indicators

### 7. Order Service (Port 4006)
**Order processing & payments**

- Order lifecycle management
- Stripe/PayPal integration
- Order status updates via events
- Refund handling

### 8. Review Service (Port 4007)
**Ratings and reviews**

- Create/update reviews
- Seller rating calculation
- Review moderation
- Aggregate statistics

---

## πŸ’» Development

### Environment Setup

Each service requires a `.env` file:

```bash
# Example for auth-service/.env
NODE_ENV=development
PORT=4002
DATABASE_URL=postgresql://user:pass@localhost:5432/jobber_auth
JWT_SECRET=your-secret-key-change-in-production
JWT_EXPIRES_IN=1h
REFRESH_TOKEN_SECRET=your-refresh-secret
RABBITMQ_URL=amqp://localhost:5672
REDIS_URL=redis://localhost:6379
```

### Running Individual Services

```bash
# Development mode with hot reload
cd 3-auth-service
npm run dev

# Production mode
npm run build
npm start

# Lint & format
npm run lint
npm run lint:fix
```

### Code Quality

This project follows strict TypeScript and ESLint rules:

```bash
# Run linting
npm run lint

# Fix auto-fixable issues
npm run lint:fix

# Type checking
npm run type-check
```

### Shared Package

Common utilities are in `@ohjobber/shared`:

```typescript
import { BadRequestError, NotFoundError } from '@ohjobber/shared';
import { CustomResponse, IAuthPayload } from '@ohjobber/shared';
```

---

## πŸ§ͺ Testing

### Unit Tests

```bash
# Run tests for a service
cd 3-auth-service
npm test

# Watch mode
npm run test:watch

# Coverage report
npm run test:coverage
```

### Integration Tests

```bash
# Run integration tests (requires Docker)
npm run test:integration
```

### E2E Tests

```bash
# Start all services first
npm run dev:all

# Run E2E tests
npm run test:e2e
```

---

## 🚒 Deployment

### Docker Compose (Development)

```bash
# Start all services
docker-compose up -d

# View logs
docker-compose logs -f gateway

# Stop all services
docker-compose down
```

### Kubernetes (Production)

```bash
# Apply Kubernetes manifests
kubectl apply -f k8s/

# Check deployment status
kubectl get pods
kubectl get services

# Scale a service
kubectl scale deployment gig-service --replicas=3
```

### Environment Variables (Production)

Required secrets for production:

```bash
JWT_SECRET=
REFRESH_TOKEN_SECRET=
DATABASE_URL=
REDIS_URL=
RABBITMQ_URL=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=
STRIPE_SECRET_KEY=
SENDGRID_API_KEY=
```

---

## πŸ”„ CI/CD

### GitHub Actions

Automated workflows for:

- **Linting**: ESLint on every push
- **Testing**: Unit + integration tests
- **Security**: Dependabot for vulnerabilities
- **Build**: Docker image builds
- **Deploy**: Automatic deployment to staging on PR merge

### Jenkins (Alternative)

Jenkins pipeline configuration included in `Jenkinsfile`:

```groovy
pipeline {
stages {
stage('Test') { ... }
stage('Build') { ... }
stage('Deploy') { ... }
}
}
```

---

## 🀝 Contributing

We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

### Quick Contribution Guide

1. **Fork** the repository
2. **Create** a feature branch (`git checkout -b feature/amazing-feature`)
3. **Commit** your changes following [Conventional Commits](https://www.conventionalcommits.org/)
4. **Push** to the branch (`git push origin feature/amazing-feature`)
5. **Open** a Pull Request

### Code Standards

- Follow the existing `.cursorrules` configuration
- Write unit tests for new features
- Update documentation as needed
- Ensure all tests pass before submitting PR

---

## πŸ“„ License

This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.

---

## πŸ™ Acknowledgments

- Inspired by production freelance platforms like Upwork and Fiverr
- Built for educational purposes to demonstrate microservices architecture
- Special thanks to the open-source community for the amazing tools

---

## πŸ“ž Support

- **Issues**: [GitHub Issues](https://github.com/hassonor/microservices-jobber/issues)
- **Discussions**: [GitHub Discussions](https://github.com/hassonor/microservices-jobber/discussions)

---

**Made with ❀️ by [Or Hasson](https://github.com/hassonor)**

⭐ Star this repo if you find it helpful!