# omarelbeggar/microservices-project architecture

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

- Interactive diagram: https://gitdiagram.com/omarelbeggar/microservices-project
- Repository: https://github.com/omarelbeggar/microservices-project

## Overview

##### Project Type and Purpose
- This is a microservices-based system.
- The project includes four key microservices: Client-SERVICE, Commande-SERVICE, Discovery-SERVICE, and Gateway-SERVICE.
- The README tells you that the services communicate via RESTTEMPLATE (HTTP REST calls) and that there are two databases (Postgres) used by two of the services. In the client database (clientdb), there is a “client” table, and in the commande database (commandedb), there is a “commande” table.
- Each microservice is structured as a Maven project with its own configuration, controllers, service layers, and repositories, indicating a typical layered architecture.

##### Analyzing the File Structure for Architectural Patterns
- Each service (e.g., client-service, commande-service) has a similar Maven-based file structure indicating separation of concerns:
- /src/main/java contains controllers, business objects (bo), configurations, DTOs, services, mappers, repositories, and sometimes exception handlers.
- /src/main/resources holds configuration files (notably, application.properties with DB connections).
- The project also includes test directories, build files, and helper scripts (mvnw, mvnw.cmd) that ensure consistency in builds.
- There is also an external directory in both microservices that might indicate outbound REST calls (e.g., to exchange data with other services).

- Main Components – include:
- Client-SERVICE: Manages clients, containing its own MVC-like structure (Controller, BO, DTO, Service, Repository, and external communication objects).
- Commande-SERVICE: Manages orders (commande), similarly structured to deal with business operations.
- Discovery-SERVICE: Likely acts as a service registry (e.g., Eureka, if assumed by naming) to enable service discovery within the microservices ecosystem.
- Gateway-SERVICE: Acts as the API gateway that routes requests to appropriate services and handles cross-cutting concerns (like authentication, load balancing, etc.).
- Databases: Representing two distinct Postgres DB instances, one for clientdb (with a “client” table) and one for commandedb (with a “commande” table).
- Relationships and Interactions:
- The Gateway-SERVICE forwards incoming requests from clients to the respective microservice.
- The microservices (Client-SERVICE and Commande-SERVICE) communicate among each other using RESTTEMPLATE calls.
- Discovery-SERVICE enables the microservices to register themselves as available and to discover other services to call.
- Each microservice connects to its designated database using configurations from application.properties.
- Important Architectural Highlights:
- Microservices architecture with service discovery and an API gateway.
- A layered structure in each service (Controller, Service, Repository, etc.).
- Communication using synchronous HTTP REST calls (via RESTTEMPLATE).
- Database separation between services ensuring data encapsulation.
- Use of Maven for builds and standard Java project structure.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Global Microservices
    gw["Gateway-SERVICE"]:::microservice
    ds["Discovery-SERVICE"]:::microservice

    %% Gateway and Discovery Connections
    gw -->|"RoutesRequest"| cs
    gw -->|"RoutesRequest"| cms
    gw -->|"register/discover"| ds

    %% Client-SERVICE Subgraph
    subgraph "Client-SERVICE"
        cs["Client-SERVICE"]:::microservice
        cs_ctrl["Controller"]:::layer
        cs_service["ServiceLayer"]:::layer
        cs_repo["Repository"]:::layer
        cs_conf["Configuration"]:::layer
        cs --> cs_ctrl
        cs_ctrl --> cs_service
        cs_service --> cs_repo
        cs_repo -.-> cs_conf
    end

    %% Client Database
    client_db["Client DB (client table)"]:::database
    cs_conf -->|"JDBC/ORM"| client_db

    %% Commande-SERVICE Subgraph
    subgraph "Commande-SERVICE"
        cms["Commande-SERVICE"]:::microservice
        cms_ctrl["Controller"]:::layer
        cms_service["ServiceLayer"]:::layer
        cms_repo["Repository"]:::layer
        cms_conf["Configuration"]:::layer
        cms --> cms_ctrl
        cms_ctrl --> cms_service
        cms_service --> cms_repo
        cms_repo -.-> cms_conf
    end

    %% Commande Database
    commandedb["Commande DB (commande table)"]:::database
    cms_conf -->|"JDBC/ORM"| commandedb

    %% Inter-service Communication via RESTTEMPLATE
    cs -->|"RESTCall(RESTTEMPLATE)"| cms
    cms -->|"RESTCall(RESTTEMPLATE)"| cs

    %% Service Discovery Registrations
    cs -->|"register/discover"| ds
    cms -->|"register/discover"| ds

    %% Styles
    classDef microservice fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef layer fill:#D5F5E3,stroke:#27AE60,stroke-width:1px;

    %% Click Events
    click gw "https://github.com/omarelbeggar/microservices-project/blob/main/gateway-service/src/main/java/ma/fstm/ilisi/gateway_service/GatewayServiceApplication.java"
    click ds "https://github.com/omarelbeggar/microservices-project/blob/main/discovery-service/src/main/java/ma/fstm/ilisi/discovery_service/DiscoveryServiceApplication.java"
    click cs "https://github.com/omarelbeggar/microservices-project/blob/main/client-service/src/main/java/ma/fstm/ilisi/client_service/ClientServiceApplication.java"
    click cs_conf "https://github.com/omarelbeggar/microservices-project/blob/main/client-service/src/main/resources/application.properties"
    click cms "https://github.com/omarelbeggar/microservices-project/blob/main/commande-service/src/main/java/ma/fstm/ilisi/commande_service/CommandeServiceApplication.java"
    click cms_conf "https://github.com/omarelbeggar/microservices-project/blob/main/commande-service/src/main/resources/application.properties"
```
