How kimoanhlethi2004/dhhttt18tthl-n11-cab-system works
1. Overall shape
This repository is a Node.js microservices taxi platform with a single public edge (api-gateway), a React/Vite client (cab-ui), and a set of domain services under services/. The system is split into synchronous HTTP request/response paths and asynchronous Kafka event flows, with WebSockets used for live updates.
2. Edge layer
api-gateway is the only client-facing backend entrypoint in normal use. It routes requests to internal services, performs auth introspection, and forwards either user JWTs or internally signed service JWTs depending on the downstream route. This makes the gateway the trust boundary between the browser/app and the service mesh.
3. Frontend
cab-ui is a separate SPA built with React and Vite, styled with Tailwind, and served behind Nginx in Docker. It talks to the gateway for application APIs and uses realtime channels for live driver/ride updates. The presence of services/osrm.js suggests route/map support is handled client-side with an OSRM integration helper.
4. Identity and account creation
auth-service owns registration, login, logout, access/refresh token issuance, and token storage. It creates credentials first, then provisions the customer or driver profile by calling user-service or driver-service with an internal service JWT. user-service and driver-service therefore hold profile data, while auth-service owns authentication state.
5. Core booking and ride domain
booking-service manages booking lifecycle and cancellation rules. It is the source of booking events and depends on pricing-service for fare/ETA calculation before a booking is created. ride-service consumes booking confirmation events and materializes the ride aggregate/status as the downstream read model for active trips.
6. Driver matching pipeline
Matching is intentionally event-driven. booking-service emits booking-created events, ai-matching-service consumes them, scores available drivers using its repository/scoring logic plus Redis/Kafka state, and publishes driver.assigned.requested. driver-service consumes that assignment request, notifies the driver, and later emits accept/reject events back into the flow.
7. Notification and realtime delivery
notification-service is the broadcast layer for live user-facing updates. It consumes Kafka events such as ride status changes, payment success, and driver location updates, stores notification records, and pushes WebSocket messages to connected clients. driver-service also has its own WebSocket gateway for driver-side realtime interaction.
8. Payments and reviews
payment-service owns payment creation and driver revenue tracking, backed by Postgres. It reads ride context from ride-service before recording payment state, then emits payment.success for downstream notifications. review-service is a separate persistence boundary for post-ride customer ratings and comments.
9. Data storage boundaries
The repository uses multiple datastores by service: MongoDB for booking/ride/review/auth-style document data, Postgres for driver and payment transactional data, and Redis for fast state/caching in matching, driver, and ride workflows. These are not shared databases; each service has its own storage adapter and owns its schema/state.
10. Async infrastructure
Kafka is the main integration backbone. Key topics connect booking, matching, driver acceptance, ride creation, payment success, and notification fan-out. The architecture relies on this event bus to decouple service ownership and to keep the ride lifecycle resilient to latency or temporary downstream unavailability.
11. Security model
There are two token layers: user access JWTs and internal service JWTs. User JWTs protect customer/driver actions through the gateway and service middlewares, while service JWTs are used for privileged service-to-service calls and event-triggered internal requests. The repo also includes a zero-trust checklist, reflecting that internal traffic is still authenticated rather than implicitly trusted.
12. Operations and delivery
The project is container-first: every service has a Dockerfile and the top-level docker-compose.yml orchestrates the platform locally. Observability is separated into Prometheus config and alert rules, and the API contract is documented in docs/openapi.yaml. That makes the architecture diagram naturally include runtime services, Kafka, databases, WebSockets, and the monitoring plane.
Main entry points: api-gateway/app.js API Gateway · driver-service/app.js Drivers · ride-service/app.js Ride · auth-service/app.js Auth
Components 20
Client
Browser SPA and realtime user-facing UI
- Cab UI · React/Vite client for riders and drivers
cab-ui/src/App.jsx
Edge
Public API gateway and trust boundary
- API Gateway · Public entrypoint, routing, auth introspection, and internal token forwarding
api-gateway/app.js
Domain services
Core booking, identity, ride, payment, and review services
- Auth · Registration, login, token issuance, and credential state
services/auth-service/app.js - Users · Customer profile ownership and user data
services/user-service/app.js - Drivers · Driver profiles, assignment handling, and driver realtime API
services/driver-service/app.js - Booking · Booking lifecycle, cancellation rules, and booking events
services/booking-service/app.js - Pricing · Fare and ETA calculation used during booking creation
services/pricing-service/app.js - Ride · Ride materialization and active trip status
services/ride-service/app.js - Payments · Payment creation and driver revenue tracking
services/payment-service/app.js - Reviews · Post-ride ratings and comments
services/review-service/app.js
Eventing
Kafka-driven matching, notification, and realtime flows
- Matching · Scores available drivers and emits assignment requests
services/ai-matching-service/index.js - Notifications · Stores notification records and pushes websocket updates
services/notification-service/app.js - Kafka · Asynchronous backbone for booking, matching, ride, payment, and notification events
- Redis · Shared caching and workflow state for matching, driver, and ride flows
- MongoDB · Document persistence used by booking, ride, review, and auth-style data
- Postgres · Transactional persistence for driver and payment services
Ops
Contracts, orchestration, security, and observability
- API Spec · Documented HTTP contract for the platform
docs/openapi.yaml - Compose · Local multi-service container composition
docker-compose.yml - Metrics · Prometheus scraping and alerting configuration
observability/prometheus.yml - Zero Trust · Internal service authentication and trust model checklist
security/zero-trust-checklist.md
Connections 35
- Cab UI → API Gateway: API calls · Browser traffic goes through the gateway
- Cab UI → Notifications: live updates · Client receives realtime ride and driver updates
- API Gateway → Auth: auth · Login, registration, and token flows
- API Gateway → Users: profile · User profile operations
- API Gateway → Drivers: driver · Driver-facing HTTP operations
- API Gateway → Booking: booking · Booking creation and lifecycle requests
- API Gateway → Pricing: pricing · Fare and ETA requests
- API Gateway → Ride: ride · Ride state reads and actions
- API Gateway → Payments: payment · Payment API entrypoint
- API Gateway → Reviews: review · Post-ride review API entrypoint
- Auth → Users: provision user · Creates customer profiles after credential setup
- Auth → Drivers: provision driver · Creates driver profiles after credential setup
- Booking → Pricing: quote · Fetches fare and ETA before booking creation
- Booking → Kafka: booking events · Publishes booking lifecycle events
- Matching → Kafka: consume/publish · Consumes booking-created events and emits assignment requests
- Matching → Redis: state · Uses fast state for matching inputs and availability
- Drivers → Kafka: assignment events · Consumes assignment requests and publishes driver responses
- Drivers → Redis: state · Uses Redis for driver workflow and availability state
- Drivers → Postgres: persist · Stores transactional driver data
- Ride → Kafka: booking confirmed · Consumes booking confirmation and publishes ride events
- Ride → MongoDB: persist · Stores ride aggregate data
- Ride → Redis: cache · Uses Redis for live ride state
- Payments → Ride: ride context · Reads ride details before recording payment state
- Payments → Postgres: persist · Stores payment and revenue records
- Payments → Kafka: payment.success · Emits downstream payment success events
- Notifications → Kafka: consume · Consumes ride, payment, and driver update events
- Notifications → Cab UI: websocket push · Pushes user-facing realtime notifications
- Booking → MongoDB: persist · Stores booking documents
- Auth → MongoDB: persist · Stores credentials and refresh tokens
- Reviews → MongoDB: persist · Stores review documents
- API Spec → API Gateway: contract · Documents the external HTTP surface
- Compose → API Gateway: orchestrates · Local platform composition
- Compose → Kafka: orchestrates · Local event backbone composition
- Metrics → Notifications: monitor · Operational coverage for services
- Zero Trust → API Gateway: trust boundary · Documents authenticated internal and external traffic