Skip to content

Life-Pill/mobile-ms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

65 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LifePill Microservices Architecture

API Gateway Service Registry User Auth Config Server Patient Customer Service

πŸ—οΈ Production-Grade Microservices Platform

This repository contains a production-grade microservices architecture for the LifePill Pharmacy Management System. Built with Spring Cloud ecosystem, it follows industry best practices including Service Discovery, Centralized Configuration, API Gateway pattern, Circuit Breaker, Distributed Tracing, and comprehensive monitoring.


πŸ“ Complete System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                    LIFEPILL MICROSERVICES ARCHITECTURE                                            β”‚
β”‚                                         Production Environment                                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

                                              EXTERNAL CLIENTS
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚   Mobile App    β”‚    β”‚    Web App      β”‚    β”‚   POS System    β”‚    β”‚   Admin Panel   β”‚
    β”‚   (Flutter)     β”‚    β”‚    (React)      β”‚    β”‚    (Desktop)    β”‚    β”‚    (React)      β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚                      β”‚                      β”‚                      β”‚
             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                               β”‚
                                               β”‚ HTTPS (Port 9191)
                                               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                         πŸšͺ API GATEWAY (Spring Cloud Gateway)                                     β”‚
β”‚                                                   Port: 9191                                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚  β”‚  Rate Limiting β”‚ β”‚ Circuit Breakerβ”‚ β”‚  Load Balancer β”‚ β”‚  CORS Handler  β”‚ β”‚ Request Router β”‚                  β”‚
β”‚  β”‚    (Redis)     β”‚ β”‚  (Resilience4j)β”‚ β”‚   (Ribbon)     β”‚ β”‚                β”‚ β”‚                β”‚                  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                               β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚                          β”‚                          β”‚
                    β–Ό                          β–Ό                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  πŸ” SERVICE REGISTRY        β”‚  β”‚  βš™οΈ CONFIG SERVER            β”‚  β”‚  πŸ” DISTRIBUTED TRACING     β”‚
β”‚     (Netflix Eureka)        β”‚  β”‚     (Spring Cloud Config)   β”‚  β”‚     (Zipkin)                β”‚
β”‚     Port: 8761              β”‚  β”‚     Port: 8888              β”‚  β”‚     Port: 9411              β”‚
β”‚                             β”‚  β”‚                             β”‚  β”‚                             β”‚
β”‚  β€’ Service Registration     β”‚  β”‚  β€’ Centralized Config       β”‚  β”‚  β€’ Request Tracing          β”‚
β”‚  β€’ Health Monitoring        β”‚  β”‚  β€’ Environment Profiles     β”‚  β”‚  β€’ Latency Analysis         β”‚
β”‚  β€’ Load Balancing Info      β”‚  β”‚  β€’ Runtime Refresh          β”‚  β”‚  β€’ Dependency Mapping       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β–²                          β–²                          β–²
                    β”‚    Register & Heartbeat  β”‚    Pull Configuration    β”‚    Send Traces
                    β”‚                          β”‚                          β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                         🏒 BUSINESS MICROSERVICES LAYER                                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                                                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚
