# nfephp-org/sped-nfe architecture

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

- Interactive diagram: https://gitdiagram.com/nfephp-org/sped-nfe
- Repository: https://github.com/nfephp-org/sped-nfe

## Overview

SPED-NFE is a PHP library for creating and communicating Brazilian NF-e/NFC-e fiscal documents with authorizing SEFAZ services. The main workflow is application input into the document builder, followed by signing and transmission; SEFAZ returns the authorization response. The builder’s trait-based tag families cover document identity, parties, items, taxes and totals. Communication includes service selection and contingency support. Edges reflect README statements or relationships named in the source index; unsampled implementation details are not assumed.

Main entry points: [`src/Make.php`](https://github.com/nfephp-org/sped-nfe/blob/master/src/Make.php) (NF-e builder), [`src/Tools.php`](https://github.com/nfephp-org/sped-nfe/blob/master/src/Tools.php) (SEFAZ operations), [`src/Common/Tools.php`](https://github.com/nfephp-org/sped-nfe/blob/master/src/Common/Tools.php) (Signing and config), [`src/Common/Standardize.php`](https://github.com/nfephp-org/sped-nfe/blob/master/src/Common/Standardize.php) (Response standardization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_document["Document construction"]
  node_make["NF-e builder<br/>[Make.php]"]
  node_identity["Identity and parties"]
  node_items["Items and products"]
  node_tax["Tax details"]
  node_totals["Document totals<br/>[TraitTagTotal.php]"]
end

subgraph group_communication["SEFAZ communication"]
  node_sign["Signing and config<br/>[Tools.php]"]
  node_api["SEFAZ operations<br/>[Tools.php]"]
  node_services["Service selection<br/>[Webservices.php]"]
  node_contingency["Contingency modes<br/>[Contingency.php]"]
end

subgraph group_support["Shared support"]
  node_calculation["Fiscal calculations"]
  node_validation["Input validation<br/>[ValidTXT.php]"]
end

subgraph group_response["Parsing and response"]
  node_standardize["Response standardization<br/>[Standardize.php]"]
  node_parser["Document parser<br/>[Parser.php]"]
  node_complements["Document complements<br/>[Complements.php]"]
end

node_app(("Client application"))
node_sefaz{{"SEFAZ services"}}

node_app -->|"builds"| node_make
node_make -->|"uses tags"| node_identity
node_make -->|"uses tags"| node_items
node_make -->|"uses tags"| node_tax
node_make -->|"uses tags"| node_totals
node_make -->|"signed by"| node_sign
node_sign -->|"sent through"| node_api
node_api -->|"transmits to"| node_sefaz
node_api -->|"selects service"| node_services
node_api -->|"checks mode"| node_contingency
node_make -->|"uses calculations"| node_calculation
node_sefaz -.->|"returns response"| node_standardize
node_standardize -.->|"normalizes for"| node_parser

click node_make "https://github.com/nfephp-org/sped-nfe/blob/master/src/Make.php"
click node_identity "https://github.com/nfephp-org/sped-nfe/tree/master/src/Traits"
click node_items "https://github.com/nfephp-org/sped-nfe/tree/master/src/Traits"
click node_tax "https://github.com/nfephp-org/sped-nfe/tree/master/src/Traits"
click node_totals "https://github.com/nfephp-org/sped-nfe/blob/master/src/Traits/TraitTagTotal.php"
click node_sign "https://github.com/nfephp-org/sped-nfe/blob/master/src/Common/Tools.php"
click node_api "https://github.com/nfephp-org/sped-nfe/blob/master/src/Tools.php"
click node_services "https://github.com/nfephp-org/sped-nfe/blob/master/src/Common/Webservices.php"
click node_contingency "https://github.com/nfephp-org/sped-nfe/blob/master/src/Factories/Contingency.php"
click node_calculation "https://github.com/nfephp-org/sped-nfe/blob/master/src/Traits/TraitCalculations.php"
click node_validation "https://github.com/nfephp-org/sped-nfe/blob/master/src/Common/ValidTXT.php"
click node_standardize "https://github.com/nfephp-org/sped-nfe/blob/master/src/Common/Standardize.php"
click node_parser "https://github.com/nfephp-org/sped-nfe/blob/master/src/Factories/Parser.php"
click node_complements "https://github.com/nfephp-org/sped-nfe/blob/master/src/Complements.php"

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_make,node_identity,node_items,node_tax,node_totals,node_app toneBlue
class node_sign,node_api,node_services,node_contingency toneAmber
class node_calculation,node_validation toneMint
class node_standardize,node_parser,node_complements toneRose
class node_sefaz toneIndigo
```

## Components

### Document construction

- [NF-e builder](https://github.com/nfephp-org/sped-nfe/blob/master/src/Make.php): `src/Make.php`
- [Identity and parties](https://github.com/nfephp-org/sped-nfe/tree/master/src/Traits): `src/Traits`
- [Items and products](https://github.com/nfephp-org/sped-nfe/tree/master/src/Traits): `src/Traits`
- [Tax details](https://github.com/nfephp-org/sped-nfe/tree/master/src/Traits): `src/Traits`
- [Document totals](https://github.com/nfephp-org/sped-nfe/blob/master/src/Traits/TraitTagTotal.php): `src/Traits/TraitTagTotal.php`

### SEFAZ communication

- [Signing and config](https://github.com/nfephp-org/sped-nfe/blob/master/src/Common/Tools.php): `src/Common/Tools.php`
- [SEFAZ operations](https://github.com/nfephp-org/sped-nfe/blob/master/src/Tools.php): `src/Tools.php`
- [Service selection](https://github.com/nfephp-org/sped-nfe/blob/master/src/Common/Webservices.php): `src/Common/Webservices.php`
- [Contingency modes](https://github.com/nfephp-org/sped-nfe/blob/master/src/Factories/Contingency.php): `src/Factories/Contingency.php`

### Shared support

- [Fiscal calculations](https://github.com/nfephp-org/sped-nfe/blob/master/src/Traits/TraitCalculations.php): `src/Traits/TraitCalculations.php`
- [Input validation](https://github.com/nfephp-org/sped-nfe/blob/master/src/Common/ValidTXT.php): `src/Common/ValidTXT.php`

### Parsing and response

- [Response standardization](https://github.com/nfephp-org/sped-nfe/blob/master/src/Common/Standardize.php): `src/Common/Standardize.php`
- [Document parser](https://github.com/nfephp-org/sped-nfe/blob/master/src/Factories/Parser.php): `src/Factories/Parser.php`
- [Document complements](https://github.com/nfephp-org/sped-nfe/blob/master/src/Complements.php): `src/Complements.php`

### Other components

- **Client application**
- **SEFAZ services**

## Connections

- Client application → NF-e builder: builds (evidence: `README.md`)
- NF-e builder → Identity and parties: uses tags (evidence: `src/Make.php`)
- NF-e builder → Items and products: uses tags (evidence: `src/Make.php`)
- NF-e builder → Tax details: uses tags (evidence: `src/Make.php`)
- NF-e builder → Document totals: uses tags (evidence: `src/Make.php`)
- NF-e builder → Signing and config: signed by (evidence: `README.md`)
- Signing and config → SEFAZ operations: sent through (evidence: `README.md`)
- SEFAZ operations → SEFAZ services: transmits to (evidence: `README.md`)
- SEFAZ operations → Service selection: selects service (evidence: `src/Tools.php`)
- SEFAZ operations → Contingency modes: checks mode (evidence: `src/Tools.php`)
- NF-e builder → Fiscal calculations: uses calculations (evidence: `src/Make.php`)
- SEFAZ services → Response standardization: returns response
- Response standardization → Document parser: normalizes for
