Architecture Overview
Core Components
Gateway API
Purpose: Unified entry point for all client requests with routing and authentication Technology: YARP (Yet Another Reverse Proxy) Key Features:- Reverse proxy with service discovery
- JWT token validation via JWKS
- Request/response logging
- CORS policy management
- Automatic header forwarding
/users/*→ Users Service/trips/*→ Trips Service/notifications/*→ Notifications Service/identity/*→ Identity Service
Identity Service
Purpose: Centralized authentication and authorization Database:authdb (PostgreSQL)
Key Features:
- User authentication with JWT tokens
- JWKS endpoint for token validation
- Identity key management with persistent storage
- Integration with Users service for profile data
- PostgreSQL (auth database)
- RabbitMQ (event publishing)
- Users Service (HTTP)
Users Service
Purpose: Manages user profiles, drivers, passengers, and file uploads Database:userdb (PostgreSQL)
Key Features:
- User profile management (drivers, passengers, companies)
- File upload handling with local storage (
wwwroot) - Account purge background worker
- Integration with Trips service for usage tracking
- Response compression (Brotli/Gzip)
- Wolverine + RabbitMQ for messaging with PostgreSQL outbox pattern
- PostgreSQL (users database)
- RabbitMQ (pub/sub messaging)
- Trips Service (HTTP - usage tracking)
- Notifications Service (HTTP)
- Identity Service (JWKS for authentication)
AccountPurgeWorker- Periodic cleanup of inactive accounts
Trips Service
Purpose: Core business logic for trip management, bookings, and payments Database:tripdb (PostgreSQL)
Key Features:
- Trip creation and management (driver trips, company trips)
- Seat booking and passenger reservations
- Unified search (driver trips + company trips)
- Payment integration with Moyasar
- Wallet operations and top-ups
- Booking transfers and cancellations
- Trip reminders with Hangfire scheduling
- Auto-cancellation of overdue trips
- GeoJSON support for routes
- PostgreSQL (trips database)
- RabbitMQ (event-driven communication)
- Hangfire (background job scheduling)
- Users Service (HTTP - for user data)
HangfireStartupService- Configures recurring jobs- Trip reminder scheduling
- Auto-cancellation of overdue trips
Notifications Service
Purpose: Push notifications to mobile devices via Firebase Cloud Messaging Database:notificationsdb (PostgreSQL)
Key Features:
- Firebase Cloud Messaging (FCM) integration
- Device token management
- Notification history tracking
- Event-driven notifications via RabbitMQ
- Integration with Users service for user data
- PostgreSQL (notifications database)
- RabbitMQ (event subscription)
- Users Service (HTTP)
- Firebase Cloud Messaging
- Trip creation notifications
- Booking confirmations
- Payment confirmations
- Trip reminders
- Cancellation alerts
Technology Stack
Runtime
.NET 9
- Minimal APIs
- Native AOT ready
- High-performance runtime
Orchestration
.NET Aspire
- Service orchestration
- Service discovery
- Resource management
- Dashboard and monitoring
Database
PostgreSQL
- 4 separate databases
- FluentMigrator for migrations
- Npgsql driver
Message Broker
RabbitMQ
- Event-driven communication
- Pub/sub pattern
- Message persistence
Messaging Framework
Wolverine
- .NET messaging framework
- PostgreSQL outbox pattern
- RabbitMQ integration
- Transactional messaging
API Gateway
YARP
- Reverse proxy
- Dynamic routing
- Service discovery
- Load balancing
Authentication
JWT + JWKS
- Token-based auth
- Key discovery
- Distributed validation
Validation
FluentValidation
- Request validation
- Complex rules
- Composable validators
Scheduling
Hangfire
- Background jobs
- Recurring tasks
- Trip reminders
- Auto-cancellation
API Documentation
Swagger/OpenAPI
- Interactive documentation
- Schema generation
- Try-it-out functionality
Observability
OpenTelemetry
- Distributed tracing
- Metrics collection
- Log aggregation
- OTLP protocol
Push Notifications
Firebase Cloud Messaging
- Mobile push notifications
- Cross-platform support
- Rich notifications
Communication Patterns
Synchronous (HTTP)
Service Discovery: All HTTP communication uses Aspire’s built-in service discovery:https+http:// scheme tells Aspire to:
- Discover the service endpoint
- Try HTTPS first, fall back to HTTP
- Handle load balancing automatically
- Users → Trips (usage tracking)
- Users → Notifications (send notifications)
- Notifications → Users (get user data)
- All Services → Identity (JWKS key discovery)
Asynchronous (Event-Driven)
Wolverine + RabbitMQ: All services use Wolverine for reliable, transactional messaging: Publishing Events:- Reliability: PostgreSQL outbox pattern ensures no message loss
- Decoupling: Services don’t need to know about each other
- Scalability: Async processing doesn’t block HTTP requests
- Resilience: Failed messages are automatically retried
Database Architecture
Database-per-Service Pattern
Each service owns its database with complete autonomy:userdb- Users Servicetripdb- Trips Servicenotificationsdb- Notifications Serviceauthdb- Identity Service
Observability Stack
OpenTelemetry Integration
All services export telemetry using the OTLP protocol:Telemetry Pipeline
Metrics
- Request rates
- Response times
- Error rates
- Resource usage (CPU, memory)
- Custom business metrics
Traces
- Request flow across services
- Latency breakdown
- Database query times
- HTTP client calls
- RabbitMQ message flow
Logs
- Structured logs
- Correlation IDs
- Exception details
- Business events
- Audit trails
Resilience Patterns
HTTP Resilience
All HTTP clients include standard resilience handlers:- Retry: Automatic retry with exponential backoff
- Timeout: Per-request and total timeout
- Circuit Breaker: Fail fast when service is down
- Bulkhead: Limit concurrent requests
Messaging Resilience
PostgreSQL Outbox Pattern:- Messages are first written to the database
- Published to RabbitMQ in a background process
- Guarantees message delivery even if RabbitMQ is down
- Failed messages are moved to DLQ
- Can be reprocessed or analyzed
Health Checks
All services expose health endpoints:Service Dependencies
Startup Order
Aspire manages service dependencies withWaitFor():
Service References
Identity References: All services reference Identity for JWKS:Configuration Management
Aspire Configuration
All configuration flows through Aspire:appsettings.json(development defaults)- Environment variables (overrides)
- User secrets (local development)
- Azure Key Vault (production)
Environment-Specific Settings
dotnet run→ Development modeaspire publish→ Production mode (generates docker-compose)
Deployment Architecture
Development (Aspire)
Development uses Aspire orchestration:- Service discovery
- Health monitoring
- Log aggregation
- Resource visualization
- Live reload
Production (Docker Compose)
Production uses generated docker-compose files:deploy.sh:57):
- Initialize volumes for file storage
- Attach containers to npm-network (for reverse proxy)
- Run permission fixes for upload directories
Security Considerations
Development Security Issues
-
Certificate Validation Disabled:
-
CORS Allow All:
-
Default Credentials:
- RabbitMQ:
guest/guest - PostgreSQL: Trust authentication
- RabbitMQ:
Production Recommendations
- Use proper TLS certificates
- Configure specific CORS origins
- Use strong, unique passwords from Key Vault
- Enable PostgreSQL authentication
- Implement rate limiting
- Use API keys for service-to-service auth
- Enable network segmentation
Next Steps
Quickstart Guide
Get the system running locally in minutes
Development Setup
Configure your development environment
API Reference
Detailed API documentation for all services
Deployment Guide
Deploy to production environments