# drfaelsan/emissor-lote architecture

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

- Interactive diagram: https://gitdiagram.com/drfaelsan/emissor-lote
- Repository: https://github.com/drfaelsan/emissor-lote

## Overview

NEO-e is a Windows desktop application for fiscal-document synchronization, XML organization, received-document manifestation, and value reconciliation. Its documented primary workflow downloads NFS-e using an A1 certificate, resumes from persisted per-company NSU state, stores documents idempotently, and confirms progress after storage. A related workflow indexes received XMLs, supports reviewed manifestation events, and records outcomes; reconciliation prioritizes exact keys and progressively looser matches. The README describes planned behavior, while sampled code confirms selected domain entities and infrastructure components; manifestation orchestration and reconciliation implementation are not established by the excerpts.

Main entry points: [`src/NEO-e.Application/UseCases/SyncUseCases.cs`](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Application/UseCases/SyncUseCases.cs) (Synchronization use case), [`src/NEO-e.App/App.xaml.cs`](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.App/App.xaml.cs) (Application startup), [`src/NEO-e.Domain/Entities/DocumentoFiscal.cs`](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Domain/Entities/DocumentoFiscal.cs) (Fiscal document), [`src/NEO-e.Application/UseCases/CertificateUseCases.cs`](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Application/UseCases/CertificateUseCases.cs) (Certificate use cases)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop experience"]
  node_ui["WPF interface"]
  node_startup["Application startup<br/>[App.xaml.cs]"]
end

subgraph group_application["Application workflows"]
  node_sync["Synchronization use case<br/>[SyncUseCases.cs]"]
  node_certuse["Certificate use cases"]
  node_contracts["Application contracts<br/>[Interfaces.cs]"]
end

subgraph group_domain["Fiscal domain"]
  node_company["Company state<br/>[Empresa.cs]"]
  node_syncstate["Sync progress"]
  node_fiscaldoc["Fiscal document<br/>[DocumentoFiscal.cs]"]
  node_receiveddoc["Received document"]
end

subgraph group_infrastructure["Local and external services"]
  node_settings["Environment settings<br/>[AppSettings.cs]"]
  node_certstore["A1 certificates"]
  node_adn["ADN distribution API<br/>[AdnHttpClient.cs]"]
  node_xmlparser["NFS-e XML parser<br/>[NfseXmlParser.cs]"]
  node_xmlwriter["Atomic XML writer"]
  node_nsustore[("NSU repository")]
  node_docstore[("Document repository")]
  node_gaps[("NSU gap analysis")]
  node_receivedstore[("Received-document repository")]
  node_adnman["ADN manifestation client"]
  node_sefazman["SEFAZ manifestation client"]
  node_export["Spreadsheet export"]
end

node_user(("Local operator"))

node_user -->|"operates"| node_ui
node_ui -.->|"starts sync"| node_sync
node_startup -->|"shows window"| node_ui
node_startup -->|"loads settings"| node_settings
node_startup -->|"registers"| node_certuse
node_startup -->|"registers"| node_sync
node_startup -->|"configures services"| node_contracts
node_sync -->|"syncs per company"| node_company
node_sync -->|"tracks progress"| node_syncstate
node_sync -->|"uses interfaces"| node_contracts
node_certuse -->|"uses company"| node_company
node_certuse -->|"uses interfaces"| node_contracts
node_sync -->|"loads certificate"| node_certstore
node_sync -->|"requests documents"| node_adn
node_sync -->|"reads and confirms NSU"| node_nsustore
node_sync -->|"decodes documents"| node_xmlparser
node_sync -->|"stores XML"| node_xmlwriter
node_sync -->|"stores idempotently"| node_docstore
node_adn -.->|"returns fiscal data"| node_fiscaldoc
node_xmlparser -->|"parses into"| node_fiscaldoc
node_xmlwriter -->|"writes XML for"| node_fiscaldoc
node_docstore -->|"persists"| node_fiscaldoc
node_nsustore -->|"persists progress"| node_syncstate
node_gaps -->|"analyzes gaps"| node_fiscaldoc
node_user -.->|"provides received XML"| node_receivedstore
node_receivedstore -->|"indexes records"| node_receiveddoc
node_user -.->|"requests reviewed event"| node_adnman
node_user -.->|"sends reviewed event"| node_sefazman
node_receivedstore -.->|"exports received data"| node_export

