Skip to content

GoddeyUwamari/cloudbill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

51 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CloudBill - Multi-Tenant SaaS Billing Platform

Tests Docker Build codecov License Node TypeScript

Production-ready multi-tenant SaaS billing platform with microservices architecture, comprehensive testing, and enterprise observability.

⚑ Quick Stats:

  • πŸ“¦ 5 Microservices + API Gateway
  • βœ… 213 Tests (100% passing)
  • πŸ“Š Prometheus + Grafana Monitoring
  • 🐳 Docker + Kubernetes Ready
  • πŸ”„ CI/CD with GitHub Actions

πŸš€ Features

Multi-Tenant Architecture

  • Row-Level Security (RLS) for data isolation
  • Tenant-aware logging and metrics
  • Scalable subscription management

Microservices

  • Auth Service - JWT authentication, session management (Redis)
  • Billing Service - Subscriptions, invoices, usage-based metering
  • Payment Service - Stripe integration, payment methods, refunds
  • Notification Service - Email (SMTP), SMS (Twilio), webhooks
  • API Gateway - Request routing, rate limiting, CORS

Enterprise Observability

  • Prometheus - Metrics collection from all services
  • Grafana - 6 dashboards, 18 production alerts
  • Winston - Structured logging with daily rotation
  • Real-time monitoring of business and system metrics

DevOps & Infrastructure

  • Docker - Containerized services with multi-stage builds
  • Kubernetes - Production-ready manifests with Kustomize
  • CI/CD - Automated testing and Docker builds (GitHub Actions)
  • Terraform - Infrastructure as Code

πŸ›  Tech Stack

Backend:

  • Node.js 18+ with TypeScript 5.x
  • Express.js for REST APIs
  • PostgreSQL 14 with Row-Level Security
  • Redis 7 for sessions and caching

Testing:

  • Jest with 213 automated tests
  • Supertest for integration testing
  • Mock implementations for external services

Monitoring:

  • Prometheus for metrics
  • Grafana for visualization
  • Winston for structured logging

Infrastructure:

  • Docker & Docker Compose
  • Kubernetes with Kustomize
  • GitHub Actions for CI/CD
  • Terraform for cloud provisioning

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • Docker & Docker Compose
  • PostgreSQL 14+
  • Redis 7+

Local Development

# Clone the repository
git clone https://github.com/GoddeyUwamari/cloudbill.git
cd cloudbill

# Install dependencies
npm install

# Start infrastructure (PostgreSQL + Redis)
docker-compose up -d postgres redis

# Run database migrations
npm run db:migrate

# Start all services
docker-compose up -d

# Verify all services are healthy
docker-compose ps

# Run tests
npm test

Access Services

Demo Credentials

Email: admin@democompany.com
Password: Admin123!
Tenant ID: 00000000-0000-0000-0000-000000000001

πŸ“Š Monitoring

Grafana Dashboards

Access Grafana at http://localhost:3000 (admin/admin)

Available Dashboards:

  1. System Overview - Cross-service health and performance
  2. API Gateway - Traffic, latency, error rates
  3. Auth Service - Login metrics, token generation
  4. Billing Service - Subscriptions, invoices, usage
  5. Payment Service - Transaction volumes, success rates
  6. Notification Service - Email/SMS/webhook delivery

Prometheus Metrics

All services expose metrics at /metrics endpoint:

  • HTTP request metrics (count, duration, active connections)
  • Database query performance
  • Redis operation latency
  • Business metrics (subscriptions, payments, notifications)

Generate Test Traffic

# Test authentication and generate metrics
for i in {1..50}; do
  curl -X POST http://localhost:8080/api/auth/login \
    -H "Content-Type: application/json" \
    -H "X-Tenant-ID: 00000000-0000-0000-0000-000000000001" \
    -d '{"email":"admin@democompany.com","password":"Admin123!"}'
  sleep 0.5
done

Watch metrics populate in Grafana in real-time!


πŸ”§ Architecture

