# jonathan25sam/practica6-sistemas-distribuidos architecture

> Architecture diagram of the GitHub repository jonathan25sam/practica6-sistemas-distribuidos, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jonathan25sam/practica6-sistemas-distribuidos
- Repository: https://github.com/jonathan25sam/practica6-sistemas-distribuidos

## Overview

1. This repository is a small Spring-based microservices system for a franchise business domain, split into four independently runnable modules: `eureka-server`, `api-gateway`, `ms-inventario`, and `ms-ventas`.

2. The architectural center is **service discovery** via **Eureka Server**. Both business services register there, and the Gateway uses the registry to route traffic dynamically instead of hardcoding service addresses.

3. **API Gateway** is the single external entry point on port `8080`. It acts as the front door for clients and forwards requests to backend services based on discovered service instances. The README makes clear that clients should not call the business services directly.

4. **MS-Inventario** is the inventory domain service on port `8082`. Its code structure is a classic Spring Boot layered service: `controller` for HTTP endpoints, `entity` for the domain model, and `repository` for persistence access.

5. The only visible domain entity in inventory is `CorteCarne`, which suggests the service manages a product/catalog-like stock model centered on meat cuts. The repository layer (`CorteCarneRepository`) indicates data access is abstracted behind Spring Data.

6. The inventory service uses an **in-memory H2 database** per the README, so inventory state is volatile and initialized on startup. This makes it a self-contained data source for the sales service to query during runtime.

7. **MS-Ventas** is the sales/orchestration service on port `8083`. Its main role is not persistence but coordination: it exposes a business endpoint and calls inventory internally through `InventarioClient`.

8. `InventarioClient` strongly indicates **OpenFeign** is used for synchronous service-to-service communication. In other words, sales depends on inventory through a service contract, not through direct database access or shared storage.

9. The main business flow described by the repository is: external client calls the Gateway, Gateway routes to `ms-ventas`, and `ms-ventas` then queries `ms-inventario` to assemble the final response. This creates a two-hop request path with the Gateway as the first boundary and Eureka enabling service lookup.

10. The important architectural boundaries are therefore:
   - **Edge boundary:** API Gateway
   - **Discovery boundary:** Eureka Server
   - **Inventory/data boundary:** MS-Inventario with H2 persistence
   - **Orchestration boundary:** MS-Ventas consuming inventory through Feign

11. Startup order matters because discovery must exist before the services and Gateway can register and resolve endpoints. The README explicitly requires starting Eureka first, then inventory, then sales, then the Gateway, followed by a short stabilization delay for registration/heartbeats.

12. From an architecture diagram perspective, the key arrows are: client → Gateway → Sales → Inventory, with both Sales and Inventory also pointing to Eureka for registration/discovery. The only persistent data store in this repo is the embedded H2 database inside inventory; the other modules are stateless services around routing and orchestration.