β”‚  β”‚ πŸ‘€ USER AUTH        β”‚  β”‚ πŸ₯ PATIENT CUSTOMER β”‚  β”‚ πŸͺ BRANCH SERVICE   β”‚  β”‚ πŸ“¦ INVENTORY        β”‚              β”‚
β”‚  β”‚    SERVICE          β”‚  β”‚    SERVICE          β”‚  β”‚                     β”‚  β”‚    SERVICE          β”‚              β”‚
β”‚  β”‚    Port: 8080       β”‚  β”‚    Port: 8070       β”‚  β”‚    Port: 8081       β”‚  β”‚    Port: 8082       β”‚              β”‚
β”‚  β”‚                     β”‚  β”‚                     β”‚  β”‚                     β”‚  β”‚                     β”‚              β”‚
β”‚  β”‚ β€’ Mobile Auth       β”‚  β”‚ β€’ Patient Records   β”‚  β”‚ β€’ Branch Management β”‚  β”‚ β€’ Stock Management  β”‚              β”‚
β”‚  β”‚ β€’ JWT Tokens        β”‚  β”‚ β€’ Prescriptions     β”‚  β”‚ β€’ Location Data     β”‚  β”‚ β€’ Product Catalog   β”‚              β”‚
β”‚  β”‚ β€’ Email OTP         β”‚  β”‚ β€’ Stripe Payments   β”‚  β”‚ β€’ Operating Hours   β”‚  β”‚ β€’ Alerts & Reports  β”‚              β”‚
β”‚  β”‚ β€’ Password Reset    β”‚  β”‚ β€’ Customer Profile  β”‚  β”‚                     β”‚  β”‚                     β”‚              β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β”‚
β”‚             β”‚                        β”‚                        β”‚                        β”‚                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                       β”‚
β”‚  β”‚ πŸͺͺ IDENTITY         β”‚  β”‚ πŸ›’ ORDER SERVICE    β”‚  β”‚                     β”‚                                       β”‚
β”‚  β”‚    SERVICE          β”‚  β”‚    (POS System)     β”‚  β”‚   Future Services   β”‚                                       β”‚
β”‚  β”‚    Port: 8085       β”‚  β”‚    Port: 8086       β”‚  β”‚                     β”‚                                       β”‚
β”‚  β”‚                     β”‚  β”‚                     β”‚  β”‚ β€’ Notification      β”‚                                       β”‚
β”‚  β”‚ β€’ Employee Auth     β”‚  β”‚ β€’ Order Processing  β”‚  β”‚ β€’ Analytics         β”‚                                       β”‚
β”‚  β”‚ β€’ PIN Authenticationβ”‚  β”‚ β€’ Transactions      β”‚  β”‚ β€’ Reporting         β”‚                                       β”‚
β”‚  β”‚ β€’ Session Caching   β”‚  β”‚ β€’ Receipt Gen       β”‚  β”‚                     β”‚                                       β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                       β”‚
β”‚             β”‚                        β”‚                                                                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚                        β”‚
              β–Ό                        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                           πŸ’Ύ DATA LAYER                                                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                                                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                       β”‚
β”‚  β”‚ 🐘 PostgreSQL       β”‚  β”‚ πŸƒ MongoDB          β”‚  β”‚ πŸ”΄ Redis            β”‚                                       β”‚
β”‚  β”‚    Port: 5432       β”‚  β”‚    Port: 27017      β”‚  β”‚    Port: 6379       β”‚                                       β”‚
β”‚  β”‚                     β”‚  β”‚                     β”‚  β”‚                     β”‚                                       β”‚
β”‚  β”‚ DATABASES:          β”‚  β”‚ COLLECTIONS:        β”‚  β”‚ USAGE:              β”‚                                       β”‚
β”‚  β”‚ β€’ mobile_user_auth  β”‚  β”‚ β€’ lifepill_customer β”‚  β”‚ β€’ Session Cache     β”‚                                       β”‚
β”‚  β”‚ β€’ identity_service  β”‚  β”‚ β€’ prescriptions     β”‚  β”‚ β€’ Rate Limiting     β”‚                                       β”‚
β”‚  β”‚ β€’ branch_service    β”‚  β”‚ β€’ medical_records   β”‚  β”‚ β€’ Token Blacklist   β”‚                                       β”‚
β”‚  β”‚ β€’ inventory_service β”‚  β”‚                     β”‚  β”‚                     β”‚                                       β”‚
β”‚  β”‚ β€’ order_service     β”‚  β”‚                     β”‚  β”‚                     β”‚                                       β”‚
β”‚  β”‚ β€’ customer_service  β”‚  β”‚                     β”‚  β”‚                     β”‚                                       β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                       β”‚
β”‚                                                                                                                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                         πŸ“Š OBSERVABILITY STACK                                                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                                                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚
β”‚  β”‚ πŸ“ˆ Prometheus       β”‚  β”‚ πŸ“Š Grafana          β”‚  β”‚ πŸ” Zipkin           β”‚  β”‚ πŸ“€ Exporters        β”‚              β”‚
β”‚  β”‚    Port: 9090       β”‚  β”‚    Port: 3001       β”‚  β”‚    Port: 9411       β”‚  β”‚                     β”‚              β”‚
β”‚  β”‚                     β”‚  β”‚                     β”‚  β”‚                     β”‚  β”‚ β€’ PostgreSQL :9187  β”‚              β”‚
β”‚  β”‚ β€’ Metrics Scraping  β”‚  β”‚ β€’ Dashboards        β”‚  β”‚ β€’ Trace Collection  β”‚  β”‚ β€’ Redis :9121       β”‚              β”‚
β”‚  β”‚ β€’ Alert Rules       β”‚  β”‚ β€’ Visualization     β”‚  β”‚ β€’ Service Map       β”‚  β”‚ β€’ MongoDB :9216     β”‚              β”‚
β”‚  β”‚ β€’ Time Series DB    β”‚  β”‚ β€’ Alerting          β”‚  β”‚ β€’ Latency Analysis  β”‚  β”‚                     β”‚              β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β”‚
β”‚                                                                                                                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”„ Request Flow - How a Request Reaches a Service

