# kimoanhlethi2004/dhhttt18tthl-n11-cab-system architecture

> Architecture diagram of the GitHub repository kimoanhlethi2004/dhhttt18tthl-n11-cab-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system
- Repository: https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system

## Overview

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`](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/api-gateway/app.js) (API Gateway), [`services/driver-service/app.js`](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/driver-service/app.js) (Drivers), [`services/ride-service/app.js`](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/ride-service/app.js) (Ride), [`services/auth-service/app.js`](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/auth-service/app.js) (Auth)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_cab_ui["Cab UI<br/>SPA<br/>[App.jsx]"]
end

subgraph group_edge["Edge"]
  node_api_gateway["API Gateway<br/>[app.js]"]
end

subgraph group_domain["Domain services"]
  node_auth_service["Auth<br/>identity<br/>[app.js]"]
  node_user_service["Users<br/>profile-store<br/>[app.js]"]
  node_driver_service["Drivers<br/>driver-store<br/>[app.js]"]
  node_booking_service["Booking<br/>trip-orchestrator<br/>[app.js]"]
  node_pricing_service["Pricing<br/>fare-engine<br/>[app.js]"]
  node_ride_service["Ride<br/>[app.js]"]
  node_payment_service["Payments<br/>payment-ledger<br/>[app.js]"]
  node_review_service["Reviews<br/>feedback-store<br/>[app.js]"]
end

subgraph group_eventing["Eventing"]
  node_ai_matching_service["Matching<br/>assignment-engine<br/>[index.js]"]
  node_notification_service["Notifications<br/>fanout<br/>[app.js]"]
  node_kafka_bus{{"Kafka<br/>event-bus"}}
  node_redis_state[("Redis<br/>fast-state")]
  node_mongo_store[("MongoDB<br/>document-store")]
  node_postgres_store[("Postgres<br/>relational-store")]
end

subgraph group_ops["Ops"]
  node_docs_openapi["API Spec<br/>contract<br/>[openapi.yaml]"]
  node_docker_compose["Compose<br/>runtime-orchestration<br/>[docker-compose.yml]"]
  node_observability["Metrics<br/>observability<br/>[prometheus.yml]"]
  node_security_checklist["Zero Trust<br/>security-guidance"]
end

node_cab_ui -->|"API calls"| node_api_gateway
node_cab_ui -.->|"live updates"| node_notification_service
node_api_gateway -->|"auth"| node_auth_service
node_api_gateway -->|"profile"| node_user_service
node_api_gateway -->|"driver"| node_driver_service
node_api_gateway -->|"booking"| node_booking_service
node_api_gateway -->|"pricing"| node_pricing_service
node_api_gateway -->|"ride"| node_ride_service
node_api_gateway -->|"payment"| node_payment_service
node_api_gateway -->|"review"| node_review_service
node_auth_service -->|"provision user"| node_user_service
node_auth_service -->|"provision driver"| node_driver_service
node_booking_service -->|"quote"| node_pricing_service
node_booking_service -->|"booking events"| node_kafka_bus
node_ai_matching_service -->|"consume/publish"| node_kafka_bus
node_ai_matching_service -->|"state"| node_redis_state
node_driver_service -->|"assignment events"| node_kafka_bus
node_driver_service -->|"state"| node_redis_state
node_driver_service -->|"persist"| node_postgres_store
node_ride_service -->|"booking confirmed"| node_kafka_bus
node_ride_service -->|"persist"| node_mongo_store
node_ride_service -->|"cache"| node_redis_state
node_payment_service -->|"ride context"| node_ride_service
node_payment_service -->|"persist"| node_postgres_store
node_payment_service -->|"payment.success"| node_kafka_bus
node_notification_service -->|"consume"| node_kafka_bus
node_notification_service -.->|"websocket push"| node_cab_ui
node_booking_service -->|"persist"| node_mongo_store
node_auth_service -->|"persist"| node_mongo_store
node_review_service -->|"persist"| node_mongo_store
node_docs_openapi -.->|"contract"| node_api_gateway
node_docker_compose -.->|"orchestrates"| node_api_gateway
node_docker_compose -.->|"orchestrates"| node_kafka_bus
node_observability -.->|"monitor"| node_notification_service
node_security_checklist -.->|"trust boundary"| node_api_gateway

click node_cab_ui "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/cab-ui/src/App.jsx"
click node_api_gateway "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/api-gateway/app.js"
click node_auth_service "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/auth-service/app.js"
click node_user_service "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/user-service/app.js"
click node_driver_service "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/driver-service/app.js"
click node_booking_service "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/booking-service/app.js"
click node_pricing_service "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/pricing-service/app.js"
click node_ride_service "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/ride-service/app.js"
click node_payment_service "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/payment-service/app.js"
click node_review_service "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/review-service/app.js"
click node_ai_matching_service "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/ai-matching-service/index.js"
click node_notification_service "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/notification-service/app.js"
click node_docs_openapi "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/docs/openapi.yaml"
click node_docker_compose "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/docker-compose.yml"
click node_observability "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/observability/prometheus.yml"
click node_security_checklist "https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/security/zero-trust-checklist.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cab_ui toneBlue
class node_api_gateway toneAmber
class node_auth_service,node_user_service,node_driver_service,node_booking_service,node_pricing_service,node_ride_service,node_payment_service,node_review_service toneMint
class node_ai_matching_service,node_notification_service,node_kafka_bus,node_redis_state,node_mongo_store,node_postgres_store toneRose
class node_docs_openapi,node_docker_compose,node_observability,node_security_checklist toneIndigo
```