Main entry points: [`api-gateway/src/main/java/com/franquicia/apigateway/ApiGatewayApplication.java`](https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/api-gateway/src/main/java/com/franquicia/apigateway/ApiGatewayApplication.java) (API Gateway), [`ms-ventas/src/main/java/com/franquicia/msventas/MsVentasApplication.java`](https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-ventas/src/main/java/com/franquicia/msventas/MsVentasApplication.java) (MS Ventas), [`ms-inventario/src/main/java/com/franquicia/msinventario/repository/CorteCarneRepository.java`](https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-inventario/src/main/java/com/franquicia/msinventario/repository/CorteCarneRepository.java) (CorteCarne Repo), [`ms-inventario/src/main/java/com/franquicia/msinventario/controller/CorteCarneController.java`](https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-inventario/src/main/java/com/franquicia/msinventario/controller/CorteCarneController.java) (CorteCarne API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_edge["Edge"]
  node_external_client(("Client<br/>actor"))
  node_api_gateway_app["API Gateway<br/>spring boot app"]
end

subgraph group_discovery["Discovery"]
  node_eureka_server_app["Eureka Server<br/>registry server"]
end

subgraph group_sales["Sales"]
  node_ventas_app["MS Ventas<br/>spring boot app"]
  node_ventas_controller["Ventas API<br/>controller"]
  node_inventario_client["Inventario Client<br/>feign client"]
end

subgraph group_inventory["Inventory"]
  node_inventario_app["MS Inventario<br/>spring boot app"]
  node_inventario_controller["CorteCarne API<br/>controller"]
  node_corte_carne_entity["CorteCarne<br/>entity<br/>[CorteCarne.java]"]
  node_corte_carne_repo["CorteCarne Repo"]
  node_h2_db[("H2 DB<br/>embedded datastore")]
end

node_external_client -->|"requests"| node_api_gateway_app
node_api_gateway_app -.->|"discovers routes"| node_eureka_server_app
node_api_gateway_app -->|"routes to"| node_ventas_app
node_ventas_app -.->|"registers"| node_eureka_server_app
node_inventario_app -.->|"registers"| node_eureka_server_app
node_ventas_controller -->|"delegates"| node_inventario_client
node_inventario_client -->|"calls"| node_inventario_controller
node_inventario_controller -->|"uses"| node_corte_carne_repo
node_corte_carne_repo -->|"maps"| node_corte_carne_entity
node_corte_carne_repo -->|"stores in"| node_h2_db
node_ventas_app -->|"hosts"| node_ventas_controller
node_inventario_app -->|"hosts"| node_inventario_controller

click node_api_gateway_app "https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/api-gateway/src/main/java/com/franquicia/apigateway/ApiGatewayApplication.java"
click node_eureka_server_app "https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/eureka-server/src/main/java/com/franquicia/eurekaserver/EurekaServerApplication.java"
click node_ventas_app "https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-ventas/src/main/java/com/franquicia/msventas/MsVentasApplication.java"
click node_ventas_controller "https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-ventas/src/main/java/com/franquicia/msventas/VentasController.java"
click node_inventario_client "https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-ventas/src/main/java/com/franquicia/msventas/InventarioClient.java"
click node_inventario_app "https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-inventario/src/main/java/com/franquicia/msinventario/MsInventarioApplication.java"
click node_inventario_controller "https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-inventario/src/main/java/com/franquicia/msinventario/controller/CorteCarneController.java"
click node_corte_carne_entity "https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-inventario/src/main/java/com/franquicia/msinventario/entity/CorteCarne.java"
click node_corte_carne_repo "https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-inventario/src/main/java/com/franquicia/msinventario/repository/CorteCarneRepository.java"

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_external_client,node_api_gateway_app toneBlue
class node_eureka_server_app toneAmber
class node_ventas_app,node_ventas_controller,node_inventario_client toneMint
class node_inventario_app,node_inventario_controller,node_corte_carne_entity,node_corte_carne_repo,node_h2_db toneRose
```

## Components

### Edge

External access and routing

- **Client**: actor · Calls the system through the gateway
- [API Gateway](https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/api-gateway/src/main/java/com/franquicia/apigateway/ApiGatewayApplication.java): spring boot app · Single entry point on port 8080 · `api-gateway/src/main/java/com/franquicia/apigateway/ApiGatewayApplication.java`

### Discovery

Service registry and lookup

- [Eureka Server](https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/eureka-server/src/main/java/com/franquicia/eurekaserver/EurekaServerApplication.java): registry server · Service registry for discovery · `eureka-server/src/main/java/com/franquicia/eurekaserver/EurekaServerApplication.java`

### Sales

Order orchestration service

- [MS Ventas](https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-ventas/src/main/java/com/franquicia/msventas/MsVentasApplication.java): spring boot app · Sales/orchestration service on port 8083 · `ms-ventas/src/main/java/com/franquicia/msventas/MsVentasApplication.java`
- [Ventas API](https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-ventas/src/main/java/com/franquicia/msventas/VentasController.java): controller · Business endpoint exposed to clients · `ms-ventas/src/main/java/com/franquicia/msventas/VentasController.java`
- [Inventario Client](https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-ventas/src/main/java/com/franquicia/msventas/InventarioClient.java): feign client · Sync calls into inventory service · `ms-ventas/src/main/java/com/franquicia/msventas/InventarioClient.java`

### Inventory

Stock domain service

- [MS Inventario](https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-inventario/src/main/java/com/franquicia/msinventario/MsInventarioApplication.java): spring boot app · Inventory service on port 8082 · `ms-inventario/src/main/java/com/franquicia/msinventario/MsInventarioApplication.java`
- [CorteCarne API](https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-inventario/src/main/java/com/franquicia/msinventario/controller/CorteCarneController.java): controller · Inventory HTTP endpoints · `ms-inventario/src/main/java/com/franquicia/msinventario/controller/CorteCarneController.java`
- [CorteCarne](https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-inventario/src/main/java/com/franquicia/msinventario/entity/CorteCarne.java): entity · Inventory domain model · `ms-inventario/src/main/java/com/franquicia/msinventario/entity/CorteCarne.java`
- [CorteCarne Repo](https://github.com/jonathan25sam/practica6-sistemas-distribuidos/blob/main/ms-inventario/src/main/java/com/franquicia/msinventario/repository/CorteCarneRepository.java): repository · Spring Data access layer · `ms-inventario/src/main/java/com/franquicia/msinventario/repository/CorteCarneRepository.java`
- **H2 DB**: embedded datastore · In-memory inventory storage

## Connections

- Client → API Gateway: requests · External traffic enters here
- API Gateway → Eureka Server: discovers routes · Gateway resolves backend services via registry
- API Gateway → MS Ventas: routes to · Forwards client traffic to sales service
- MS Ventas → Eureka Server: registers · Sales service joins discovery
- MS Inventario → Eureka Server: registers · Inventory service joins discovery
- Ventas API → Inventario Client: delegates · Controller uses Feign client for inventory lookup
- Inventario Client → CorteCarne API: calls · Feign request to inventory API
- CorteCarne API → CorteCarne Repo: uses · Controller reads/writes through repository
- CorteCarne Repo → CorteCarne: maps · Repository persists the domain entity
- CorteCarne Repo → H2 DB: stores in · Inventory state lives in embedded H2
- MS Ventas → Ventas API: hosts · Application exposes the sales controller
- MS Inventario → CorteCarne API: hosts · Application exposes inventory endpoints
