# matheusfeq/compdistribuida architecture

> Architecture diagram of the GitHub repository matheusfeq/compdistribuida, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/matheusfeq/compdistribuida
- Repository: https://github.com/matheusfeq/compdistribuida

## Overview

DistriCommerce is a distributed retail/wholesale e-commerce system. Customers browse the tiered-price catalog, authenticate, and check out; Pedidos calculates pricing and freight and starts a Kafka-coordinated saga through stock reservation and asynchronous payment. Admins manage catalog, orders, and payment-gateway settings; customers can track delivery as logistics bridges Kafka events and MQTT vehicle telemetry. The frontend also supports accounts and order history. Edges reflect README-documented service relationships and the sampled calls; unsampled routing and persistence details are not expanded.

Main entry points: [`backend/services/api-gateway/src/main/java/com/br/unifor/districommerce/gateway`](https://github.com/matheusfeq/compdistribuida/tree/main/backend/services/api-gateway/src/main/java/com/br/unifor/districommerce/gateway) (API gateway), [`frontend/src/app/App.tsx`](https://github.com/matheusfeq/compdistribuida/blob/main/frontend/src/app/App.tsx) (React application), [`backend/services/pagamentos/src/main/java/com/br/unifor/districommerce/pagamentos/services/PagamentoService.java`](https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/pagamentos/src/main/java/com/br/unifor/districommerce/pagamentos/services/PagamentoService.java) (Async payment worker), [`backend/services/logistica/src/main/java/com/br/unifor/districommerce/logistica/services/LogisticaService.java`](https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/logistica/src/main/java/com/br/unifor/districommerce/logistica/services/LogisticaService.java) (Logistics service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web storefront"]
  node_frontend["React application<br/>[App.tsx]"]
  node_session["Account session<br/>[session.tsx]"]
  node_queries["Shared API queries<br/>[sharedQueries.ts]"]
  node_catalog_ui["Catalog and checkout<br/>[useCheckout.ts]"]
  node_admin_ui["Admin console<br/>[AdminPage.tsx]"]
  node_orders_ui["Orders and tracking UI<br/>[OrdersPage.tsx]"]
end

subgraph group_identity_catalog["Identity and catalog"]
  node_gateway["API gateway"]
  node_users["Users and auth"]
  node_products["Product catalog"]
  node_csv_import["CSV product import"]
end

subgraph group_commerce["Commerce saga"]
  node_orders["Order and checkout service<br/>[PedidoService.java]"]
  node_stock["Stock reservations"]
  node_payments["Async payment worker"]
end

subgraph group_delivery["Delivery tracking"]
  node_logistics["Logistics service"]
  node_iot_sim["Truck simulator<br/>[simulador.py]"]
end

subgraph group_integrations["Messaging and payment"]
  node_kafka["Apache Kafka"]
  node_mqtt["MQTT broker"]
  node_payment_gateway["Simulated payment gateway"]
  node_database[("PostgreSQL service schemas")]
end

node_customer(("Customer or admin"))

node_customer -->|"uses"| node_frontend
node_frontend -->|"provides session"| node_session
node_frontend -->|"renders checkout"| node_catalog_ui
node_frontend -->|"renders admin"| node_admin_ui
node_frontend -->|"renders orders"| node_orders_ui
node_session -->|"loads account"| node_gateway
node_catalog_ui -->|"reads catalog"| node_queries
node_queries -->|"requests API"| node_gateway
node_admin_ui -->|"manages commerce"| node_gateway
node_orders_ui -->|"loads orders"| node_gateway
node_gateway -->|"routes requests"| node_users
node_gateway -->|"routes requests"| node_products
node_gateway -->|"routes checkout"| node_orders
node_gateway -->|"routes inventory"| node_stock
node_gateway -->|"routes payment admin"| node_payments
node_gateway -->|"routes tracking"| node_logistics
node_orders -->|"fetches products"| node_products
node_orders -->|"publishes saga events"| node_kafka
node_kafka -->|"delivers order events"| node_stock
node_stock -->|"publishes stock events"| node_kafka
node_kafka -->|"delivers stock events"| node_payments
node_payments -->|"charges asynchronously"| node_payment_gateway
node_payments -->|"publishes payment events"| node_kafka
node_orders -.->|"persists orders"| node_database
node_stock -.->|"persists reservations"| node_database
node_payments -.->|"persists transactions"| node_database
node_products -.->|"persists catalog"| node_database
node_users -.->|"persists accounts"| node_database
node_csv_import -->|"creates catalog items"| node_products
node_kafka -->|"delivers dispatch events"| node_logistics
node_logistics -->|"bridges telemetry"| node_mqtt
node_iot_sim -->|"publishes vehicle data"| node_mqtt
node_logistics -->|"publishes delivery events"| node_kafka
node_logistics -.->|"stores tracking data"| node_database

click node_frontend "https://github.com/matheusfeq/compdistribuida/blob/main/frontend/src/app/App.tsx"
click node_session "https://github.com/matheusfeq/compdistribuida/blob/main/frontend/src/shared/state/session.tsx"
click node_queries "https://github.com/matheusfeq/compdistribuida/blob/main/frontend/src/shared/api/sharedQueries.ts"
click node_catalog_ui "https://github.com/matheusfeq/compdistribuida/blob/main/frontend/src/features/checkout/hooks/useCheckout.ts"
click node_admin_ui "https://github.com/matheusfeq/compdistribuida/blob/main/frontend/src/features/admin/pages/AdminPage.tsx"
click node_orders_ui "https://github.com/matheusfeq/compdistribuida/blob/main/frontend/src/features/orders/pages/OrdersPage.tsx"
click node_gateway "https://github.com/matheusfeq/compdistribuida/tree/main/backend/services/api-gateway/src/main/java/com/br/unifor/districommerce/gateway"
click node_users "https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/usuarios/src/main/java/com/br/unifor/districommerce/usuarios/services/UsuarioService.java"
click node_products "https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/produtos/src/main/java/com/br/unifor/districommerce/produtos/services/ProdutoService.java"
click node_csv_import "https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/produtos/src/main/java/com/br/unifor/districommerce/produtos/services/ImportacaoProdutoService.java"
click node_orders "https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/pedidos/src/main/java/com/br/unifor/districommerce/pedidos/services/PedidoService.java"
click node_stock "https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/estoque/src/main/java/com/br/unifor/districommerce/estoque/services/EstoqueService.java"
click node_payments "https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/pagamentos/src/main/java/com/br/unifor/districommerce/pagamentos/services/PagamentoService.java"
click node_logistics "https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/logistica/src/main/java/com/br/unifor/districommerce/logistica/services/LogisticaService.java"
click node_iot_sim "https://github.com/matheusfeq/compdistribuida/blob/main/backend/iot-simulador/simulador.py"
click node_payment_gateway "https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/gateway-pagamento/src/main/java/com/br/unifor/districommerce/gatewaypagamento/services/CobrancaService.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_frontend,node_session,node_queries,node_catalog_ui,node_admin_ui,node_orders_ui toneBlue
class node_gateway,node_users,node_products,node_csv_import toneAmber
class node_orders,node_stock,node_payments toneMint
class node_logistics,node_iot_sim toneRose
class node_kafka,node_mqtt,node_payment_gateway,node_database,node_customer toneIndigo
```

## Components

### Web storefront

- [React application](https://github.com/matheusfeq/compdistribuida/blob/main/frontend/src/app/App.tsx): `frontend/src/app/App.tsx`
- [Account session](https://github.com/matheusfeq/compdistribuida/blob/main/frontend/src/shared/state/session.tsx): `frontend/src/shared/state/session.tsx`
- [Shared API queries](https://github.com/matheusfeq/compdistribuida/blob/main/frontend/src/shared/api/sharedQueries.ts): `frontend/src/shared/api/sharedQueries.ts`
- [Catalog and checkout](https://github.com/matheusfeq/compdistribuida/blob/main/frontend/src/features/checkout/hooks/useCheckout.ts): `frontend/src/features/checkout/hooks/useCheckout.ts`
- [Admin console](https://github.com/matheusfeq/compdistribuida/blob/main/frontend/src/features/admin/pages/AdminPage.tsx): `frontend/src/features/admin/pages/AdminPage.tsx`
- [Orders and tracking UI](https://github.com/matheusfeq/compdistribuida/blob/main/frontend/src/features/orders/pages/OrdersPage.tsx): `frontend/src/features/orders/pages/OrdersPage.tsx`

### Identity and catalog

- [API gateway](https://github.com/matheusfeq/compdistribuida/tree/main/backend/services/api-gateway/src/main/java/com/br/unifor/districommerce/gateway): `backend/services/api-gateway/src/main/java/com/br/unifor/districommerce/gateway`
- [Users and auth](https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/usuarios/src/main/java/com/br/unifor/districommerce/usuarios/services/UsuarioService.java): `backend/services/usuarios/src/main/java/com/br/unifor/districommerce/usuarios/services/UsuarioService.java`
- [Product catalog](https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/produtos/src/main/java/com/br/unifor/districommerce/produtos/services/ProdutoService.java): `backend/services/produtos/src/main/java/com/br/unifor/districommerce/produtos/services/ProdutoService.java`
- [CSV product import](https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/produtos/src/main/java/com/br/unifor/districommerce/produtos/services/ImportacaoProdutoService.java): `backend/services/produtos/src/main/java/com/br/unifor/districommerce/produtos/services/ImportacaoProdutoService.java`

### Commerce saga

- [Order and checkout service](https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/pedidos/src/main/java/com/br/unifor/districommerce/pedidos/services/PedidoService.java): `backend/services/pedidos/src/main/java/com/br/unifor/districommerce/pedidos/services/PedidoService.java`
- [Stock reservations](https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/estoque/src/main/java/com/br/unifor/districommerce/estoque/services/EstoqueService.java): `backend/services/estoque/src/main/java/com/br/unifor/districommerce/estoque/services/EstoqueService.java`
- [Async payment worker](https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/pagamentos/src/main/java/com/br/unifor/districommerce/pagamentos/services/PagamentoService.java): `backend/services/pagamentos/src/main/java/com/br/unifor/districommerce/pagamentos/services/PagamentoService.java`

### Delivery tracking

- [Logistics service](https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/logistica/src/main/java/com/br/unifor/districommerce/logistica/services/LogisticaService.java): `backend/services/logistica/src/main/java/com/br/unifor/districommerce/logistica/services/LogisticaService.java`
- [Truck simulator](https://github.com/matheusfeq/compdistribuida/blob/main/backend/iot-simulador/simulador.py): `backend/iot-simulador/simulador.py`

### Messaging and payment

- **Apache Kafka**
- **MQTT broker**
- [Simulated payment gateway](https://github.com/matheusfeq/compdistribuida/blob/main/backend/services/gateway-pagamento/src/main/java/com/br/unifor/districommerce/gatewaypagamento/services/CobrancaService.java): `backend/services/gateway-pagamento/src/main/java/com/br/unifor/districommerce/gatewaypagamento/services/CobrancaService.java`
- **PostgreSQL service schemas**

### Other components

- **Customer or admin**

## Connections

- Customer or admin → React application: uses (evidence: `README.md`)
- React application → Account session: provides session (evidence: `frontend/src/app/App.tsx`)
- React application → Catalog and checkout: renders checkout (evidence: `frontend/src/app/App.tsx`)
- React application → Admin console: renders admin (evidence: `frontend/src/app/App.tsx`)
- React application → Orders and tracking UI: renders orders (evidence: `frontend/src/app/App.tsx`)
- Account session → API gateway: loads account (evidence: `frontend/src/shared/state/session.tsx`)
- Catalog and checkout → Shared API queries: reads catalog (evidence: `frontend/src/features/checkout/hooks/useCheckout.ts`)
- Shared API queries → API gateway: requests API (evidence: `frontend/src/shared/api/sharedQueries.ts`)
- Admin console → API gateway: manages commerce (evidence: `README.md`)
- Orders and tracking UI → API gateway: loads orders (evidence: `README.md`)
- API gateway → Users and auth: routes requests (evidence: `README.md`)
- API gateway → Product catalog: routes requests (evidence: `README.md`)
- API gateway → Order and checkout service: routes checkout (evidence: `README.md`)
- API gateway → Stock reservations: routes inventory (evidence: `README.md`)
- API gateway → Async payment worker: routes payment admin (evidence: `README.md`)
- API gateway → Logistics service: routes tracking (evidence: `README.md`)
- Order and checkout service → Product catalog: fetches products (evidence: `backend/services/pedidos/src/main/java/com/br/unifor/districommerce/pedidos/services/PedidoService.java`)
- Order and checkout service → Apache Kafka: publishes saga events (evidence: `backend/services/pedidos/src/main/java/com/br/unifor/districommerce/pedidos/services/PedidoService.java`)
- Apache Kafka → Stock reservations: delivers order events (evidence: `README.md`)
- Stock reservations → Apache Kafka: publishes stock events (evidence: `backend/services/estoque/src/main/java/com/br/unifor/districommerce/estoque/services/EstoqueService.java`)
- Apache Kafka → Async payment worker: delivers stock events (evidence: `backend/services/pagamentos/src/main/java/com/br/unifor/districommerce/pagamentos/services/PagamentoService.java`)
- Async payment worker → Simulated payment gateway: charges asynchronously (evidence: `backend/services/pagamentos/src/main/java/com/br/unifor/districommerce/pagamentos/services/PagamentoService.java`)
- Async payment worker → Apache Kafka: publishes payment events (evidence: `backend/services/pagamentos/src/main/java/com/br/unifor/districommerce/pagamentos/services/PagamentoService.java`)
- Order and checkout service → PostgreSQL service schemas: persists orders (evidence: `README.md`)
- Stock reservations → PostgreSQL service schemas: persists reservations (evidence: `README.md`)
- Async payment worker → PostgreSQL service schemas: persists transactions (evidence: `README.md`)
- Product catalog → PostgreSQL service schemas: persists catalog (evidence: `README.md`)
- Users and auth → PostgreSQL service schemas: persists accounts (evidence: `README.md`)
- CSV product import → Product catalog: creates catalog items (evidence: `backend/services/produtos/src/main/java/com/br/unifor/districommerce/produtos/services/ImportacaoProdutoService.java`)
- Apache Kafka → Logistics service: delivers dispatch events (evidence: `README.md`)
- Logistics service → MQTT broker: bridges telemetry (evidence: `README.md`)
- Truck simulator → MQTT broker: publishes vehicle data (evidence: `README.md`)
- Logistics service → Apache Kafka: publishes delivery events (evidence: `backend/services/logistica/src/main/java/com/br/unifor/districommerce/logistica/services/LogisticaService.java`)
- Logistics service → PostgreSQL service schemas: stores tracking data (evidence: `README.md`)
