# olantobi/ride-booking-service architecture

> Architecture diagram of the GitHub repository olantobi/ride-booking-service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/olantobi/ride-booking-service
- Repository: https://github.com/olantobi/ride-booking-service

## Overview

- booking-producer-service (the Producer microservice)
- booking-consumer-service (the Consumer microservice)
- booking-service-contract (shared service contract containing DTOs)

##### And Clearly Separate the Main Components
- Producer Microservice:
- Contains the REST API endpoints (BookingController, Swagger config, global exception handling).
- Runs on port 8080.
- Responsible for receiving booking requests and publishing booking messages.
- Contains configuration for interacting with a message broker (via RabbitMQ configurations in its config package).
- Consumer Microservice:
- Listens for incoming booking messages through a message queue.
- Runs on port 8100.
- Uses JPA configuration (JpaConfig) to interact with a persistence storage (database) and handles business logic like auditing (AuditService, PrintAuditService).
- Service Contract Module:
- Defines shared Data Transfer Objects (DTOs) like BookingDto, ErrorDto, MessageWrapper, etc.
- Provides a common interface so that both microservices adhere to the same data contracts.
- Cross-cutting Elements:
- Externalized configuration via application.yml in the parent project, ensuring consistent configuration across microservices.
- Usage of RabbitMQ as the message broker connecting the producer and consumer services.
- Maven build structure and dependencies (the .mvn wrapper and pom.xml files) that provide module management and build configuration.

##### Interactions and Data Flow
- An external client (or user interface / API consumer) sending booking requests to the Producer service (running on port 8080).
- The Producer microservice processes these requests and, using its messaging service (e.g., MessagingService, RQueueMessagingService), publishes messages to a RabbitMQ exchange/queue.
- The Consumer microservice, configured with RabbitMqConfig, listens on that same queue for incoming messages.
- Upon receiving a message, the Consumer service processes it, persists booking information (via BookingRepository) possibly in a database, and may perform additional tasks like logging/auditing using AuditService.
- Both microservices use the shared DTOs from the Service Contract module for unified data representation.

##### Architectural Patterns and Principles
- Microservices Architecture: Two independent, interconnected services that communicate asynchronously via a message broker.
- API Gateway/Controller Pattern: The Producer service exposes REST endpoints.
- Messaging/Queue-based Integration: Using RabbitMQ as the intermediary to decouple the services.
- Shared Contract Pattern: The Service Contract module ensures both services use the same data models, reducing integration errors.
- Configuration Management: Externalized configuration with a common application.yml file ensures consistent settings between services.

##### Relevant Technologies and Frameworks
- Spring Boot (implied by the structure and naming conventions in Java packages)
- RabbitMQ (seen by the multiple RabbitMqConfig classes in both services)
- JPA for persistence (JpaConfig & BookingRepository)
- Maven for project management (pom.xml files, mvnw scripts)
- Swagger (for API documentation in the producer service)
- Possibly Orika for object mapping (in the consumer service’s utils package)

##### Essential Architectural Elements
- Every element listed above is included and clearly labeled.
- Integration points like the RabbitMQ message broker and the shared DTO contract module.
- Be detailed in indicating the ports used for each microservice and the primary configuration files they rely on.

## Diagram (Mermaid)

