# gamrikamal/t-delivery architecture

> Architecture diagram of the GitHub repository gamrikamal/t-delivery, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gamrikamal/t-delivery
- Repository: https://github.com/gamrikamal/t-delivery

## Overview

- Microservices: Each service should be shown as a separate component. For example:
- auth-service (JWT authentication, token generation, and proxy to user-service)
- courier-service (manages courier order assignments and caching)
- discovery-service (Eureka server for service registration and discovery)
- gateway-service (API gateway for routing, load balancing, and JWT verification)
- menu-service (handles restaurant menu delivery via MongoDB)
- message-service (processes messages from Kafka and sends emails)
- order-service (processes orders, integrates with PostGIS for geodata, and serves a web-socket-enabled UI)
- route-service (calculates optimal routes and distances using Google Maps API)
- user-service (manages user data and roles stored in PostgreSQL)

- Databases and external resource integrations:
- PostgreSQL (order-service, user-service, route-service for geodata via PostGIS)
- MongoDB (menu-service)
- Kafka (message-service and inter-service event messaging)
- External APIs (Google Maps API for route-service)

- The gateway-service channels incoming requests to the appropriate microservice (auth, order, menu, etc.).
- Internal service-to-service communications should be depicted: for instance, auth-service calling user-service for authentication, order-service interacting with route-service (and in turn Google Maps API), as well as outbound message flows going to Kafka for message-service consumption.
- Data flows from services to the databases (e.g., order-service to PostgreSQL, menu-service to MongoDB).

##### Architectural patterns used
- Microservices architecture: Highlight that each service is independently deployable (using Docker) and communicates over HTTP or messaging (Kafka).
- API Gateway: Illustrate the pattern with a gateway at the front that manages concerns like authentication (token verification via JWT) and request routing.
- Service Discovery: Indicate the role of discovery-service (Eureka) in enabling dynamic service registration and discovery.
- Event-driven communication: Represent Kafka as a central messaging backbone for asynchronous messaging (primarily used by the message-service).

##### Technological stack details
- Next to each component, note the foundational technologies. For example:
- auth-service, order-service, etc. use Spring Boot.
- Gateway and Discovery are built on Spring Cloud.
- Databases are represented by PostgreSQL (enhanced with PostGIS) and MongoDB.
- Use Docker symbols to denote containerized deployment.
- Kafka as the messaging broker.
- External integrations (Google Maps API) for route calculations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Gateway & Service Discovery Layer
    subgraph "API Gateway & Service Discovery"
        GatewayService["gateway-service\n(Spring Cloud, JWT)"]:::infra
        DiscoveryService["discovery-service\n(Eureka)"]:::infra
    end

    %% Core Microservices Layer
    subgraph "Core Microservices"
        AuthService["auth-service\n(Spring Boot, JWT)"]:::micro
        CourierService["courier-service\n(Spring Boot, Caching)"]:::micro
        MenuService["menu-service\n(Spring Boot, MongoDB)"]:::micro
        MessageService["message-service\n(Spring Boot, Kafka)"]:::micro
        OrderService["order-service\n(Spring Boot, WebSocket, PostGIS)"]:::micro
        RouteService["route-service\n(Spring Boot, Google Maps API)"]:::micro
        UserService["user-service\n(Spring Boot, PostgreSQL)"]:::micro
    end

    %% Data Stores & External Integrations Layer
    subgraph "Data Stores & External Integrations"
        Postgres["PostgreSQL/PostGIS"]:::database
        Mongo["MongoDB"]:::database
        Kafka["Kafka Broker"]:::database
        GoogleMaps["Google Maps API"]:::external
    end

    %% Gateway routes incoming requests to microservices
    GatewayService -->|"routes"| AuthService
    GatewayService -->|"routes"| CourierService
    GatewayService -->|"routes"| MenuService
    GatewayService -->|"routes"| MessageService
    GatewayService -->|"routes"| OrderService
    GatewayService -->|"routes"| RouteService
    GatewayService -->|"routes"| UserService

    %% Service Discovery bi-directional registration with microservices
    AuthService <-->|"register"| DiscoveryService
    CourierService <-->|"register"| DiscoveryService
    MenuService <-->|"register"| DiscoveryService
    MessageService <-->|"register"| DiscoveryService
    OrderService <-->|"register"| DiscoveryService
    RouteService <-->|"register"| DiscoveryService
    UserService <-->|"register"| DiscoveryService

    %% Internal Service-to-Service Interactions
    AuthService -->|"calls"| UserService
    OrderService -->|"request_route"| RouteService
    OrderService -->|"send_event"| Kafka
    Kafka -->|"consume_event"| MessageService
    RouteService -->|"map_call"| GoogleMaps

    %% Data Flows to Databases
    OrderService -->|"store_order"| Postgres
    UserService -->|"store_user"| Postgres
    RouteService -->|"store_geodata"| Postgres
    MenuService -->|"store_menu"| Mongo

    %% Styles
    classDef infra fill:#fdfd96,stroke:#333,stroke-width:2px;
    classDef micro fill:#bfd8f2,stroke:#333,stroke-width:2px;
    classDef database fill:#ffb3ba,stroke:#333,stroke-width:2px;
    classDef external fill:#caffbf,stroke:#333,stroke-width:2px;

    %% Click Events
    click AuthService "https://github.com/gamrikamal/t-delivery/tree/master/auth-service/"
    click CourierService "https://github.com/gamrikamal/t-delivery/tree/master/courier-service/"
    click DiscoveryService "https://github.com/gamrikamal/t-delivery/tree/master/discovery-service/"
    click GatewayService "https://github.com/gamrikamal/t-delivery/tree/master/gateway-service/"
    click MenuService "https://github.com/gamrikamal/t-delivery/tree/master/menu-service/"
    click MessageService "https://github.com/gamrikamal/t-delivery/tree/master/message-service/"
    click OrderService "https://github.com/gamrikamal/t-delivery/tree/master/order-service/"
    click RouteService "https://github.com/gamrikamal/t-delivery/tree/master/route-service/"
    click UserService "https://github.com/gamrikamal/t-delivery/tree/master/user-service/"
```
