# renan20553/baixar_nfse_portal_nacional architecture

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

- Interactive diagram: https://gitdiagram.com/renan20553/baixar_nfse_portal_nacional
- Repository: https://github.com/renan20553/baixar_nfse_portal_nacional

## Overview

A desktop Tkinter application downloads NFS-e XMLs and event documents from Brazil’s ADN API using a PFX client certificate. The user configures the target CNPJ, environment and output settings, starts or stops a download, and receives saved files and logs; NSU checkpoints support resumption. The main workflow is visible in the README and sampled entry-point/downloader code. Some filename-generation details and other UI behavior were not fully sampled, so those relationships rely on documented behavior rather than inferred implementation.

Main entry points: [`download_nfse.py`](https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/download_nfse.py) (Tkinter application), [`nfse/downloader.py`](https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/nfse/downloader.py) (Download coordinator), [`nfse/config.py`](https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/nfse/config.py) (Config model), [`nfse/selftest.py`](https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/nfse/selftest.py) (Local self-test)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_app["Tkinter application<br/>[download_nfse.py]"]
  node_about["About and license<br/>[download_nfse.py]"]
  node_license["License text<br/>[license_text.py]"]
  node_version["Version metadata<br/>[version.py]"]
end

subgraph group_download["Download workflow"]
  node_downloader["Download coordinator<br/>[downloader.py]"]
  node_certificate["PFX certificate"]
  node_adn{{"ADN API"}}
  node_distribution["NSU distribution<br/>[downloader.py]"]
  node_xml_files["XML and event files"]
  node_logs["Download logs"]
  node_selftest["Local self-test<br/>[selftest.py]"]
end

subgraph group_settings["Configuration and state"]
  node_config_file["Configuration file<br/>[config.json]"]
  node_config["Config model<br/>[config.py]"]
  node_checkpoint["NSU checkpoint<br/>[downloader.py]"]
end

node_user(("User"))

node_user -->|"operates"| node_app
node_app -->|"loads settings"| node_config_file
node_app -->|"validates and saves"| node_config
node_config -->|"reads and writes"| node_config_file
node_app -->|"starts download"| node_downloader
node_downloader -->|"uses settings"| node_config
node_downloader -->|"converts PFX"| node_certificate
node_downloader -->|"requests batches"| node_adn
node_downloader -->|"processes responses"| node_distribution
node_distribution -->|"updates next NSU"| node_checkpoint
node_distribution -->|"saves documents"| node_xml_files
node_downloader -->|"records activity"| node_logs
node_user -->|"opens details"| node_about
node_about -->|"displays text"| node_license
node_app -->|"shows version"| node_version
node_app -->|"dispatches diagnostic"| node_selftest
node_selftest -->|"tests conversion"| node_certificate

click node_app "https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/download_nfse.py"
click node_about "https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/download_nfse.py"
click node_license "https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/license_text.py"
click node_config_file "https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/config.json"
click node_config "https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/nfse/config.py"
click node_downloader "https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/nfse/downloader.py"
click node_distribution "https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/nfse/downloader.py"
click node_checkpoint "https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/nfse/downloader.py"
click node_selftest "https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/nfse/selftest.py"
click node_version "https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/version.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_app,node_about,node_license,node_version,node_user toneBlue
class node_downloader,node_certificate,node_adn,node_distribution,node_xml_files,node_logs,node_selftest toneAmber
class node_config_file,node_config,node_checkpoint toneMint
```

## Components

### User interface

- [Tkinter application](https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/download_nfse.py): `download_nfse.py`
- [About and license](https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/download_nfse.py): `download_nfse.py`
- [License text](https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/license_text.py): `license_text.py`
- [Version metadata](https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/version.py): `version.py`

### Download workflow

- [Download coordinator](https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/nfse/downloader.py): `nfse/downloader.py`
- **PFX certificate**
- **ADN API**
- [NSU distribution](https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/nfse/downloader.py): `nfse/downloader.py`
- **XML and event files**
- **Download logs**
- [Local self-test](https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/nfse/selftest.py): `nfse/selftest.py`

### Configuration and state

- [Configuration file](https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/config.json): `config.json`
- [Config model](https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/nfse/config.py): `nfse/config.py`
- [NSU checkpoint](https://github.com/renan20553/baixar_nfse_portal_nacional/blob/main/nfse/downloader.py): `nfse/downloader.py`

### Other components

- **User**

## Connections

- User → Tkinter application: operates (evidence: `README.md`)
- Tkinter application → Configuration file: loads settings (evidence: `download_nfse.py`)
- Tkinter application → Config model: validates and saves (evidence: `download_nfse.py`)
- Config model → Configuration file: reads and writes (evidence: `nfse/config.py`)
- Tkinter application → Download coordinator: starts download (evidence: `download_nfse.py`)
- Download coordinator → Config model: uses settings (evidence: `nfse/downloader.py`)
- Download coordinator → PFX certificate: converts PFX (evidence: `nfse/downloader.py`)
- Download coordinator → ADN API: requests batches (evidence: `nfse/downloader.py`)
- Download coordinator → NSU distribution: processes responses (evidence: `nfse/downloader.py`)
- NSU distribution → NSU checkpoint: updates next NSU (evidence: `nfse/downloader.py`)
- NSU distribution → XML and event files: saves documents (evidence: `README.md`)
- Download coordinator → Download logs: records activity (evidence: `nfse/downloader.py`)
- User → About and license: opens details (evidence: `README.md`)
- About and license → License text: displays text (evidence: `download_nfse.py`)
- Tkinter application → Version metadata: shows version (evidence: `download_nfse.py`)
- Tkinter application → Local self-test: dispatches diagnostic (evidence: `download_nfse.py`)
- Local self-test → PFX certificate: tests conversion (evidence: `nfse/selftest.py`)
