PayNext follows a microservices architecture pattern with cloud-native design principles, providing scalability, resilience, and maintainability.
- High-Level Architecture
- System Components
- Service Communication
- Data Flow
- Security Architecture
- Deployment Architecture
┌─────────────────────────────────────────────────────────────────┐
│ Client Layer │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Web Dashboard│ │ Mobile App │ │ Third-Party │ │
│ │ (React 18) │ │ (Next.js) │ │ APIs │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
└─────────┼──────────────────┼──────────────────┼────────────────┘
│ │ │
└──────────────────┼──────────────────┘
│
┌────────────────────────────┼───────────────────────────────────┐
│ API Gateway Layer │
│ ┌──────────────────┴──────────────────┐ │
│ │ API Gateway (Spring Cloud) │ │
│ │ - Routing │ │
│ │ - Authentication │ │
│ │ - Rate Limiting │ │
│ └──────────────────┬──────────────────┘ │
└────────────────────────────┼───────────────────────────────────┘
│
┌────────────────────────────┼───────────────────────────────────┐
│ Service Discovery Layer │
│ ┌─────────────────────────────┐ │
│ │ Eureka Server (Netflix) │ │
│ │ - Service Registration │ │
│ │ - Health Monitoring │ │
│ └─────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
┌────────────────────────────┼───────────────────────────────────┐
│ Microservices Layer │
│ ┌───────────┐ ┌───────────┐ ┌──────────┐ ┌─────────────┐ │
│ │ User │ │ Payment │ │Transaction│ │Notification │ │
│ │ Service │ │ Service │ │ Service │ │ Service │ │
│ └─────┬─────┘ └─────┬─────┘ └─────┬────┘ └──────┬──────┘ │
│ │ │ │ │ │
└────────┼──────────────┼──────────────┼───────────────┼──────────┘
│ │ │ │
┌────────┼──────────────┼──────────────┼───────────────┼──────────┐
│ │ ML Services Layer (Python/FastAPI) │ │
│ ┌─────┴──┐ ┌────────┴──┐ ┌────────┴────┐ ┌──────┴──────┐ │
│ │ Fraud │ │ Credit │ │ Churn │ │Categorization│ │
│ │Detection│ │ Scoring │ │ Prediction │ │ Service │ │
│ └────────┘ └───────────┘ └─────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│ │ │ │
┌────────┼──────────────┼──────────────┼───────────────┼──────────┐
│ Data & Infrastructure Layer │
│ ┌───────────┐ ┌──────────┐ ┌──────────┐ ┌──────────────┐ │
│ │ MySQL │ │ Redis │ │ RabbitMQ │ │ Monitoring │ │
│ │ (Primary) │ │ (Cache) │ │(Messaging)│ │(Prometheus) │ │
│ └───────────┘ └──────────┘ └──────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────────┘
Purpose: Centralized entry point for all client requests
File: backend/api-gateway/
Responsibilities:
- Request routing to microservices
- JWT token validation
- Rate limiting and throttling
- Circuit breaking
- Request/response logging
Technology: Spring Cloud Gateway (Reactive)
Purpose: Service discovery and health monitoring
File: backend/eureka-server/
Responsibilities:
- Dynamic service registration
- Service instance health checks
- Load balancing coordination
- Service metadata management
Technology: Netflix Eureka
Purpose: User account and authentication management
File: backend/user-service/
Responsibilities:
- User registration and profile management
- Authentication (JWT generation)
- Role-based access control (RBAC)
- Password management and security
Database: MySQL (user_db)
Key Entities: User, Role, Permission
Purpose: Core payment processing
File: backend/payment-service/
Responsibilities:
- Payment transaction processing
- Multiple payment method support
- Multi-currency handling
- Payment gateway integration
- Transaction validation
Database: MySQL (payment_db)
Cache: Redis
Key Entities: Payment, PaymentMethod, Currency
Purpose: Transaction history and reconciliation
File: backend/transaction-service/ (planned/integrated with payment-service)
Responsibilities:
- Transaction recording and tracking
- Refund processing
- Chargeback handling
- Financial reconciliation
- Audit trail
Purpose: Multi-channel notifications
File: backend/notification-service/
Responsibilities:
- Email notifications (SMTP)
- SMS notifications
- Push notifications
- Notification templates
- Delivery tracking
Database: MySQL (notification_db)
Message Queue: RabbitMQ/Kafka
Purpose: AI-powered fraud prevention
File: ml_services/fraud/
Responsibilities:
- Real-time fraud scoring
- Anomaly detection
- Risk assessment
- Model training and updating
Technology: Python, FastAPI, scikit-learn
Models: Random Forest, Isolation Forest, Autoencoder
Services communicate via RESTful APIs through the API Gateway:
Client → API Gateway → Service Registry → Target Service
Example Flow:
- Client sends request to API Gateway
- Gateway validates JWT token
- Gateway discovers service location from Eureka
- Gateway routes request to service
- Service processes and returns response
Event-driven communication for non-blocking operations:
Service → RabbitMQ/Kafka → Subscribed Services
Use Cases:
- Payment confirmation emails
- Fraud alert notifications
- Transaction logs
- Analytics events
sequenceDiagram
participant Client
participant Gateway
participant UserService
participant PaymentService
participant FraudService
participant NotificationService
Client->>Gateway: POST /api/payments
Gateway->>Gateway: Validate JWT
Gateway->>UserService: Verify user
UserService-->>Gateway: User valid
Gateway->>FraudService: Check fraud
FraudService-->>Gateway: Risk score
Gateway->>PaymentService: Process payment
PaymentService->>PaymentService: Save transaction
PaymentService-->>Gateway: Payment result
Gateway->>NotificationService: Send confirmation
Gateway-->>Client: Payment response
1. User → API Gateway: POST /users/login {username, password}
2. Gateway → User Service: Forward credentials
3. User Service → Database: Validate credentials
4. User Service → JWT Util: Generate token
5. User Service → Gateway: Return JWT token
6. Gateway → User: Return token
1. Payment Service: Receive payment request
2. Payment Service → Fraud Service: Send transaction data
3. Fraud Service → ML Model: Predict fraud probability
4. ML Model → Fraud Service: Return risk score
5. Fraud Service → Payment Service: Fraud assessment
6. Payment Service: Approve/Decline based on score
JWT-Based Authentication:
- Stateless token-based auth
- 1-hour token expiry
- Refresh token support
- Token stored in HTTP-only cookies
RBAC Model:
User → Role → Permissions
Roles: USER, MERCHANT, ADMIN
Encryption:
- TLS 1.3 for data in transit
- AES-256 for sensitive data at rest
- Payment data tokenization
Compliance:
- PCI DSS Level 1
- GDPR compliant
- SOC 2 Type II (planned)
services:
- eureka-server
- api-gateway
- user-service
- payment-service
- notification-service
- mysql
- redis
- rabbitmqNamespace: paynext
├── Deployments
│ ├── eureka-server (replicas: 1)
│ ├── api-gateway (replicas: 3)
│ ├── user-service (replicas: 2)
│ ├── payment-service (replicas: 3)
│ └── notification-service (replicas: 2)
├── Services (ClusterIP, LoadBalancer)
├── Ingress (HTTPS)
├── ConfigMaps & Secrets
└── Persistent Volumes (MySQL, Redis)
- VPC with public/private subnets
- EKS cluster for microservices
- RDS MySQL (Multi-AZ)
- ElastiCache Redis
- Application Load Balancer
- Route53 DNS
- CloudWatch monitoring
- S3 for backups
| Module | Primary Files | Dependencies |
|---|---|---|
| API Gateway | backend/api-gateway/src/ |
Eureka, JWT |
| Eureka Server | backend/eureka-server/src/ |
None |
| User Service | backend/user-service/src/ |
MySQL, Eureka, JWT |
| Payment Service | backend/payment-service/src/ |
MySQL, Redis, Kafka |
| Notification Service | backend/notification-service/src/ |
MySQL, RabbitMQ |
| Fraud Detection | ml_services/fraud/ |
Python, FastAPI |
| Common Module | backend/common-module/src/ |
Shared utilities |
- Services run as multiple replicas
- Load balanced by Kubernetes
- Stateless design enables scaling
- Redis for frequently accessed data
- Cache-aside pattern
- TTL-based expiration
- Connection pooling (HikariCP)
- Read replicas for heavy queries
- Indexed columns for performance
- Request count/latency
- Error rates
- Database connection pool
- JVM metrics
- Centralized log aggregation
- Structured logging (JSON)
- Correlation IDs for tracing
- Distributed request tracing
- Performance bottleneck identification
- Dependency visualization
- API Reference - API endpoints
- Configuration - Service configuration
- Kubernetes Deployment - Deploy guide