# sergiosousacode/mcp_farma architecture

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

- Interactive diagram: https://gitdiagram.com/sergiosousacode/mcp_farma
- Repository: https://github.com/sergiosousacode/mcp_farma

## Overview

MCP Farma is a pharmacy-catalog backend. The main demonstrated workflow accepts product search or availability requests, queries product, price and stock data, and returns REST responses; a separate CSV workflow validates rows, records import outcomes and errors, and updates catalog data. The tree and excerpts also show read-only MCP tools and a public-catalog controller. The README describes some of these as future work, so the graph follows the sampled implementation where available; unsampled wiring is not inferred.

Main entry points: [`backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoService.java`](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoService.java) (CSV processing), [`backend/src/main/java/br/com/mcpfarma/produto/ProdutoController.java`](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/produto/ProdutoController.java) (Product endpoints), [`backend/src/main/java/br/com/mcpfarma/importacao/ProdutoImportacaoService.java`](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/ProdutoImportacaoService.java) (Product import), [`backend/src/main/java/br/com/mcpfarma/produto/ProdutoRepository.java`](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/produto/ProdutoRepository.java) (Product repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_catalog["Catalog API"]
  node_product_api["Product endpoints"]
  node_product_query["Product queries"]
  node_public_catalog["Public catalog"]
  node_availability["Availability DTO"]
end

subgraph group_import["Catalog Import"]
  node_import_api["Import endpoints"]
  node_csv_import["CSV processing"]
  node_product_import["Product import"]
  node_gtin["GTIN validation<br/>[GtinValidator.java]"]
  node_import_result["Import result"]
  node_import_record["Import record<br/>[Importacao.java]"]
  node_import_error["Import errors"]
  node_import_repo["Import repositories"]
  node_error_repo["Error repository"]
end

subgraph group_data["Catalog Data"]
  node_product["Product entity<br/>[Produto.java]"]
  node_product_repo["Product repository"]
  node_price["Price entity<br/>[Preco.java]"]
  node_price_repo["Price repository"]
  node_stock["Stock entity<br/>[Estoque.java]"]
  node_stock_repo["Stock repository"]
end

subgraph group_integrations["Interfaces"]
  node_mcp_config["MCP registration"]
  node_mcp_tools["Product MCP tools"]
end

node_client(("API client"))

node_client -->|"requests"| node_product_api
node_product_api -->|"queries"| node_product_repo
node_product_api -->|"delegates"| node_product_query
node_product_api -->|"reads prices"| node_price_repo
node_product_api -->|"reads stock"| node_stock_repo
node_product_api -->|"returns"| node_availability
node_product_query -->|"queries"| node_product_repo
node_public_catalog -->|"queries"| node_product_repo
node_client -->|"uploads CSV"| node_import_api
node_import_api -->|"delegates"| node_csv_import
node_import_api -->|"reads history"| node_import_repo
node_import_api -->|"reads errors"| node_error_repo
node_csv_import -->|"imports rows"| node_product_import
node_csv_import -->|"saves status"| node_import_repo
node_csv_import -->|"saves errors"| node_error_repo
node_csv_import -->|"returns"| node_import_result
node_csv_import -->|"tracks run"| node_import_record
node_csv_import -->|"records failures"| node_import_error
node_product_import -->|"validates code"| node_gtin
node_product_import -->|"saves product"| node_product_repo
node_product_import -->|"saves price"| node_price_repo
node_product_import -->|"saves stock"| node_stock_repo
node_product_repo -->|"persists"| node_product
node_price_repo -->|"persists"| node_price
node_stock_repo -->|"persists"| node_stock
node_import_repo -->|"persists"| node_import_record
node_error_repo -->|"persists"| node_import_error
node_mcp_config -->|"registers"| node_mcp_tools
node_mcp_tools -->|"delegates"| node_product_query

click node_product_api "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/produto/ProdutoController.java"
click node_product_query "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/produto/ProdutoConsultaService.java"
click node_public_catalog "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/produto/CatalogoPublicoController.java"
click node_availability "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/produto/dto/ProdutoDisponibilidadeDTO.java"
click node_import_api "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoController.java"
click node_csv_import "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoService.java"
click node_product_import "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/ProdutoImportacaoService.java"
click node_gtin "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/GtinValidator.java"
click node_import_result "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/dto/ImportacaoResultadoDTO.java"
click node_import_record "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/Importacao.java"
click node_import_error "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoErro.java"
click node_import_repo "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoRepository.java"
click node_error_repo "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoErroRepository.java"
click node_product "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/produto/Produto.java"
click node_product_repo "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/produto/ProdutoRepository.java"
click node_price "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/preco/Preco.java"
click node_price_repo "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/preco/PrecoRepository.java"
click node_stock "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/estoque/Estoque.java"
click node_stock_repo "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/estoque/EstoqueRepository.java"
click node_mcp_config "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/mcp/McpToolsConfig.java"
click node_mcp_tools "https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/mcp/ProdutoMcpTools.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_product_api,node_product_query,node_public_catalog,node_availability,node_client toneBlue
class node_import_api,node_csv_import,node_product_import,node_gtin,node_import_result,node_import_record,node_import_error,node_import_repo,node_error_repo toneAmber
class node_product,node_product_repo,node_price,node_price_repo,node_stock,node_stock_repo toneMint
class node_mcp_config,node_mcp_tools toneRose
```

## Components

### Catalog API

- [Product endpoints](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/produto/ProdutoController.java): `backend/src/main/java/br/com/mcpfarma/produto/ProdutoController.java`
- [Product queries](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/produto/ProdutoConsultaService.java): `backend/src/main/java/br/com/mcpfarma/produto/ProdutoConsultaService.java`
- [Public catalog](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/produto/CatalogoPublicoController.java): `backend/src/main/java/br/com/mcpfarma/produto/CatalogoPublicoController.java`
- [Availability DTO](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/produto/dto/ProdutoDisponibilidadeDTO.java): `backend/src/main/java/br/com/mcpfarma/produto/dto/ProdutoDisponibilidadeDTO.java`

### Catalog Import

- [Import endpoints](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoController.java): `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoController.java`
- [CSV processing](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoService.java): `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoService.java`
- [Product import](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/ProdutoImportacaoService.java): `backend/src/main/java/br/com/mcpfarma/importacao/ProdutoImportacaoService.java`
- [GTIN validation](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/GtinValidator.java): `backend/src/main/java/br/com/mcpfarma/importacao/GtinValidator.java`
- [Import result](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/dto/ImportacaoResultadoDTO.java): `backend/src/main/java/br/com/mcpfarma/importacao/dto/ImportacaoResultadoDTO.java`
- [Import record](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/Importacao.java): `backend/src/main/java/br/com/mcpfarma/importacao/Importacao.java`
- [Import errors](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoErro.java): `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoErro.java`
- [Import repositories](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoRepository.java): `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoRepository.java`
- [Error repository](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoErroRepository.java): `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoErroRepository.java`

### Catalog Data

- [Product entity](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/produto/Produto.java): `backend/src/main/java/br/com/mcpfarma/produto/Produto.java`
- [Product repository](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/produto/ProdutoRepository.java): `backend/src/main/java/br/com/mcpfarma/produto/ProdutoRepository.java`
- [Price entity](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/preco/Preco.java): `backend/src/main/java/br/com/mcpfarma/preco/Preco.java`
- [Price repository](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/preco/PrecoRepository.java): `backend/src/main/java/br/com/mcpfarma/preco/PrecoRepository.java`
- [Stock entity](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/estoque/Estoque.java): `backend/src/main/java/br/com/mcpfarma/estoque/Estoque.java`
- [Stock repository](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/estoque/EstoqueRepository.java): `backend/src/main/java/br/com/mcpfarma/estoque/EstoqueRepository.java`

### Interfaces

- [MCP registration](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/mcp/McpToolsConfig.java): `backend/src/main/java/br/com/mcpfarma/mcp/McpToolsConfig.java`
- [Product MCP tools](https://github.com/sergiosousacode/mcp_farma/blob/main/backend/src/main/java/br/com/mcpfarma/mcp/ProdutoMcpTools.java): `backend/src/main/java/br/com/mcpfarma/mcp/ProdutoMcpTools.java`

### Other components

- **API client**

## Connections

- API client → Product endpoints: requests (evidence: `README.md`)
- Product endpoints → Product repository: queries (evidence: `backend/src/main/java/br/com/mcpfarma/produto/ProdutoController.java`)
- Product endpoints → Product queries: delegates (evidence: `backend/src/main/java/br/com/mcpfarma/produto/ProdutoController.java`)
- Product endpoints → Price repository: reads prices (evidence: `backend/src/main/java/br/com/mcpfarma/produto/ProdutoController.java`)
- Product endpoints → Stock repository: reads stock (evidence: `backend/src/main/java/br/com/mcpfarma/produto/ProdutoController.java`)
- Product endpoints → Availability DTO: returns (evidence: `backend/src/main/java/br/com/mcpfarma/produto/ProdutoController.java`)
- Product queries → Product repository: queries (evidence: `backend/src/main/java/br/com/mcpfarma/produto/ProdutoConsultaService.java`)
- Public catalog → Product repository: queries (evidence: `backend/src/main/java/br/com/mcpfarma/produto/CatalogoPublicoController.java`)
- API client → Import endpoints: uploads CSV (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoController.java`)
- Import endpoints → CSV processing: delegates (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoController.java`)
- Import endpoints → Import repositories: reads history (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoController.java`)
- Import endpoints → Error repository: reads errors (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoController.java`)
- CSV processing → Product import: imports rows (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoService.java`)
- CSV processing → Import repositories: saves status (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoService.java`)
- CSV processing → Error repository: saves errors (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoService.java`)
- CSV processing → Import result: returns (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoService.java`)
- CSV processing → Import record: tracks run (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoService.java`)
- CSV processing → Import errors: records failures (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoService.java`)
- Product import → GTIN validation: validates code (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ProdutoImportacaoService.java`)
- Product import → Product repository: saves product (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ProdutoImportacaoService.java`)
- Product import → Price repository: saves price (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ProdutoImportacaoService.java`)
- Product import → Stock repository: saves stock (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ProdutoImportacaoService.java`)
- Product repository → Product entity: persists (evidence: `backend/src/main/java/br/com/mcpfarma/produto/ProdutoRepository.java`)
- Price repository → Price entity: persists (evidence: `backend/src/main/java/br/com/mcpfarma/preco/PrecoRepository.java`)
- Stock repository → Stock entity: persists (evidence: `backend/src/main/java/br/com/mcpfarma/estoque/EstoqueRepository.java`)
- Import repositories → Import record: persists (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoRepository.java`)
- Error repository → Import errors: persists (evidence: `backend/src/main/java/br/com/mcpfarma/importacao/ImportacaoErroRepository.java`)
- MCP registration → Product MCP tools: registers (evidence: `backend/src/main/java/br/com/mcpfarma/mcp/McpToolsConfig.java`)
- Product MCP tools → Product queries: delegates (evidence: `backend/src/main/java/br/com/mcpfarma/mcp/ProdutoMcpTools.java`)