Complete Request Journey

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                              REQUEST FLOW: Client β†’ Service β†’ Response                                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

 CLIENT                    API GATEWAY                SERVICE REGISTRY              TARGET SERVICE
    β”‚                          β”‚                            β”‚                            β”‚
    β”‚  1. HTTP Request         β”‚                            β”‚                            β”‚
    β”‚  GET /api/user-auth/...  β”‚                            β”‚                            β”‚
    │─────────────────────────▢│                            β”‚                            β”‚
    β”‚                          β”‚                            β”‚                            β”‚
    β”‚                          β”‚  2. Rate Limit Check       β”‚                            β”‚
    β”‚                          β”‚  (Redis)                   β”‚                            β”‚
    β”‚                          │─────────┐                  β”‚                            β”‚
    β”‚                          β”‚         β”‚ Check            β”‚                            β”‚
    β”‚                          β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Quota            β”‚                            β”‚
    β”‚                          β”‚                            β”‚                            β”‚
    β”‚                          β”‚  3. Lookup Service         β”‚                            β”‚
    β”‚                          β”‚  Location                  β”‚                            β”‚
    β”‚                          │───────────────────────────▢│                            β”‚
    β”‚                          β”‚                            β”‚                            β”‚
    β”‚                          β”‚  4. Return Healthy         β”‚                            β”‚
    β”‚                          β”‚  Instance List             β”‚                            β”‚
    β”‚                          │◀───────────────────────────│                            β”‚
    β”‚                          β”‚                            β”‚                            β”‚
    β”‚                          β”‚  5. Load Balance &         β”‚                            β”‚
    β”‚                          β”‚  Forward Request           β”‚                            β”‚
    β”‚                          │───────────────────────────────────────────────────────▢│
    β”‚                          β”‚                            β”‚                            β”‚
    β”‚                          β”‚                            β”‚   6. Process Request       β”‚
    β”‚                          β”‚                            β”‚   - Validate JWT           β”‚
    β”‚                          β”‚                            β”‚   - Business Logic         β”‚
    β”‚                          β”‚                            β”‚   - Database Query         β”‚
    β”‚                          β”‚                            β”‚                            β”‚
    β”‚                          β”‚  7. Service Response       β”‚                            β”‚
    β”‚                          │◀───────────────────────────────────────────────────────│
    β”‚                          β”‚                            β”‚                            β”‚
    β”‚                          β”‚  8. Circuit Breaker        β”‚                            β”‚
    β”‚                          β”‚  Health Update             β”‚                            β”‚
    β”‚                          │─────────┐                  β”‚                            β”‚
    β”‚                          β”‚         β”‚ Record           β”‚                            β”‚
    β”‚                          β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Metrics          β”‚                            β”‚
    β”‚                          β”‚                            β”‚                            β”‚
    β”‚  9. HTTP Response        β”‚                            β”‚                            β”‚
    │◀─────────────────────────│                            β”‚                            β”‚
    β”‚                          β”‚                            β”‚                            β”‚

PARALLEL: Zipkin Trace Propagation ─────────────────────────────────────────────────────▢ Zipkin Server

Step-by-Step Request Processing

Step Component Action Details
1 Client Send Request HTTP/HTTPS request to http://34.59.6.212:9191/api/{service}/{endpoint}
2 API Gateway Rate Limiting Check Redis for request quota (prevents DDoS)
3 API Gateway Service Discovery Query Eureka for available service instances
4 Eureka Return Instances Provide list of healthy service instances
5 API Gateway Load Balancing Select instance using Round Robin / Weighted algorithm
6 Target Service Process Request JWT validation β†’ Business logic β†’ Database query
7 Target Service Return Response Send response back through gateway
8 API Gateway Circuit Breaker Update health metrics, trip breaker if errors exceed threshold
9 Client Receive Response Final HTTP response with data

πŸ›£οΈ API Gateway Routing Configuration