## Components

### Client

Browser SPA and realtime user-facing UI

- [Cab UI](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/cab-ui/src/App.jsx): SPA · React/Vite client for riders and drivers · `cab-ui/src/App.jsx`

### Edge

Public API gateway and trust boundary

- [API Gateway](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/api-gateway/app.js): 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](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/auth-service/app.js): identity · Registration, login, token issuance, and credential state · `services/auth-service/app.js`
- [Users](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/user-service/app.js): profile-store · Customer profile ownership and user data · `services/user-service/app.js`
- [Drivers](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/driver-service/app.js): driver-store · Driver profiles, assignment handling, and driver realtime API · `services/driver-service/app.js`
- [Booking](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/booking-service/app.js): trip-orchestrator · Booking lifecycle, cancellation rules, and booking events · `services/booking-service/app.js`
- [Pricing](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/pricing-service/app.js): fare-engine · Fare and ETA calculation used during booking creation · `services/pricing-service/app.js`
- [Ride](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/ride-service/app.js): ride-read-model · Ride materialization and active trip status · `services/ride-service/app.js`
- [Payments](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/payment-service/app.js): payment-ledger · Payment creation and driver revenue tracking · `services/payment-service/app.js`
- [Reviews](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/review-service/app.js): feedback-store · Post-ride ratings and comments · `services/review-service/app.js`

### Eventing

Kafka-driven matching, notification, and realtime flows

- [Matching](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/ai-matching-service/index.js): assignment-engine · Scores available drivers and emits assignment requests · `services/ai-matching-service/index.js`
- [Notifications](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/services/notification-service/app.js): fanout · Stores notification records and pushes websocket updates · `services/notification-service/app.js`
- **Kafka**: event-bus · Asynchronous backbone for booking, matching, ride, payment, and notification events
- **Redis**: fast-state · Shared caching and workflow state for matching, driver, and ride flows
- **MongoDB**: document-store · Document persistence used by booking, ride, review, and auth-style data
- **Postgres**: relational-store · Transactional persistence for driver and payment services

### Ops

Contracts, orchestration, security, and observability

- [API Spec](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/docs/openapi.yaml): contract · Documented HTTP contract for the platform · `docs/openapi.yaml`
- [Compose](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/docker-compose.yml): runtime-orchestration · Local multi-service container composition · `docker-compose.yml`
- [Metrics](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/observability/prometheus.yml): observability · Prometheus scraping and alerting configuration · `observability/prometheus.yml`
- [Zero Trust](https://github.com/kimoanhlethi2004/dhhttt18tthl-n11-cab-system/blob/main/security/zero-trust-checklist.md): security-guidance · Internal service authentication and trust model checklist · `security/zero-trust-checklist.md`

## Connections

- 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