click node_ui "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.App/ViewModels/MainWindowViewModel.cs"
click node_startup "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.App/App.xaml.cs"
click node_sync "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Application/UseCases/SyncUseCases.cs"
click node_certuse "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Application/UseCases/CertificateUseCases.cs"
click node_contracts "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Application/Contracts/Interfaces.cs"
click node_company "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Domain/Entities/Empresa.cs"
click node_syncstate "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Domain/Entities/EstadoSincronizacao.cs"
click node_fiscaldoc "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Domain/Entities/DocumentoFiscal.cs"
click node_receiveddoc "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Domain/Entities/DocumentoRecebido.cs"
click node_settings "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Configuration/AppSettings.cs"
click node_certstore "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Certificates/CertificateRepository.cs"
click node_adn "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Http/AdnHttpClient.cs"
click node_xmlparser "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Parsers/NfseXmlParser.cs"
click node_xmlwriter "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/FileSystem/AtomicXmlFileWriter.cs"
click node_nsustore "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Persistence/SqliteNsuRepository.cs"
click node_docstore "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Persistence/SqliteDocumentRepository.cs"
click node_gaps "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Persistence/SqliteGapAnalyzer.cs"
click node_receivedstore "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Persistence/SqliteReceivedDocumentRepository.cs"
click node_adnman "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Http/AdnManifestationClient.cs"
click node_sefazman "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Http/SefazManifestationClient.cs"
click node_export "https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Export/ClosedXmlExcelExporter.cs"

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_ui,node_startup toneBlue
class node_sync,node_certuse,node_contracts toneAmber
class node_company,node_syncstate,node_fiscaldoc,node_receiveddoc toneMint
class node_settings,node_certstore,node_adn,node_xmlparser,node_xmlwriter,node_nsustore,node_docstore,node_gaps,node_receivedstore,node_adnman,node_sefazman,node_export toneRose
class node_user toneIndigo
```

## Components

### Desktop experience

- [WPF interface](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.App/ViewModels/MainWindowViewModel.cs): `src/NEO-e.App/ViewModels/MainWindowViewModel.cs`
- [Application startup](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.App/App.xaml.cs): `src/NEO-e.App/App.xaml.cs`

### Application workflows

- [Synchronization use case](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Application/UseCases/SyncUseCases.cs): `src/NEO-e.Application/UseCases/SyncUseCases.cs`
- [Certificate use cases](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Application/UseCases/CertificateUseCases.cs): `src/NEO-e.Application/UseCases/CertificateUseCases.cs`
- [Application contracts](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Application/Contracts/Interfaces.cs): `src/NEO-e.Application/Contracts/Interfaces.cs`

### Fiscal domain

- [Company state](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Domain/Entities/Empresa.cs): `src/NEO-e.Domain/Entities/Empresa.cs`
- [Sync progress](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Domain/Entities/EstadoSincronizacao.cs): `src/NEO-e.Domain/Entities/EstadoSincronizacao.cs`
- [Fiscal document](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Domain/Entities/DocumentoFiscal.cs): `src/NEO-e.Domain/Entities/DocumentoFiscal.cs`
- [Received document](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Domain/Entities/DocumentoRecebido.cs): `src/NEO-e.Domain/Entities/DocumentoRecebido.cs`

### Local and external services

- [Environment settings](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Configuration/AppSettings.cs): `src/NEO-e.Infrastructure/Configuration/AppSettings.cs`
- [A1 certificates](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Certificates/CertificateRepository.cs): `src/NEO-e.Infrastructure/Certificates/CertificateRepository.cs`
- [ADN distribution API](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Http/AdnHttpClient.cs): `src/NEO-e.Infrastructure/Http/AdnHttpClient.cs`
- [NFS-e XML parser](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Parsers/NfseXmlParser.cs): `src/NEO-e.Infrastructure/Parsers/NfseXmlParser.cs`
- [Atomic XML writer](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/FileSystem/AtomicXmlFileWriter.cs): `src/NEO-e.Infrastructure/FileSystem/AtomicXmlFileWriter.cs`
- [NSU repository](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Persistence/SqliteNsuRepository.cs): `src/NEO-e.Infrastructure/Persistence/SqliteNsuRepository.cs`
- [Document repository](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Persistence/SqliteDocumentRepository.cs): `src/NEO-e.Infrastructure/Persistence/SqliteDocumentRepository.cs`
- [NSU gap analysis](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Persistence/SqliteGapAnalyzer.cs): `src/NEO-e.Infrastructure/Persistence/SqliteGapAnalyzer.cs`
- [Received-document repository](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Persistence/SqliteReceivedDocumentRepository.cs): `src/NEO-e.Infrastructure/Persistence/SqliteReceivedDocumentRepository.cs`
- [ADN manifestation client](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Http/AdnManifestationClient.cs): `src/NEO-e.Infrastructure/Http/AdnManifestationClient.cs`
- [SEFAZ manifestation client](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Http/SefazManifestationClient.cs): `src/NEO-e.Infrastructure/Http/SefazManifestationClient.cs`
- [Spreadsheet export](https://github.com/drfaelsan/emissor-lote/blob/main/src/NEO-e.Infrastructure/Export/ClosedXmlExcelExporter.cs): `src/NEO-e.Infrastructure/Export/ClosedXmlExcelExporter.cs`

### Other components

- **Local operator**

## Connections

- Local operator → WPF interface: operates (evidence: `README.md`)
- WPF interface → Synchronization use case: starts sync
- Application startup → WPF interface: shows window (evidence: `src/NEO-e.App/App.xaml.cs`)
- Application startup → Environment settings: loads settings (evidence: `src/NEO-e.App/App.xaml.cs`)
- Application startup → Certificate use cases: registers (evidence: `src/NEO-e.App/App.xaml.cs`)
- Application startup → Synchronization use case: registers (evidence: `src/NEO-e.App/App.xaml.cs`)
- Application startup → Application contracts: configures services (evidence: `src/NEO-e.App/App.xaml.cs`)
- Synchronization use case → Company state: syncs per company (evidence: `src/NEO-e.Application/UseCases/SyncUseCases.cs`)
- Synchronization use case → Sync progress: tracks progress (evidence: `src/NEO-e.Application/UseCases/SyncUseCases.cs`)
- Synchronization use case → Application contracts: uses interfaces (evidence: `src/NEO-e.Application/UseCases/SyncUseCases.cs`)
- Certificate use cases → Company state: uses company (evidence: `src/NEO-e.Application/UseCases/CertificateUseCases.cs`)
- Certificate use cases → Application contracts: uses interfaces (evidence: `src/NEO-e.Application/UseCases/CertificateUseCases.cs`)
- Synchronization use case → A1 certificates: loads certificate (evidence: `README.md`)
- Synchronization use case → ADN distribution API: requests documents (evidence: `README.md`)
- Synchronization use case → NSU repository: reads and confirms NSU (evidence: `README.md`)
- Synchronization use case → NFS-e XML parser: decodes documents (evidence: `README.md`)
- Synchronization use case → Atomic XML writer: stores XML (evidence: `README.md`)
- Synchronization use case → Document repository: stores idempotently (evidence: `README.md`)
- ADN distribution API → Fiscal document: returns fiscal data
- NFS-e XML parser → Fiscal document: parses into (evidence: `src/NEO-e.Infrastructure/Parsers/NfseXmlParser.cs`)
- Atomic XML writer → Fiscal document: writes XML for (evidence: `src/NEO-e.Infrastructure/FileSystem/AtomicXmlFileWriter.cs`)
- Document repository → Fiscal document: persists (evidence: `src/NEO-e.Infrastructure/Persistence/SqliteDocumentRepository.cs`)
- NSU repository → Sync progress: persists progress (evidence: `src/NEO-e.Infrastructure/Persistence/SqliteNsuRepository.cs`)
- NSU gap analysis → Fiscal document: analyzes gaps (evidence: `src/NEO-e.Infrastructure/Persistence/SqliteGapAnalyzer.cs`)
- Local operator → Received-document repository: provides received XML
- Received-document repository → Received document: indexes records (evidence: `src/NEO-e.Infrastructure/Persistence/SqliteReceivedDocumentRepository.cs`)
- Local operator → ADN manifestation client: requests reviewed event
- Local operator → SEFAZ manifestation client: sends reviewed event
- Received-document repository → Spreadsheet export: exports received data
