Skip to content

A decentralized utility payment platform (Pay electricity & water bills using stellar)

Notifications You must be signed in to change notification settings

nathydre21/nepa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

128 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NEPA - Decentralized Utility Payment Platform

A decentralized utility payment platform enabling users to pay electricity & water bills using Stellar blockchain.

πŸ—οΈ Architecture

This project implements a Database Per Service microservices architecture, ensuring:

  • Data isolation between services
  • Independent scaling capabilities
  • Technology diversity support
  • Autonomous deployment

Microservices

  1. User Service - Authentication, profiles, sessions
  2. Notification Service - Email, SMS, push notifications
  3. Document Service - File storage (S3/IPFS)
  4. Utility Service - Utility provider management
  5. Payment Service - Payment processing via Stellar
  6. Billing Service - Bill management and coupons
  7. Analytics Service - Reporting and metrics
  8. Webhook Service - Event webhooks

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • Docker & Docker Compose
  • PostgreSQL client tools
  • Stellar account (testnet)

Setup

  1. Clone and install dependencies
git clone <repository-url>
cd nepa
npm install
  1. Start database containers
npm run db:docker-up
  1. Configure environment
cp .env.example .env
# Update database URLs and other configurations
  1. Generate Prisma clients
npm run db:generate-all
  1. Run migrations
npm run db:migrate-all
  1. Start the application
npm run dev

πŸ“Š Database Management

Available Commands

# Setup all databases
npm run db:setup

# Generate all Prisma clients
npm run db:generate-all

# Run all migrations
npm run db:migrate-all

# Backup all databases
npm run db:backup

# Health check
npm run db:health-check

# Monitor connection pools
npm run db:monitor-pools

# Docker commands
npm run db:docker-up      # Start containers
npm run db:docker-down    # Stop containers
npm run db:docker-logs    # View logs

Database Services

Each service has its own PostgreSQL database:

Service Database Port
User nepa_user_service 5432
Notification nepa_notification_service 5433
Document nepa_document_service 5434
Utility nepa_utility_service 5435
Payment nepa_payment_service 5436
Billing nepa_billing_service 5437
Analytics nepa_analytics_service 5438
Webhook nepa_webhook_service 5439

πŸ”„ Event-Driven Architecture

Services communicate through domain events:

import EventBus from './databases/event-patterns/EventBus';
import MessageBroker from './databases/event-patterns/MessageBroker';
import { createPaymentSuccessEvent } from './databases/event-patterns/events';

// Publish event (in-memory)
EventBus.publish(createPaymentSuccessEvent(paymentId, billId, userId, amount));

// Publish event (persistent queue)
await MessageBroker.connect();
await MessageBroker.publish(event);

// Subscribe to event
EventBus.subscribe('payment.success', async (event) => {
  // Handle event
});

Start Message Broker

npm run messaging:start  # Start RabbitMQ & Redis
npm run test:events      # Test event system

RabbitMQ Management

πŸ” Saga Pattern

Distributed transactions use the Saga pattern:

import PaymentSaga from './databases/saga/PaymentSaga';

const result = await PaymentSaga.executePayment({
  userId,
  billId,
  amount,
  method: 'STELLAR',
  transactionId
});

πŸ“– Documentation

πŸ§ͺ Testing

npm test                    # Run all tests
npm run test:unit          # Unit tests
npm run test:integration   # Integration tests
npm run test:e2e           # End-to-end tests
npm run db:test-saga       # Test saga implementation

πŸ“ˆ Monitoring

# Check database health
npm run db:health-check

# Monitor connection pools
npm run db:monitor-pools 300000 10000  # 5 min duration, 10s interval

πŸ”§ Development

npm run dev          # Start development server
npm run build        # Build for production
npm run lint         # Lint code
npm run type-check   # TypeScript type checking

πŸ“Š Observability

Start Monitoring Stack

# Start all observability services
npm run observability:start

# Test observability
npm run observability:test

# View logs
npm run observability:logs

Access Dashboards

Features

  • Structured Logging: JSON logs with correlation IDs
  • Distributed Tracing: OpenTelemetry + Jaeger
  • Metrics Collection: Prometheus + Grafana
  • Log Aggregation: Loki + Promtail
  • Alerting: Alertmanager with Slack/PagerDuty
  • SLA Monitoring: Automated SLA tracking
  • Anomaly Detection: ML-based anomaly detection

See Observability Documentation for details.

🌟 Features

  • βœ… Microservices architecture with database per service
  • βœ… Event-driven communication between services
  • βœ… Saga pattern for distributed transactions
  • βœ… Stellar blockchain integration for payments
  • βœ… Multi-utility support (electricity, water)
  • βœ… Webhook system for external integrations
  • βœ… Document storage (S3/IPFS)
  • βœ… Comprehensive analytics and reporting
  • βœ… Real-time notifications
  • βœ… Automated backups and disaster recovery
  • βœ… Distributed monitoring and observability
  • βœ… SLA tracking and anomaly detection
  • βœ… Event-driven architecture with RabbitMQ
  • βœ… Asynchronous event processing with retry logic
  • βœ… Event sourcing for audit trails

πŸ“ License

MIT

About

A decentralized utility payment platform (Pay electricity & water bills using stellar)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 15