```mermaid
flowchart TD
    ExternalClient("External Client"):::external

    subgraph "Producer Microservice (Port 8080)"
        direction TB
        PC_BC["Booking Controller (REST)"]:::microservice
        PC_SW["Swagger Config"]:::microservice
        PC_GE["Global Exception Handling"]:::microservice
        PC_MS["Messaging Service"]:::microservice
        PC_RMQ["Producer RabbitMQ Config"]:::microservice
    end

    RabbitMQ["RabbitMQ Broker"]:::messaging

    subgraph "Consumer Microservice (Port 8100)"
        direction TB
        CC_RMQ["Message Listener (RabbitMQ Config)"]:::microservice
        CC_JPA["JPA Config"]:::microservice
        CC_BR["Booking Repository"]:::microservice
        CC_AUD["Audit Service"]:::microservice
        CC_AUD2["Print Audit Service"]:::microservice
    end

    Shared["Booking Service Contract (DTOs)"]:::shared

    ExternalConfigProducer["Producer application.yml"]:::config
    ExternalConfigConsumer["Consumer application.yml"]:::config

    Maven["Maven Build Config"]:::maven

    %% Interactions
    ExternalClient -->|"RESTcall"| PC_BC
    PC_BC -->|"uses"| PC_SW
    PC_BC -->|"uses"| PC_GE
    PC_BC -->|"publishes_to"| PC_MS
    PC_MS -->|"configured_by"| PC_RMQ
    PC_RMQ -->|"sends_message"| RabbitMQ
    RabbitMQ -->|"delivers_message"| CC_RMQ
    CC_RMQ -->|"invokes"| CC_JPA
    CC_JPA -->|"triggers"| CC_BR
    CC_BR -->|"processes_data"| CC_AUD
    CC_BR -->|"logs"| CC_AUD2

    %% Shared DTO connections
    PC_BC ---|"DTOs"| Shared
    PC_SW ---|"DTOs"| Shared
    PC_GE ---|"DTOs"| Shared
    PC_MS ---|"DTOs"| Shared
    PC_RMQ ---|"DTOs"| Shared
    CC_RMQ ---|"DTOs"| Shared
    CC_JPA ---|"DTOs"| Shared
    CC_BR ---|"DTOs"| Shared
    CC_AUD ---|"DTOs"| Shared
    CC_AUD2 ---|"DTOs"| Shared

    %% Externalized configuration links
    ExternalConfigProducer ---|"config"| PC_BC
    ExternalConfigProducer ---|"config"| PC_MS
    ExternalConfigConsumer ---|"config"| CC_RMQ
    ExternalConfigConsumer ---|"config"| CC_JPA

    %% Maven build links
    Maven ---|"build"| PC_BC
    Maven ---|"build"| CC_JPA

    %% Class Definitions for styling
    classDef microservice fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef external fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef messaging fill:#FFCC00,stroke:#000,stroke-width:1px;
    classDef shared fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef config fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef maven fill:#FFB6C1,stroke:#000,stroke-width:1px;

click PC_BC "https://github.com/olantobi/ride-booking-service/blob/master/booking-producer-service/src/main/java/mt/com/ecabs/booking/producer/controller/BookingController.java"
click PC_SW "https://github.com/olantobi/ride-booking-service/blob/master/booking-producer-service/src/main/java/mt/com/ecabs/booking/producer/config/SwaggerConfiguration.java"
click PC_GE "https://github.com/olantobi/ride-booking-service/blob/master/booking-producer-service/src/main/java/mt/com/ecabs/booking/producer/exception/GlobalExceptionHandler.java"
click PC_MS "https://github.com/olantobi/ride-booking-service/blob/master/booking-producer-service/src/main/java/mt/com/ecabs/booking/producer/service/RQueueMessagingService.java"
click PC_RMQ "https://github.com/olantobi/ride-booking-service/blob/master/booking-producer-service/src/main/java/mt/com/ecabs/booking/producer/config/RabbitMqConfig.java"

click CC_RMQ "https://github.com/olantobi/ride-booking-service/blob/master/booking-consumer-service/src/main/java/mt/com/ecabs/booking/consumer/config/RabbitMqConfig.java"
click CC_JPA "https://github.com/olantobi/ride-booking-service/blob/master/booking-consumer-service/src/main/java/mt/com/ecabs/booking/consumer/config/JpaConfig.java"
click CC_BR "https://github.com/olantobi/ride-booking-service/blob/master/booking-consumer-service/src/main/java/mt/com/ecabs/booking/consumer/repository/BookingRepository.java"
click CC_AUD "https://github.com/olantobi/ride-booking-service/blob/master/booking-consumer-service/src/main/java/mt/com/ecabs/booking/consumer/service/AuditService.java"
click CC_AUD2 "https://github.com/olantobi/ride-booking-service/blob/master/booking-consumer-service/src/main/java/mt/com/ecabs/booking/consumer/service/PrintAuditService.java"

click Shared "https://github.com/olantobi/ride-booking-service/tree/master/booking-service-contract/src/main/java/mt/com/ecabs/booking/dto"

click ExternalConfigProducer "https://github.com/olantobi/ride-booking-service/blob/master/booking-producer-service/src/main/resources/application.yml"
click ExternalConfigConsumer "https://github.com/olantobi/ride-booking-service/blob/master/booking-consumer-service/src/main/resources/application.yml"

click Maven "https://github.com/olantobi/ride-booking-service/blob/master/booking-producer-service/pom.xml"
```
