# lufelip3/autopreco-nfe architecture

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

- Interactive diagram: https://gitdiagram.com/lufelip3/autopreco-nfe
- Repository: https://github.com/lufelip3/autopreco-nfe

## Overview

AutoPreço NFe is a desktop tool for updating Bling product costs and prices from invoice XML and an exported inventory CSV. Its main workflow is to preview or link invoice items, match them to inventory products, calculate updated costs and prices, and export only changed rows for reimport. The graph preserves documented matching, variation, pricing, and stock features. The GUI source is listed in the tree but was not excerpted, so its internal wiring is shown only where documented; sampled logic confirms the GUI calls the business logic.

Main entry points: [`logica_nfe.py`](https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py) (Product matching), [`processar_custos.pyw`](https://github.com/lufelip3/autopreco-nfe/blob/main/processar_custos.pyw) (Desktop GUI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_gui["Desktop GUI"]
  node_preview["Invoice preview"]
  node_assorted_link["Assorted-item links"]
end

subgraph group_invoice["Invoice processing"]
  node_xml["Invoice XML"]
  node_invoice_parse["XML parsing<br/>[logica_nfe.py]"]
  node_cost_calc["Cost calculation<br/>[logica_nfe.py]"]
  node_price_calc["Price strategies<br/>[logica_nfe.py]"]
end

subgraph group_catalog["Catalog updates"]
  node_inventory_csv["Inventory CSV"]
  node_matching["Product matching<br/>[logica_nfe.py]"]
  node_variant_update["Parent variations<br/>[logica_nfe.py]"]
  node_price_decision["Price threshold<br/>[logica_nfe.py]"]
  node_stock_update["Stock update<br/>[logica_nfe.py]"]
  node_risk_alert["Stock risk alert<br/>[logica_nfe.py]"]
end

subgraph group_export["Bling exchange"]
  node_lean_export["Changed-item export<br/>[logica_nfe.py]"]
  node_updated_csv["Updated CSV"]
end

node_user(("User"))
node_bling(("Bling ERP"))

node_user -->|"operates"| node_gui
node_gui -->|"calls logic"| node_invoice_parse
node_user -->|"previews items"| node_preview
node_preview -->|"reads"| node_xml
node_user -->|"sets links"| node_assorted_link
node_assorted_link -->|"prioritizes links"| node_matching
node_xml -->|"provides data"| node_invoice_parse
node_invoice_parse -->|"provides products"| node_matching
node_inventory_csv -->|"provides catalog"| node_matching
node_matching -->|"supplies matched items"| node_cost_calc
node_cost_calc -->|"supplies real cost"| node_price_calc
node_price_calc -->|"proposes price"| node_price_decision
node_price_decision -->|"requests decision"| node_gui
node_matching -->|"updates parent"| node_variant_update
node_matching -->|"adds quantity"| node_stock_update
node_price_calc -->|"alerts on increase"| node_risk_alert
node_matching -->|"selects changed items"| node_lean_export
node_variant_update -->|"includes updated parents"| node_lean_export
node_stock_update -->|"includes changed rows"| node_lean_export
node_lean_export -->|"writes"| node_updated_csv
node_updated_csv -->|"reimported into"| node_bling
node_inventory_csv -->|"selected by user"| node_gui

click node_gui "https://github.com/lufelip3/autopreco-nfe/blob/main/processar_custos.pyw"
click node_preview "https://github.com/lufelip3/autopreco-nfe/blob/main/processar_custos.pyw"
click node_assorted_link "https://github.com/lufelip3/autopreco-nfe/blob/main/processar_custos.pyw"
click node_invoice_parse "https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py"
click node_cost_calc "https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py"
click node_price_calc "https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py"
click node_matching "https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py"
click node_variant_update "https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py"
click node_price_decision "https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py"
click node_stock_update "https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py"
click node_risk_alert "https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py"
click node_lean_export "https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py"

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_gui,node_preview,node_assorted_link,node_user toneBlue
class node_xml,node_invoice_parse,node_cost_calc,node_price_calc toneAmber
class node_inventory_csv,node_matching,node_variant_update,node_price_decision,node_stock_update,node_risk_alert toneMint
class node_lean_export,node_updated_csv toneRose
class node_bling toneIndigo
```

## Components

### User interface

- [Desktop GUI](https://github.com/lufelip3/autopreco-nfe/blob/main/processar_custos.pyw): `processar_custos.pyw`
- [Invoice preview](https://github.com/lufelip3/autopreco-nfe/blob/main/processar_custos.pyw): `processar_custos.pyw`
- [Assorted-item links](https://github.com/lufelip3/autopreco-nfe/blob/main/processar_custos.pyw): `processar_custos.pyw`

### Invoice processing

- **Invoice XML**
- [XML parsing](https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py): `logica_nfe.py`
- [Cost calculation](https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py): `logica_nfe.py`
- [Price strategies](https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py): `logica_nfe.py`

### Catalog updates

- **Inventory CSV**
- [Product matching](https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py): `logica_nfe.py`
- [Parent variations](https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py): `logica_nfe.py`
- [Price threshold](https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py): `logica_nfe.py`
- [Stock update](https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py): `logica_nfe.py`
- [Stock risk alert](https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py): `logica_nfe.py`

### Bling exchange

- [Changed-item export](https://github.com/lufelip3/autopreco-nfe/blob/main/logica_nfe.py): `logica_nfe.py`
- **Updated CSV**

### Other components

- **User**
- **Bling ERP**

## Connections

- User → Desktop GUI: operates (evidence: `README.md`)
- Desktop GUI → XML parsing: calls logic (evidence: `logica_nfe.py`)
- User → Invoice preview: previews items (evidence: `README.md`)
- Invoice preview → Invoice XML: reads (evidence: `README.md`)
- User → Assorted-item links: sets links (evidence: `README.md`)
- Assorted-item links → Product matching: prioritizes links (evidence: `logica_nfe.py`)
- Invoice XML → XML parsing: provides data (evidence: `README.md`)
- XML parsing → Product matching: provides products (evidence: `README.md`)
- Inventory CSV → Product matching: provides catalog (evidence: `README.md`)
- Product matching → Cost calculation: supplies matched items (evidence: `README.md`)
- Cost calculation → Price strategies: supplies real cost (evidence: `logica_nfe.py`)
- Price strategies → Price threshold: proposes price (evidence: `README.md`)
- Price threshold → Desktop GUI: requests decision (evidence: `README.md`)
- Product matching → Parent variations: updates parent (evidence: `README.md`)
- Product matching → Stock update: adds quantity (evidence: `logica_nfe.py`)
- Price strategies → Stock risk alert: alerts on increase (evidence: `README.md`)
- Product matching → Changed-item export: selects changed items (evidence: `README.md`)
- Parent variations → Changed-item export: includes updated parents (evidence: `README.md`)
- Stock update → Changed-item export: includes changed rows (evidence: `README.md`)
- Changed-item export → Updated CSV: writes (evidence: `README.md`)
- Updated CSV → Bling ERP: reimported into (evidence: `README.md`)
- Inventory CSV → Desktop GUI: selected by user (evidence: `README.md`)