Route Mapping Table

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                    API GATEWAY ROUTE CONFIGURATION                                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                                          β”‚
β”‚  INCOMING REQUEST                          ROUTED TO                          SERVICE                   β”‚
β”‚  ─────────────────                         ─────────                          ───────                   β”‚
β”‚                                                                                                          β”‚
β”‚  /api/user-auth/**        ───────────────▢ lb://USER-AUTH          ───────▢  User Auth (8080)          β”‚
β”‚  /api/identity/**         ───────────────▢ lb://IDENTITY-SERVICE   ───────▢  Identity (8085)           β”‚
β”‚  /api/customer/**         ───────────────▢ lb://PATIENT-CUSTOMER   ───────▢  Patient Customer (8070)   β”‚
β”‚  /api/branch/**           ───────────────▢ lb://BRANCH-SERVICE     ───────▢  Branch (8081)             β”‚
β”‚  /api/inventory/**        ───────────────▢ lb://INVENTORY-SERVICE  ───────▢  Inventory (8082)          β”‚
β”‚  /api/order/**            ───────────────▢ lb://ORDER-SERVICE      ───────▢  Order (8086)              β”‚
β”‚                                                                                                          β”‚
β”‚  Note: "lb://" = Load Balanced (Service Discovery enabled)                                              β”‚
β”‚                                                                                                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Example Request Flows

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ EXAMPLE 1: Mobile App Login (User Auth Service)                                                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                                          β”‚
β”‚  Mobile App                                                                                              β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β”‚  POST http://34.59.6.212:9191/api/user-auth/v1/auth/login                                        β”‚
β”‚      β”‚  Body: { "email": "user@test.com", "password": "..." }                                           β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β–Ό                                                                                                   β”‚
β”‚  API Gateway (9191)                                                                                      β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β”‚  Route: /api/user-auth/** β†’ lb://USER-AUTH                                                       β”‚
β”‚      β”‚  Strip Prefix: /api/user-auth                                                                    β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β–Ό                                                                                                   β”‚
β”‚  User Auth Service (8080)                                                                                β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β”‚  Internal: POST /v1/auth/login                                                                   β”‚
β”‚      β”‚  β€’ Validate credentials against PostgreSQL                                                       β”‚
β”‚      β”‚  β€’ Generate JWT access + refresh tokens                                                          β”‚
β”‚      β”‚  β€’ Return tokens to client                                                                       β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β–Ό                                                                                                   β”‚
β”‚  Response: { "accessToken": "eyJ...", "refreshToken": "eyJ...", "user": {...} }                         β”‚
β”‚                                                                                                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ EXAMPLE 2: POS System Employee Login (Identity Service + Redis)                                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                                          β”‚
β”‚  POS Desktop App                                                                                         β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β”‚  POST http://34.59.6.212:9191/api/identity/lifepill/v1/auth/authenticate                         β”‚
β”‚      β”‚  Body: { "employerEmail": "emp@lifepill.com", "employerPassword": "..." }                        β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β–Ό                                                                                                   β”‚
β”‚  API Gateway (9191)                                                                                      β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β”‚  Route: /api/identity/** β†’ lb://IDENTITY-SERVICE                                                 β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β–Ό                                                                                                   β”‚
β”‚  Identity Service (8085)                                                                                 β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β”œβ”€β”€β–Ά PostgreSQL: Verify employee credentials                                                       β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β”œβ”€β”€β–Ά Redis: Cache session { token, user, pin, expiry }                                             β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β–Ό                                                                                                   β”‚
β”‚  Response: { "token": "eyJ...", "employer": {...}, "sessionId": "..." }                                 β”‚
β”‚                                                                                                          β”‚
β”‚  ───────────────────────────────────────────────────────────────────────────────────────────────────────│
β”‚                                                                                                          β”‚
β”‚  QUICK RE-LOGIN (PIN from Redis Cache):                                                                  β”‚
β”‚                                                                                                          β”‚
β”‚  POST /api/identity/lifepill/v1/session/authenticate/cached                                             β”‚
β”‚  Body: { "username": "emp@lifepill.com", "pin": 1234 }                                                  β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β–Ό                                                                                                   β”‚
β”‚  Identity Service β†’ Redis (Check cached PIN) β†’ Return cached session                                    β”‚
β”‚                                                                                                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ EXAMPLE 3: Customer Payment (Patient Customer Service + Stripe)                                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                                          β”‚
β”‚  Web App                                                                                                 β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β”‚  POST http://34.59.6.212:9191/api/customer/payments/create                                       β”‚
β”‚      β”‚  Headers: { Authorization: "Bearer eyJ..." }                                                     β”‚
β”‚      β”‚  Body: { "amount": 150.00, "customerId": "cust_123" }                                            β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β–Ό                                                                                                   β”‚
β”‚  API Gateway (9191)                                                                                      β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β”‚  β€’ Relay Authorization header                                                                    β”‚
β”‚      β”‚  β€’ Route: /api/customer/** β†’ lb://PATIENT-CUSTOMER                                               β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β–Ό                                                                                                   β”‚
β”‚  Patient Customer Service (8070)                                                                         β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β”œβ”€β”€β–Ά MongoDB: Fetch customer profile                                                               β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β”œβ”€β”€β–Ά Stripe API: Create PaymentIntent                                                              β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β”œβ”€β”€β–Ά PostgreSQL: Record transaction                                                                β”‚
β”‚      β”‚                                                                                                   β”‚
β”‚      β–Ό                                                                                                   β”‚
β”‚  Response: { "paymentIntentId": "pi_...", "clientSecret": "pi_..._secret_..." }                         β”‚
β”‚                                                                                                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”„ Service Discovery (Pull Architecture)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                    PULL-BASED SERVICE DISCOVERY                                          β”‚
β”‚                                       (Netflix Eureka Pattern)                                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚    EUREKA SERVER        β”‚
                                    β”‚      (Port 8761)        β”‚
                                    β”‚                         β”‚
                                    β”‚  Service Registry:      β”‚
                                    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
                                    β”‚  β”‚ USER-AUTH         β”‚  β”‚
                                    β”‚  β”‚  └─ 8080 (healthy)β”‚  β”‚
                                    β”‚  β”‚ IDENTITY-SERVICE  β”‚  β”‚
                                    β”‚  β”‚  └─ 8085 (healthy)β”‚  β”‚
                                    β”‚  β”‚ PATIENT-CUSTOMER  β”‚  β”‚
                                    β”‚  β”‚  └─ 8070 (healthy)β”‚  β”‚
                                    β”‚  β”‚ BRANCH-SERVICE    β”‚  β”‚
                                    β”‚  β”‚  └─ 8081 (healthy)β”‚  β”‚
                                    β”‚  β”‚ INVENTORY-SERVICE β”‚  β”‚
                                    β”‚  β”‚  └─ 8082 (healthy)β”‚  β”‚
                                    β”‚  β”‚ ORDER-SERVICE     β”‚  β”‚
                                    β”‚  β”‚  └─ 8086 (healthy)β”‚  β”‚
                                    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚                           β”‚                           β”‚
            1. REGISTER                 2. PULL REGISTRY            3. HEARTBEAT
            (On Startup)                (Every 30 sec)              (Every 30 sec)
                    β”‚                           β”‚                           β”‚
                    β–Ό                           β–Ό                           β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β”‚
    β”‚   MICROSERVICE        β”‚     β”‚     API GATEWAY       β”‚                β”‚
    β”‚   (Any Service)       β”‚     β”‚      (Port 9191)      β”‚                β”‚
    β”‚                       β”‚     β”‚                       β”‚                β”‚
    β”‚ On startup:           β”‚     β”‚ Cached Registry:      β”‚                β”‚
    β”‚ β€’ Register with       β”‚     β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚                β”‚
    β”‚   Eureka              β”‚     β”‚ β”‚ USER-AUTH: 8080   β”‚ β”‚                β”‚
    β”‚ β€’ Send metadata       β”‚     β”‚ β”‚ IDENTITY: 8085    β”‚ β”‚                β”‚
    β”‚   (host, port, health)β”‚     β”‚ β”‚ PATIENT: 8070     β”‚ β”‚                β”‚
    β”‚                       β”‚     β”‚ β”‚ ...               β”‚ β”‚                β”‚
    β”‚ Every 30 seconds:     β”‚     β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚                β”‚
    β”‚ β€’ Send heartbeat β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    β”‚                       β”‚     β”‚                       β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚ Uses cache to route   β”‚
                                  β”‚ requests instantly    β”‚
                                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

FLOW EXPLANATION:
━━━━━━━━━━━━━━━━━
1. SERVICE REGISTRATION: When a microservice starts, it registers itself with Eureka
   including its service name, host, port, and health check URL.

2. REGISTRY PULL: API Gateway pulls the full service registry every 30 seconds
   and caches it locally for fast routing decisions.

3. HEARTBEAT: Each service sends a heartbeat to Eureka every 30 seconds.
   If missed 3 times (90 sec), the service is marked as DOWN and removed.

4. SELF-PRESERVATION: If >85% of instances miss heartbeats (network partition),
   Eureka enters self-preservation mode and keeps registrations.

πŸ“‚ Repository Structure (Git Submodules)

This is a monorepo that links to the following microservices as Git submodules:

Submodule Repository Description Port
api-gateway Life-Pill/api-gateway Spring Cloud Gateway with Circuit Breaker 9191
service-registry Life-Pill/service-registry Netflix Eureka Server 8761
config-server Life-Pill/configuration-server Spring Cloud Config Server 8888
user-auth Life-Pill/mobile-auth-user-service JWT Authentication Service (Mobile) 8080
patient-customer-service Life-Pill/patient-web-customer-service Patient & Customer Management 8070

Additional Services (Non-Submodule)

Service Location Description Port
employee-identity-service ./employee-identity-service Employee Auth with Redis Session 8085
branch-service ./branch-service Branch Management 8081
inventory-service ./inventory-service Inventory Management 8082
order-service ./pharmacy-pos-main-backend/order-system Order Processing & POS 8086

πŸ”„ Cloning with Submodules

# Clone with all submodules
git clone --recurse-submodules https://github.com/Life-Pill/mobile-ms.git

# Or if already cloned, initialize submodules
git submodule init
git submodule update

# Update all submodules to latest
git submodule update --remote --merge

πŸ“‹ Services Overview

Business Services

Service Port Description Database
User Auth Service 8080 JWT-based authentication for mobile apps PostgreSQL
Identity Service 8085 Employee auth with PIN & Redis session caching PostgreSQL + Redis
Patient Customer Service 8070 Patient records, prescriptions, Stripe payments PostgreSQL + MongoDB
Branch Service 8081 Branch management, locations, operating hours PostgreSQL
Inventory Service 8082 Stock management, product catalog, alerts PostgreSQL
Order Service 8086 Order processing, transactions, receipts PostgreSQL

Infrastructure Services

Service Port Description
Service Registry 8761 Netflix Eureka Server for service discovery
Config Server 8888 Centralized configuration management
API Gateway 9191 Single entry point with routing, load balancing, circuit breaker

Data Stores

Service Port Description
PostgreSQL 5432 Primary relational database
MongoDB 27017 Document database for patient records
Redis 6379 Session caching and rate limiting

Observability Stack

Service Port Description
Prometheus 9090 Metrics collection and alerting
Grafana 3001 Metrics visualization dashboards
Zipkin 9411 Distributed tracing
PostgreSQL Exporter 9187 PostgreSQL metrics for Prometheus
Redis Exporter 9121 Redis metrics for Prometheus
MongoDB Exporter 9216 MongoDB metrics for Prometheus

Pull Architecture (Service Discovery)

The system uses Pull-based Service Discovery via Netflix Eureka:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         PULL ARCHITECTURE                                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                              β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          1. Register              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚   β”‚   Service   β”‚ ─────────────────────────────────▢│  Eureka Server  β”‚     β”‚
β”‚   β”‚  (on start) β”‚                                   β”‚    (8761)       β”‚     β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β”‚                                                              β”‚              β”‚
β”‚                                                              β”‚              β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         2. Pull Registry          β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”      β”‚
β”‚   β”‚ API Gateway β”‚ ◀────────────────────────────────│ Service List  β”‚      β”‚
β”‚   β”‚   (9191)    β”‚         (Every 30 sec)           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                                                          β”‚
β”‚          β”‚                                                                  β”‚
β”‚          β”‚ 3. Route Request (with cached registry)                         β”‚
β”‚          β”‚                                                                  β”‚
β”‚          β–Ό                                                                  β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚   β”‚                      MICROSERVICES                                β”‚     β”‚
β”‚   β”‚                                                                   β”‚     β”‚
β”‚   β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚     β”‚
β”‚   β”‚  β”‚ Identity  β”‚  β”‚   User    β”‚  β”‚  Patient  β”‚  β”‚   Order   β”‚     β”‚     β”‚
β”‚   β”‚  β”‚  Service  β”‚  β”‚   Auth    β”‚  β”‚  Service  β”‚  β”‚  Service  β”‚     β”‚     β”‚
β”‚   β”‚  β”‚  (8085)   β”‚  β”‚  (8080)   β”‚  β”‚  (8070)   β”‚  β”‚  (8086)   β”‚     β”‚     β”‚
β”‚   β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚     β”‚
β”‚   β”‚                                                                   β”‚     β”‚
β”‚   β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                    β”‚     β”‚
β”‚   β”‚  β”‚  Branch   β”‚  β”‚ Inventory β”‚                                    β”‚     β”‚
β”‚   β”‚  β”‚  Service  β”‚  β”‚  Service  β”‚                                    β”‚     β”‚
β”‚   β”‚  β”‚  (8081)   β”‚  β”‚  (8082)   β”‚                                    β”‚     β”‚
β”‚   β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                    β”‚     β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β”‚                                                                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

PULL FLOW:
1. Services REGISTER themselves with Eureka on startup
2. API Gateway PULLS the service registry every 30 seconds
3. Gateway uses CACHED registry to route requests to services
4. If a service goes down, it's removed from registry after heartbeat timeout

Session Management Architecture (Redis Caching)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     SESSION MANAGEMENT FLOW                                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    1. Login (password)     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”‚
β”‚  β”‚  Client  β”‚ ──────────────────────────▢│   Identity   β”‚                   β”‚
β”‚  β”‚  (POS)   β”‚                            β”‚   Service    β”‚                   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                            β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜                   β”‚
β”‚       β”‚                                         β”‚                           β”‚
β”‚       β”‚                                         β”‚ 2. Authenticate           β”‚
β”‚       β”‚                                         β”‚    & Generate JWT         β”‚
β”‚       β”‚                                         β–Ό                           β”‚
β”‚       β”‚                                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”‚
β”‚       β”‚                                  β”‚  PostgreSQL  β”‚                   β”‚
β”‚       β”‚                                  β”‚   (5432)     β”‚                   β”‚
β”‚       β”‚                                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                   β”‚
β”‚       β”‚                                         β”‚                           β”‚
β”‚       β”‚                                         β”‚ 3. Cache Session          β”‚
β”‚       β”‚                                         β–Ό                           β”‚
β”‚       β”‚                                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”‚
β”‚       β”‚                                  β”‚    Redis     β”‚                   β”‚
β”‚       β”‚    ◀──────────────────────────── β”‚   (6379)     β”‚                   β”‚
β”‚       β”‚    4. Return JWT + Session       β”‚              β”‚                   β”‚
β”‚       β”‚                                  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚                   β”‚
β”‚       β”‚                                  β”‚  β”‚Session β”‚  β”‚                   β”‚
β”‚       β”‚                                  β”‚  β”‚ Data:  β”‚  β”‚                   β”‚
β”‚       β”‚                                  β”‚  β”‚ -token β”‚  β”‚                   β”‚
β”‚       β”‚                                  β”‚  β”‚ -user  β”‚  β”‚                   β”‚
β”‚       β”‚                                  β”‚  β”‚ -expiryβ”‚  β”‚                   β”‚
β”‚       β”‚                                  β”‚  β”‚-revokedβ”‚  β”‚                   β”‚
β”‚       β”‚                                  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚                   β”‚
β”‚       β”‚                                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                   β”‚
β”‚       β”‚                                                                     β”‚
β”‚       β”‚    5. Re-login with PIN (from cache)                               β”‚
β”‚       β”‚ ─────────────────────────────────────────▢                         β”‚
β”‚       β”‚                                                                     β”‚
β”‚       β”‚    ◀─────────────────────────────────────                          β”‚
β”‚       β”‚    6. Return cached session                                        β”‚
β”‚                                                                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

SESSION OPERATIONS:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Temporary Logout  β”‚ Keep cache data, set DB inactive           β”‚
β”‚                   β”‚ User can re-login with PIN                 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Permanent Logout  β”‚ Delete cache data, set DB inactive         β”‚
β”‚                   β”‚ User must login with password              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Session Valid     β”‚ revoked == false AND expiresAt > now()     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Identity Service Session Endpoints

Method Endpoint Request Body Description
POST /lifepill/v1/auth/authenticate {"employerEmail": "...", "employerPassword": "..."} Login with password (caches session)
POST /lifepill/v1/auth/authenticate-pin {"employerEmail": "...", "pin": 1234} Login with PIN (caches session)
POST /lifepill/v1/session/authenticate/cached {"username": "...", "pin": 1234} Re-login from cache with PIN
POST /lifepill/v1/session/logout/temporary {"username": "..."} Temporary logout (keeps cache)
POST /lifepill/v1/session/logout/permanent {"username": "..."} Permanent logout (removes cache)
GET /lifepill/v1/session/get-cached-employer/email/{email} - Get cached session by email
GET /lifepill/v1/session/get-all-cached-employers - Get all cached sessions
GET /lifepill/v1/session/check/{email} - Check if session is valid

Startup Order

Important: Services must be started in the following order:

1. PostgreSQL, MongoDB, Redis - Infrastructure
2. Service Registry (Eureka Server) - Port 8761
3. Config Server - Port 8888
4. Zipkin - Port 9411
5. API Gateway - Port 9191
6. Identity Service - Port 8085
7. User Auth Service - Port 8080
8. Patient Customer Service - Port 8070
9. Other Services...
10. Prometheus, Grafana - Monitoring

πŸ”§ Configuration

Environment Variables

Each service requires specific environment variables. Copy the .env.example files to .env and configure:

Service Registry

EUREKA_PORT=8761
EUREKA_USERNAME=admin
EUREKA_PASSWORD=your-secure-password

Config Server

CONFIG_SERVER_PORT=8888
CONFIG_SERVER_USERNAME=configuser
CONFIG_SERVER_PASSWORD=your-secure-password
EUREKA_URI=http://localhost:8761/eureka/

API Gateway

API_GATEWAY_PORT=9191
EUREKA_URI=http://localhost:8761/eureka/
CORS_ORIGINS=http://localhost:3000,http://localhost:8081

User Auth Service

DB_URL=jdbc:postgresql://localhost:5432/mobile_user_auth_db
DB_USERNAME=postgres
DB_PASSWORD=your-db-password
JWT_SECRET=your-jwt-secret-key
EUREKA_URI=http://localhost:8761/eureka/

Identity Service

DB_URL=jdbc:postgresql://localhost:5432/identity_service_db
REDIS_HOST=localhost
REDIS_PORT=6379
JWT_SECRET=your-jwt-secret-key
EUREKA_URI=http://localhost:8761/eureka/

πŸƒβ€β™‚οΈ Running the Services

Using Docker Compose

# Copy environment file and configure
cp .env.example .env

# Build and start all services
docker compose --env-file .env up -d

# View logs
docker compose logs -f

# Stop all services
docker compose down

Quick Start with Docker

# 1. Clone repository
git clone --recurse-submodules https://github.com/Life-Pill/mobile-ms.git
cd mobile-ms

# 2. Setup environment
cp .env.example .env
# Edit .env with your configuration

# 3. Start all services
docker compose --env-file .env up -d

# 4. Verify services
docker compose ps

Service URLs

After starting with Docker Compose:

Service URL
Eureka Dashboard http://localhost:8761
API Gateway http://localhost:9191
Identity Service Swagger http://localhost:8085/swagger-ui/index.html
User Auth Swagger http://localhost:8080/api/swagger-ui.html
Patient Customer Swagger http://localhost:8070/swagger-ui.html
Branch Service Swagger http://localhost:8081/swagger-ui.html
Inventory Service Swagger http://localhost:8082/swagger-ui.html
Order Service Swagger http://localhost:8086/swagger-ui.html
Prometheus http://localhost:9090
Grafana http://localhost:3001
Zipkin http://localhost:9411

Production URLs (Server: 34.59.6.212)

Service URL
Eureka Dashboard http://34.59.6.212:8761
API Gateway http://34.59.6.212:9191
User Auth Swagger http://34.59.6.212:8080/api/swagger-ui.html
Patient Customer Swagger http://34.59.6.212:8070/swagger-ui.html
Branch Service Swagger http://34.59.6.212:8081/swagger-ui.html
Inventory Service Swagger http://34.59.6.212:8082/swagger-ui.html
Identity Service Swagger http://34.59.6.212:8085/swagger-ui.html
Order Service Swagger http://34.59.6.212:8086/swagger-ui.html
Prometheus http://34.59.6.212:9090
Grafana http://34.59.6.212:3001
Zipkin http://34.59.6.212:9411

Monitoring & Health Checks

Actuator Endpoints

All services expose actuator endpoints for monitoring:

Endpoint Description
/actuator/health Health status
/actuator/info Application info
/actuator/metrics Metrics data
/actuator/prometheus Prometheus format metrics

Service Discovery Dashboard

Access Eureka Dashboard: http://localhost:8761

  • Username: admin (default)
  • Password: admin (default)

πŸ”’ Security Features

API Gateway

  • Circuit Breaker pattern (Resilience4j)
  • Request rate limiting
  • CORS configuration
  • Request/Response logging
  • Authentication header relay

Identity Service

  • JWT-based authentication
  • BCrypt password encoding
  • PIN-based quick authentication
  • Redis session caching with TTL
  • Session revocation support

Service Registry

  • Basic authentication for dashboard
  • Secured actuator endpoints

πŸ”„ Circuit Breaker Configuration

The API Gateway implements circuit breaker pattern:

resilience4j:
  circuitbreaker:
    instances:
      userAuthCircuitBreaker:
        sliding-window-size: 5
        failure-rate-threshold: 40
        wait-duration-in-open-state: 15s

πŸ› οΈ Technology Stack

  • Java 17
  • Spring Boot 3.3.0
  • Spring Cloud 2023.0.1
  • Spring Cloud Gateway (Reactive)
  • Netflix Eureka (Service Discovery)
  • Spring Cloud Config (Configuration Management)
  • Resilience4j (Circuit Breaker)
  • Spring Data Redis (Session Caching)
  • Micrometer + Prometheus (Metrics)
  • PostgreSQL (Database)
  • MongoDB (Document Database)
  • Redis (Session Cache)
  • Flyway (Database Migration)
  • JWT (Authentication)

πŸ“ž Support

For support, email support@lifepill.com or raise an issue in the repository.

πŸ“„ License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published