# rachidatanassat/micro_service architecture

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

- Interactive diagram: https://gitdiagram.com/rachidatanassat/micro_service
- Repository: https://github.com/rachidatanassat/micro_service

## Overview

##### Project Type and Purpose
- This is TP2 from a series of Java EE micro-service exercises.
- It implements a small e-commerce backend: multiple Spring Boot microservices (customer, inventory, order, billing), a Spring Cloud Config server integrating with Consul & Vault, an API Gateway, plus an Angular frontend (“ecom-web-app1”).

##### Top-Level Structure
- TP2/
- config-service (Spring Cloud Config server, backed by Consul & Vault)
- gateway-service (Spring Cloud Gateway)
- customer-service (manages customers, JPA entities + REST)
- inventory-service (manages products, JPA + REST)
- order-service (manages orders, calls customer & inventory via RestClient)
- billing (demonstrates reading config from Consul & Vault via custom config classes)
- ecom-web-app1 (Angular single-page app)

##### Key Components
a. External Clients
- Browser/SPA (Angular app)
b. Edge/API Layer
- API Gateway (routes calls to backend services)
c. Configuration & Secret Management
- Spring Cloud Config Server (“config-service”)
- Consul (configuration registry)
- Vault (secret store)
d. Business Microservices
- Customer Service (REST + JPA → Customer DB)
- Inventory Service (REST + JPA → Product DB)
- Order Service (REST + JPA → Order DB; communicates with Customer + Inventory)
- Billing Service (consumes configuration from Consul & Vault; exposes its own endpoints)
e. Data Stores
- Each microservice has its own relational database (e.g., H2/Postgres)
f. Communication Patterns
- UI ↔ Gateway via HTTP/JSON
- Gateway ↔ each Microservice via HTTP/JSON
- Order Service ↔ Customer Service & Inventory Service via internal REST clients
- Microservices ↔ Config Server via Spring Cloud config protocol (HTTP)
- Config Server ↔ Consul & Vault

##### Relationships and Flows
- From Gateway to each microservice (customer, inventory, order, billing).
- From each microservice to “Config Server” (on startup and refresh).
- From each microservice to its own database.

##### Architectural Patterns and Principles
- Microservices (single responsibility per service, own database)
- API Gateway (central entry point, routing)
- Externalized Configuration (Config Service + Consul + Vault)
- Service-to-Service REST communication
- Separation of concerns (config vs. business logic)

##### Technologies & Frameworks
- Spring Boot, Spring Cloud Config, Spring Cloud Gateway, Spring Data JPA
- Consul (service/config registry), HashiCorp Vault (secrets)
- Angular CLI, TypeScript, RxJS, HTTPClient
- Maven build scripts, application-properties/YAML

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Zone
    subgraph "Frontend Zone"
        UI["Angular SPA\n(UI Layer)"]:::frontend
    end

    %% Edge Zone
    subgraph "Edge Zone"
        Gateway["API Gateway\n(Spring Cloud Gateway)"]:::gateway
    end

    %% Service Zone
    subgraph "Service & Config Zone"
        ConfigServer["Config Service\n(Spring Cloud Config)"]:::config
        Consul["Consul"]:::data
        Vault["Vault"]:::data
        Customer["Customer Service\n(Spring Boot)"]:::service
        Inventory["Inventory Service\n(Spring Boot)"]:::service
        Order["Order Service\n(Spring Boot)"]:::service
        Billing["Billing Service\n(Spring Boot)"]:::service
    end

    %% Data Zone
    subgraph "Data Zone"
        CustDB["Customer DB"]:::db
        InvDB["Inventory DB"]:::db
        OrderDB["Order DB"]:::db
        BillingDB["Billing DB"]:::db
    end

    %% Relationships
    UI -->|"REST/HTTP"| Gateway
    Gateway -->|"REST/HTTP"| Customer
    Gateway -->|"REST/HTTP"| Inventory
    Gateway -->|"REST/HTTP"| Order
    Gateway -->|"REST/HTTP"| Billing

    Order -->|"REST HTTP to Customer"| Customer
    Order -->|"REST HTTP to Inventory"| Inventory

    Customer -->|"Config Pull"| ConfigServer
    Inventory -->|"Config Pull"| ConfigServer
    Order -->|"Config Pull"| ConfigServer
    Billing -->|"Config Pull"| ConfigServer

    ConfigServer -->|"Config"| Consul
    ConfigServer -->|"Secrets"| Vault

    Customer --> CustDB
    Inventory --> InvDB
    Order --> OrderDB
    Billing --> BillingDB

    %% Click Events
    click ConfigServer "https://github.com/rachidatanassat/micro_service/blob/master/TP2/config-service/src/main/java/com/example/config_service/ConfigServiceApplication.java"
    click Gateway "https://github.com/rachidatanassat/micro_service/blob/master/TP2/gateway-service/src/main/java/com/example/gateway_service/GatewayServiceApplication.java"
    click Customer "https://github.com/rachidatanassat/micro_service/blob/master/TP2/customer-service/src/main/java/com/example/customer_service/CustomerServiceApplication.java"
    click Inventory "https://github.com/rachidatanassat/micro_service/blob/master/TP2/inventory-service/src/main/java/com/example/inventory_service/InventoryServiceApplication.java"
    click Order "https://github.com/rachidatanassat/micro_service/blob/master/TP2/order-service/src/main/java/com/example/order_service/OrderServiceApplication.java"
    click Billing "https://github.com/rachidatanassat/micro_service/blob/master/TP2/billing/src/main/java/com/example/billing/BillingApplication.java"
    click UI "https://github.com/rachidatanassat/micro_service/blob/master/TP2/ecom-web-app1/src/app/app.module.ts"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#1e88e5,color:#0d47a1,stroke-width:2px;
    classDef gateway fill:#fff59d,stroke:#fbc02d,color:#f57f17,stroke-width:2px;
    classDef config fill:#ffe0b2,stroke:#fb8c00,color:#e65100,stroke-width:2px;
    classDef service fill:#eeeeee,stroke:#9e9e9e,color:#424242,stroke-width:2px;
    classDef data fill:#c8e6c9,stroke:#43a047,color:#1b5e20,stroke-width:2px;
    classDef db fill:#a5d6a7,stroke:#388e3c,color:#1b5e20,stroke-width:2px;
```
