# nfephp-org/nfephp architecture

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

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

## Overview

NFePHP is a legacy PHP API for Brazilian electronic invoices (NFe), not a stand-alone invoice issuer. An integrating application builds or supplies invoice XML, then uses the API to sign and exchange requests with SEFAZ; the API also handles responses, related operations, email, and document output. The graph emphasizes those runtime responsibilities and shared support. Several subsystem relationships are documented only by the source index or README; unsampled integrations are omitted rather than inferred.

Main entry points: [`libs/NFe/ToolsNFe.php`](https://github.com/nfephp-org/nfephp/blob/master/libs/NFe/ToolsNFe.php) (SEFAZ operations), [`libs/Common/Base/BaseTools.php`](https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Base/BaseTools.php) (Tools foundation), [`libs/NFe/MakeNFe.php`](https://github.com/nfephp-org/nfephp/blob/master/libs/NFe/MakeNFe.php) (NFe builder), [`libs/NFe/IdentifyNFe.php`](https://github.com/nfephp-org/nfephp/blob/master/libs/NFe/IdentifyNFe.php) (NFe identification)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_invoice["Invoice data"]
  node_builder["NFe builder<br/>[MakeNFe.php]"]
  node_converter["NFe converter<br/>[ConvertNFe.php]"]
  node_identity["NFe identification<br/>[IdentifyNFe.php]"]
end

subgraph group_services["SEFAZ services"]
  node_tools["SEFAZ operations<br/>[ToolsNFe.php]"]
  node_responses["Response handling<br/>[ReturnNFe.php]"]
end

subgraph group_common["Shared foundation"]
  node_base_tools["Tools foundation<br/>[BaseTools.php]"]
  node_base_make["XML foundation<br/>[BaseMake.php]"]
  node_config["Configuration<br/>[Configure.php]"]
  node_certificate["Certificate handling<br/>[Pkcs12.php]"]
  node_soap["SOAP transport<br/>[CurlSoap.php]"]
  node_xml["XML utilities<br/>[Dom.php]"]
  node_files["File utilities<br/>[FilesFolders.php]"]
  node_date["Date and time<br/>[DateTime.php]"]
  node_schema["XML validation<br/>[ValidXsd.php]"]
end

subgraph group_output["Documents and delivery"]
  node_mail["NFe email<br/>[MailNFe.php]"]
  node_danfe["DANFE renderer<br/>[Danfe.php]"]
  node_danfce["DANFC-e renderer<br/>[Danfce.php]"]
end

node_issuer(("Issuer application"))
node_sefaz(("SEFAZ"))

node_issuer -->|"builds XML"| node_builder
node_issuer -->|"calls API"| node_tools
node_builder -->|"uses foundation"| node_base_make
node_builder -->|"uses dates"| node_date
node_converter -->|"uses builder"| node_builder
node_tools -->|"extends foundation"| node_base_tools
node_tools -->|"handles replies"| node_responses
node_tools -->|"sends email"| node_mail
node_tools -->|"identifies invoices"| node_identity
node_tools -->|"validates XML"| node_schema
node_tools -->|"creates PDF"| node_danfe
node_base_tools -->|"loads certificate"| node_certificate
node_base_tools -->|"sets timezone"| node_date
node_base_tools -->|"parses XML"| node_xml
node_base_tools -->|"reads files"| node_files
node_base_tools -->|"uses transport"| node_soap
node_responses -->|"uses XML"| node_xml
node_identity -->|"uses file tools"| node_files
node_identity -->|"uses XML"| node_xml
node_sefaz -->|"exchanges messages"| node_tools
node_issuer -.->|"requests print"| node_danfce

click node_builder "https://github.com/nfephp-org/nfephp/blob/master/libs/NFe/MakeNFe.php"
click node_converter "https://github.com/nfephp-org/nfephp/blob/master/libs/NFe/ConvertNFe.php"
click node_identity "https://github.com/nfephp-org/nfephp/blob/master/libs/NFe/IdentifyNFe.php"
click node_tools "https://github.com/nfephp-org/nfephp/blob/master/libs/NFe/ToolsNFe.php"
click node_responses "https://github.com/nfephp-org/nfephp/blob/master/libs/NFe/ReturnNFe.php"
click node_mail "https://github.com/nfephp-org/nfephp/blob/master/libs/NFe/MailNFe.php"
click node_base_tools "https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Base/BaseTools.php"
click node_base_make "https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Base/BaseMake.php"
click node_config "https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Configure/Configure.php"
click node_certificate "https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Certificate/Pkcs12.php"
click node_soap "https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Soap/CurlSoap.php"
click node_xml "https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Dom/Dom.php"
click node_files "https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Files/FilesFolders.php"
click node_date "https://github.com/nfephp-org/nfephp/blob/master/libs/Common/DateTime/DateTime.php"
click node_schema "https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Dom/ValidXsd.php"
click node_danfe "https://github.com/nfephp-org/nfephp/blob/master/libs/Extras/Danfe.php"
click node_danfce "https://github.com/nfephp-org/nfephp/blob/master/libs/Extras/Danfce.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_builder,node_converter,node_identity toneBlue
class node_tools,node_responses toneAmber
class node_base_tools,node_base_make,node_config,node_certificate,node_soap,node_xml,node_files,node_date,node_schema toneMint
class node_mail,node_danfe,node_danfce toneRose
class node_issuer,node_sefaz toneIndigo
```

## Components

### Invoice data

- [NFe builder](https://github.com/nfephp-org/nfephp/blob/master/libs/NFe/MakeNFe.php): `libs/NFe/MakeNFe.php`
- [NFe converter](https://github.com/nfephp-org/nfephp/blob/master/libs/NFe/ConvertNFe.php): `libs/NFe/ConvertNFe.php`
- [NFe identification](https://github.com/nfephp-org/nfephp/blob/master/libs/NFe/IdentifyNFe.php): `libs/NFe/IdentifyNFe.php`

### SEFAZ services

- [SEFAZ operations](https://github.com/nfephp-org/nfephp/blob/master/libs/NFe/ToolsNFe.php): `libs/NFe/ToolsNFe.php`
- [Response handling](https://github.com/nfephp-org/nfephp/blob/master/libs/NFe/ReturnNFe.php): `libs/NFe/ReturnNFe.php`

### Shared foundation

- [Tools foundation](https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Base/BaseTools.php): `libs/Common/Base/BaseTools.php`
- [XML foundation](https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Base/BaseMake.php): `libs/Common/Base/BaseMake.php`
- [Configuration](https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Configure/Configure.php): `libs/Common/Configure/Configure.php`
- [Certificate handling](https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Certificate/Pkcs12.php): `libs/Common/Certificate/Pkcs12.php`
- [SOAP transport](https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Soap/CurlSoap.php): `libs/Common/Soap/CurlSoap.php`
- [XML utilities](https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Dom/Dom.php): `libs/Common/Dom/Dom.php`
- [File utilities](https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Files/FilesFolders.php): `libs/Common/Files/FilesFolders.php`
- [Date and time](https://github.com/nfephp-org/nfephp/blob/master/libs/Common/DateTime/DateTime.php): `libs/Common/DateTime/DateTime.php`
- [XML validation](https://github.com/nfephp-org/nfephp/blob/master/libs/Common/Dom/ValidXsd.php): `libs/Common/Dom/ValidXsd.php`

### Documents and delivery

- [NFe email](https://github.com/nfephp-org/nfephp/blob/master/libs/NFe/MailNFe.php): `libs/NFe/MailNFe.php`
- [DANFE renderer](https://github.com/nfephp-org/nfephp/blob/master/libs/Extras/Danfe.php): `libs/Extras/Danfe.php`
- [DANFC-e renderer](https://github.com/nfephp-org/nfephp/blob/master/libs/Extras/Danfce.php): `libs/Extras/Danfce.php`

### Other components

- **Issuer application**
- **SEFAZ**

## Connections

- Issuer application → NFe builder: builds XML
- Issuer application → SEFAZ operations: calls API
- NFe builder → XML foundation: uses foundation (evidence: `libs/NFe/MakeNFe.php`)
- NFe builder → Date and time: uses dates (evidence: `libs/NFe/MakeNFe.php`)
- NFe converter → NFe builder: uses builder (evidence: `libs/NFe/ConvertNFe.php`)
- SEFAZ operations → Tools foundation: extends foundation (evidence: `libs/NFe/ToolsNFe.php`)
- SEFAZ operations → Response handling: handles replies (evidence: `libs/NFe/ToolsNFe.php`)
- SEFAZ operations → NFe email: sends email (evidence: `libs/NFe/ToolsNFe.php`)
- SEFAZ operations → NFe identification: identifies invoices (evidence: `libs/NFe/ToolsNFe.php`)
- SEFAZ operations → XML validation: validates XML (evidence: `libs/NFe/ToolsNFe.php`)
- SEFAZ operations → DANFE renderer: creates PDF (evidence: `libs/NFe/ToolsNFe.php`)
- Tools foundation → Certificate handling: loads certificate (evidence: `libs/Common/Base/BaseTools.php`)
- Tools foundation → Date and time: sets timezone (evidence: `libs/Common/Base/BaseTools.php`)
- Tools foundation → XML utilities: parses XML (evidence: `libs/Common/Base/BaseTools.php`)
- Tools foundation → File utilities: reads files (evidence: `libs/Common/Base/BaseTools.php`)
- Tools foundation → SOAP transport: uses transport (evidence: `libs/Common/Base/BaseTools.php`)
- Response handling → XML utilities: uses XML (evidence: `libs/NFe/ReturnNFe.php`)
- NFe identification → File utilities: uses file tools
- NFe identification → XML utilities: uses XML
- SEFAZ → SEFAZ operations: exchanges messages
- Issuer application → DANFC-e renderer: requests print