CloudBill Platform
β”œβ”€ API Gateway (Port 8080)
β”‚  β”œβ”€ Request routing & proxying
β”‚  β”œβ”€ Rate limiting (Redis-based)
β”‚  β”œβ”€ CORS & security headers
β”‚  └─ Health check aggregation
β”‚
β”œβ”€ Auth Service (Port 3001)
β”‚  β”œβ”€ JWT authentication
β”‚  β”œβ”€ Session management (Redis)
β”‚  β”œβ”€ User registration & login
β”‚  └─ Password reset flows
β”‚
β”œβ”€ Billing Service (Port 3002)
β”‚  β”œβ”€ Subscription management
β”‚  β”œβ”€ Invoice generation
β”‚  β”œβ”€ Usage-based metering
β”‚  └─ Multi-tier pricing plans
β”‚
β”œβ”€ Payment Service (Port 3003)
β”‚  β”œβ”€ Stripe integration
β”‚  β”œβ”€ Payment method management
β”‚  β”œβ”€ Refund processing
β”‚  └─ Webhook handling
β”‚
β”œβ”€ Notification Service (Port 3004)
β”‚  β”œβ”€ Email (SMTP/Nodemailer)
β”‚  β”œβ”€ SMS (Twilio)
β”‚  β”œβ”€ Webhook delivery
β”‚  └─ Template management
β”‚
β”œβ”€ PostgreSQL (Port 5433)
β”‚  β”œβ”€ Multi-tenant with RLS
β”‚  β”œβ”€ Production & test databases
β”‚  └─ Automated migrations
β”‚
β”œβ”€ Redis (Port 6380)
β”‚  β”œβ”€ Session storage
β”‚  β”œβ”€ Rate limiting
β”‚  └─ Caching layer
β”‚
└─ Monitoring Stack
   β”œβ”€ Prometheus (Port 9090)
   β”œβ”€ Grafana (Port 3000)
   └─ 18 production alerts

πŸ§ͺ Testing

Run All Tests

# All 213 tests
npm test

# With coverage report
npm run test:coverage

# Specific service
cd services/auth-service && npm test
cd services/billing-service && npm test
cd services/payment-service && npm test
cd services/notification-service && npm test

Test Coverage

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Service                β”‚ Tests β”‚ Passing β”‚ Coverage β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Auth Service           β”‚  34   β”‚   34    β”‚   100%   β”‚
β”‚ Billing Service        β”‚  80   β”‚   80    β”‚   100%   β”‚
β”‚ Payment Service        β”‚  69   β”‚   69    β”‚   100%   β”‚
β”‚ Notification Service   β”‚  30   β”‚   30    β”‚   100%   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ TOTAL                  β”‚ 213   β”‚  213    β”‚   100%   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🚒 Deployment

Docker Compose (Development)

# Start all services
docker-compose up -d

# Check service health
docker-compose ps

# View logs
docker-compose logs -f api-gateway

# Stop all services
docker-compose down

Kubernetes (Production)

# Deploy to development environment
kubectl apply -k infrastructure/kubernetes/overlays/dev/

# Deploy to production
kubectl apply -k infrastructure/kubernetes/overlays/production/

# Verify deployment
kubectl get pods -n cloudbill
kubectl get services -n cloudbill

# Access services (port-forward)
kubectl port-forward svc/api-gateway 8080:8080 -n cloudbill

πŸ“‘ API Documentation

Authentication

# Login
POST http://localhost:8080/api/auth/login
Content-Type: application/json
X-Tenant-ID: 00000000-0000-0000-0000-000000000001

{
  "email": "admin@democompany.com",
  "password": "Admin123!"
}

# Response
{
  "success": true,
  "data": {
    "user": { "id": "...", "email": "...", "role": "SUPER_ADMIN" },
    "accessToken": "eyJhbGc...",
    "expiresIn": 900
  }
}

Subscriptions

# Create subscription
POST http://localhost:8080/api/billing/subscriptions
Authorization: Bearer <token>
X-Tenant-ID: <tenant-id>

{
  "planId": "professional",
  "paymentMethodId": "pm_..."
}

Payments

# Create payment
POST http://localhost:8080/api/payments/create
Authorization: Bearer <token>
X-Tenant-ID: <tenant-id>

{
  "amount": 2999,
  "currency": "usd",
  "paymentMethodId": "pm_..."
}

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development Workflow

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Standards

  • TypeScript strict mode enabled
  • ESLint for code quality
  • Prettier for formatting
  • 100% test coverage for new features
  • Meaningful commit messages

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

Goddey Uwamari


πŸ™ Acknowledgments

Built with:


⭐ If you find this project useful, please consider giving it a star!

About

Production-ready SaaS billing platform: 5 microservices, 213 tests, Prometheus monitoring, Kubernetes deployment, CI/CD pipeline

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors