# aricordguhan/e-invoice architecture

> Architecture diagram of the GitHub repository aricordguhan/e-invoice, 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/aricordguhan/e-invoice
- Repository: https://github.com/aricordguhan/e-invoice

## Overview

This is a Node.js e-invoicing compliance manager: source systems or cockpit users ingest invoices, which are mapped to a canonical model, validated against common and country rules, rendered in the required payload format, then submitted and tracked through an authority connector. The cockpit also supports document actions, administration, and audit history. The graph preserves the documented country packs and processing features; several worker, UI, and persistence details are not shown in sampled source, so those relationships are omitted where evidence is insufficient.

Main entry points: [`src/countries/index.js`](https://github.com/aricordguhan/e-invoice/blob/main/src/countries/index.js) (Pack registry), [`src/service.js`](https://github.com/aricordguhan/e-invoice/blob/main/src/service.js) (Document lifecycle), [`src/app.js`](https://github.com/aricordguhan/e-invoice/blob/main/src/app.js) (REST API), [`src/authority/index.js`](https://github.com/aricordguhan/e-invoice/blob/main/src/authority/index.js) (Connector selection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and cockpit"]
  node_webapi["REST API<br/>[app.js]"]
  node_cockpit["Web cockpit<br/>[app.js]"]
  node_server["HTTP server<br/>[server.js]"]
end

subgraph group_processing["Document processing"]
  node_lifecycle["Document lifecycle<br/>[service.js]"]
  node_canonical["Canonical model<br/>[model.js]"]
  node_ublreader["UBL XML import<br/>[xml-import.js]"]
  node_validation["Common validation<br/>[validation.js]"]
end

subgraph group_compliance["Compliance packs"]
  node_packregistry["Pack registry<br/>[index.js]"]
  node_uaepack["UAE rules and payload<br/>[AE.js]"]
  node_indiapack["India GST pack<br/>[IN.js]"]
  node_kenyapack["Kenya eTIMS pack<br/>[KE.js]"]
  node_nigeriapack["Nigeria FIRS pack<br/>[NG.js]"]
  node_saudipack["Saudi ZATCA pack<br/>[SA.js]"]
  node_peppolpack["Peppol packs<br/>[peppol.js]"]
  node_ublwriter["UBL writer<br/>[ubl.js]"]
end

subgraph group_authority["Authority submission"]
  node_authorityrouter["Connector selection<br/>[index.js]"]
  node_drc["SAP DRC connector<br/>[drc.js]"]
  node_uaeasp["UAE ASP connector<br/>[uae-asp.js]"]
  node_simulator["Authority simulator<br/>[sandbox.js]"]
end

subgraph group_governance["Security and state"]
  node_database[("Application database<br/>[db.js]")]
  node_configuration["Runtime configuration<br/>[config.js]"]
end

node_erp(("ERP source"))
node_operator(("Cockpit user"))
node_authorityservice["Tax authority or ASP"]

node_erp -->|"sends documents"| node_webapi
node_operator -->|"manages documents"| node_cockpit
node_cockpit -.->|"calls API"| node_webapi
node_server -->|"hosts routes"| node_webapi
node_webapi -->|"invokes actions"| node_lifecycle
node_webapi -->|"authenticates keys"| node_database
node_lifecycle -->|"normalizes documents"| node_canonical
node_lifecycle -->|"imports XML"| node_ublreader
node_lifecycle -->|"evaluates documents"| node_validation
node_validation -->|"gets country pack"| node_packregistry
node_packregistry -->|"registers pack"| node_uaepack
node_packregistry -->|"registers pack"| node_indiapack
node_packregistry -->|"registers pack"| node_kenyapack
node_packregistry -->|"registers pack"| node_nigeriapack
node_packregistry -->|"registers pack"| node_saudipack
node_packregistry -->|"registers packs"| node_peppolpack
node_uaepack -->|"uses writer"| node_ublwriter
node_saudipack -->|"uses writer"| node_ublwriter
node_lifecycle -.->|"submits and polls"| node_authorityrouter
node_authorityrouter -->|"selects connector"| node_drc
node_authorityrouter -->|"selects connector"| node_uaeasp
node_authorityrouter -->|"selects fallback"| node_simulator
node_drc -.->|"transmits documents"| node_authorityservice
node_uaeasp -.->|"transmits documents"| node_authorityservice
node_lifecycle -.->|"tracks state"| node_database
node_server -->|"loads settings"| node_configuration

click node_webapi "https://github.com/aricordguhan/e-invoice/blob/main/src/app.js"
click node_cockpit "https://github.com/aricordguhan/e-invoice/blob/main/public/app.js"
click node_server "https://github.com/aricordguhan/e-invoice/blob/main/src/server.js"
click node_lifecycle "https://github.com/aricordguhan/e-invoice/blob/main/src/service.js"
click node_canonical "https://github.com/aricordguhan/e-invoice/blob/main/src/model.js"
click node_ublreader "https://github.com/aricordguhan/e-invoice/blob/main/src/xml-import.js"
click node_validation "https://github.com/aricordguhan/e-invoice/blob/main/src/validation.js"
click node_packregistry "https://github.com/aricordguhan/e-invoice/blob/main/src/countries/index.js"
click node_uaepack "https://github.com/aricordguhan/e-invoice/blob/main/src/countries/AE.js"
click node_indiapack "https://github.com/aricordguhan/e-invoice/blob/main/src/countries/IN.js"
click node_kenyapack "https://github.com/aricordguhan/e-invoice/blob/main/src/countries/KE.js"
click node_nigeriapack "https://github.com/aricordguhan/e-invoice/blob/main/src/countries/NG.js"
click node_saudipack "https://github.com/aricordguhan/e-invoice/blob/main/src/countries/SA.js"
click node_peppolpack "https://github.com/aricordguhan/e-invoice/blob/main/src/countries/peppol.js"
click node_ublwriter "https://github.com/aricordguhan/e-invoice/blob/main/src/countries/ubl.js"
click node_authorityrouter "https://github.com/aricordguhan/e-invoice/blob/main/src/authority/index.js"
click node_drc "https://github.com/aricordguhan/e-invoice/blob/main/src/authority/drc.js"
click node_uaeasp "https://github.com/aricordguhan/e-invoice/blob/main/src/authority/uae-asp.js"
click node_simulator "https://github.com/aricordguhan/e-invoice/blob/main/src/authority/sandbox.js"
click node_database "https://github.com/aricordguhan/e-invoice/blob/main/src/db.js"
click node_configuration "https://github.com/aricordguhan/e-invoice/blob/main/src/config.js"

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_webapi,node_cockpit,node_server,node_operator toneBlue
class node_lifecycle,node_canonical,node_ublreader,node_validation toneAmber
class node_packregistry,node_uaepack,node_indiapack,node_kenyapack,node_nigeriapack,node_saudipack,node_peppolpack,node_ublwriter toneMint
class node_authorityrouter,node_drc,node_uaeasp,node_simulator toneRose
class node_database,node_configuration,node_erp,node_authorityservice toneIndigo
```

## Components

### Entry and cockpit

- [REST API](https://github.com/aricordguhan/e-invoice/blob/main/src/app.js): `src/app.js`
- [Web cockpit](https://github.com/aricordguhan/e-invoice/blob/main/public/app.js): `public/app.js`
- [HTTP server](https://github.com/aricordguhan/e-invoice/blob/main/src/server.js): `src/server.js`

### Document processing

- [Document lifecycle](https://github.com/aricordguhan/e-invoice/blob/main/src/service.js): `src/service.js`
- [Canonical model](https://github.com/aricordguhan/e-invoice/blob/main/src/model.js): `src/model.js`
- [UBL XML import](https://github.com/aricordguhan/e-invoice/blob/main/src/xml-import.js): `src/xml-import.js`
- [Common validation](https://github.com/aricordguhan/e-invoice/blob/main/src/validation.js): `src/validation.js`

### Compliance packs

- [Pack registry](https://github.com/aricordguhan/e-invoice/blob/main/src/countries/index.js): `src/countries/index.js`
- [UAE rules and payload](https://github.com/aricordguhan/e-invoice/blob/main/src/countries/AE.js): `src/countries/AE.js`
- [India GST pack](https://github.com/aricordguhan/e-invoice/blob/main/src/countries/IN.js): `src/countries/IN.js`
- [Kenya eTIMS pack](https://github.com/aricordguhan/e-invoice/blob/main/src/countries/KE.js): `src/countries/KE.js`
- [Nigeria FIRS pack](https://github.com/aricordguhan/e-invoice/blob/main/src/countries/NG.js): `src/countries/NG.js`
- [Saudi ZATCA pack](https://github.com/aricordguhan/e-invoice/blob/main/src/countries/SA.js): `src/countries/SA.js`
- [Peppol packs](https://github.com/aricordguhan/e-invoice/blob/main/src/countries/peppol.js): `src/countries/peppol.js`
- [UBL writer](https://github.com/aricordguhan/e-invoice/blob/main/src/countries/ubl.js): `src/countries/ubl.js`

### Authority submission

- [Connector selection](https://github.com/aricordguhan/e-invoice/blob/main/src/authority/index.js): `src/authority/index.js`
- [SAP DRC connector](https://github.com/aricordguhan/e-invoice/blob/main/src/authority/drc.js): `src/authority/drc.js`
- [UAE ASP connector](https://github.com/aricordguhan/e-invoice/blob/main/src/authority/uae-asp.js): `src/authority/uae-asp.js`
- [Authority simulator](https://github.com/aricordguhan/e-invoice/blob/main/src/authority/sandbox.js): `src/authority/sandbox.js`

### Security and state

- [Application database](https://github.com/aricordguhan/e-invoice/blob/main/src/db.js): `src/db.js`
- [Runtime configuration](https://github.com/aricordguhan/e-invoice/blob/main/src/config.js): `src/config.js`

### Other components

- **ERP source**
- **Cockpit user**
- **Tax authority or ASP**

## Connections

- ERP source → REST API: sends documents (evidence: `README.md`)
- Cockpit user → Web cockpit: manages documents (evidence: `README.md`)
- Web cockpit → REST API: calls API
- HTTP server → REST API: hosts routes (evidence: `src/server.js`)
- REST API → Document lifecycle: invokes actions (evidence: `src/app.js`)
- REST API → Application database: authenticates keys (evidence: `src/app.js`)
- Document lifecycle → Canonical model: normalizes documents (evidence: `src/service.js`)
- Document lifecycle → UBL XML import: imports XML (evidence: `src/service.js`)
- Document lifecycle → Common validation: evaluates documents (evidence: `src/service.js`)
- Common validation → Pack registry: gets country pack (evidence: `src/validation.js`)
- Pack registry → UAE rules and payload: registers pack (evidence: `src/countries/index.js`)
- Pack registry → India GST pack: registers pack (evidence: `src/countries/index.js`)
- Pack registry → Kenya eTIMS pack: registers pack (evidence: `src/countries/index.js`)
- Pack registry → Nigeria FIRS pack: registers pack (evidence: `src/countries/index.js`)
- Pack registry → Saudi ZATCA pack: registers pack (evidence: `src/countries/index.js`)
- Pack registry → Peppol packs: registers packs (evidence: `src/countries/index.js`)
- UAE rules and payload → UBL writer: uses writer (evidence: `src/countries/AE.js`)
- Saudi ZATCA pack → UBL writer: uses writer (evidence: `src/countries/ubl.js`)
- Document lifecycle → Connector selection: submits and polls
- Connector selection → SAP DRC connector: selects connector (evidence: `src/authority/index.js`)
- Connector selection → UAE ASP connector: selects connector (evidence: `src/authority/index.js`)
- Connector selection → Authority simulator: selects fallback (evidence: `src/authority/index.js`)
- SAP DRC connector → Tax authority or ASP: transmits documents
- UAE ASP connector → Tax authority or ASP: transmits documents
- Document lifecycle → Application database: tracks state
- HTTP server → Runtime configuration: loads settings (evidence: `src/server.js`)
