# emilioastarita/facturajs architecture

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

- Interactive diagram: https://gitdiagram.com/emilioastarita/facturajs
- Repository: https://github.com/emilioastarita/facturajs

## Overview

FacturaJS is a Node.js client for AFIP web services, with helpers for electronic invoicing and a generic SOAP operation API. The main workflow is a caller invoking an AfipServices method, which delegates to AfipSoap; the SOAP layer obtains credentials and makes the remote request. The library also exposes generated wsfev1 TypeScript definitions and supports token caching and TLS configuration. The README documents capabilities not fully visible in sampled excerpts; edges to remote services reflect documented SOAP usage and the sampled loginCms implementation.

Main entry points: [`src/AfipServices.ts`](https://github.com/emilioastarita/facturajs/blob/master/src/AfipServices.ts) (AFIP Services), [`src/lib/AfipSoap.ts`](https://github.com/emilioastarita/facturajs/blob/master/src/lib/AfipSoap.ts) (SOAP Engine), [`src/util.ts`](https://github.com/emilioastarita/facturajs/blob/master/src/util.ts) (Crypto and XML Utilities), [`src/IConfigService.ts`](https://github.com/emilioastarita/facturajs/blob/master/src/IConfigService.ts) (Client Configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Client API"]
  node_service_api["AFIP Services<br/>[AfipServices.ts]"]
  node_invoice_ops["Invoice Operations<br/>[AfipServices.ts]"]
  node_config["Client Configuration<br/>[IConfigService.ts]"]
end

subgraph group_auth["Authentication"]
  node_token_cache["Credential Cache<br/>[AfipSoap.ts]"]
  node_login_ticket["Signed Login Ticket<br/>[AfipSoap.ts]"]
end

subgraph group_transport["SOAP Integration"]
  node_soap_engine["SOAP Engine<br/>[AfipSoap.ts]"]
  node_utilities["Crypto and XML Utilities<br/>[util.ts]"]
end

subgraph group_types["Contracts"]
  node_soap_methods["Operation Contracts<br/>[SoapMethods.ts]"]
  node_wsfe_types["wsfev1 Definitions"]
end

node_caller(("Library Caller"))
node_wsaa{{"AFIP WSAA"}}
node_afip_wsfe{{"AFIP wsfev1"}}

node_caller -->|"calls"| node_service_api
node_service_api -->|"offers"| node_invoice_ops
node_service_api -->|"delegates"| node_soap_engine
node_service_api -->|"uses types"| node_soap_methods
node_service_api -->|"returns typed result"| node_wsfe_types
node_soap_engine -->|"reads settings"| node_config
node_soap_engine -->|"gets credentials"| node_token_cache
node_soap_engine -->|"calls SOAP"| node_afip_wsfe
node_soap_engine -->|"uses"| node_utilities
node_token_cache -->|"requests tokens"| node_login_ticket
node_login_ticket -->|"signs and parses"| node_utilities
node_login_ticket -->|"submits login ticket"| node_wsaa

click node_service_api "https://github.com/emilioastarita/facturajs/blob/master/src/AfipServices.ts"
click node_invoice_ops "https://github.com/emilioastarita/facturajs/blob/master/src/AfipServices.ts"
click node_config "https://github.com/emilioastarita/facturajs/blob/master/src/IConfigService.ts"
click node_soap_methods "https://github.com/emilioastarita/facturajs/blob/master/src/SoapMethods.ts"
click node_soap_engine "https://github.com/emilioastarita/facturajs/blob/master/src/lib/AfipSoap.ts"
click node_token_cache "https://github.com/emilioastarita/facturajs/blob/master/src/lib/AfipSoap.ts"
click node_login_ticket "https://github.com/emilioastarita/facturajs/blob/master/src/lib/AfipSoap.ts"
click node_utilities "https://github.com/emilioastarita/facturajs/blob/master/src/util.ts"
click node_wsfe_types "https://github.com/emilioastarita/facturajs/tree/master/src/generated/wsfev1/definitions"

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_service_api,node_invoice_ops,node_config toneBlue
class node_token_cache,node_login_ticket toneAmber
class node_soap_engine,node_utilities toneMint
class node_soap_methods,node_wsfe_types toneRose
class node_caller,node_wsaa,node_afip_wsfe toneIndigo
```

## Components

### Client API

- [AFIP Services](https://github.com/emilioastarita/facturajs/blob/master/src/AfipServices.ts): `src/AfipServices.ts`
- [Invoice Operations](https://github.com/emilioastarita/facturajs/blob/master/src/AfipServices.ts): `src/AfipServices.ts`
- [Client Configuration](https://github.com/emilioastarita/facturajs/blob/master/src/IConfigService.ts): `src/IConfigService.ts`

### Authentication

- [Credential Cache](https://github.com/emilioastarita/facturajs/blob/master/src/lib/AfipSoap.ts): `src/lib/AfipSoap.ts`
- [Signed Login Ticket](https://github.com/emilioastarita/facturajs/blob/master/src/lib/AfipSoap.ts): `src/lib/AfipSoap.ts`

### SOAP Integration

- [SOAP Engine](https://github.com/emilioastarita/facturajs/blob/master/src/lib/AfipSoap.ts): `src/lib/AfipSoap.ts`
- [Crypto and XML Utilities](https://github.com/emilioastarita/facturajs/blob/master/src/util.ts): `src/util.ts`

### Contracts

- [Operation Contracts](https://github.com/emilioastarita/facturajs/blob/master/src/SoapMethods.ts): `src/SoapMethods.ts`
- [wsfev1 Definitions](https://github.com/emilioastarita/facturajs/tree/master/src/generated/wsfev1/definitions): `src/generated/wsfev1/definitions`

### Other components

- **Library Caller**
- **AFIP WSAA**
- **AFIP wsfev1**

## Connections

- Library Caller → AFIP Services: calls (evidence: `README.md`)
- AFIP Services → Invoice Operations: offers (evidence: `src/AfipServices.ts`)
- AFIP Services → SOAP Engine: delegates (evidence: `src/AfipServices.ts`)
- AFIP Services → Operation Contracts: uses types (evidence: `src/AfipServices.ts`)
- AFIP Services → wsfev1 Definitions: returns typed result (evidence: `src/AfipServices.ts`)
- SOAP Engine → Client Configuration: reads settings (evidence: `src/lib/AfipSoap.ts`)
- SOAP Engine → Credential Cache: gets credentials (evidence: `src/lib/AfipSoap.ts`)
- SOAP Engine → AFIP wsfev1: calls SOAP (evidence: `README.md`)
- SOAP Engine → Crypto and XML Utilities: uses (evidence: `src/lib/AfipSoap.ts`)
- Credential Cache → Signed Login Ticket: requests tokens (evidence: `src/lib/AfipSoap.ts`)
- Signed Login Ticket → Crypto and XML Utilities: signs and parses (evidence: `src/lib/AfipSoap.ts`)
- Signed Login Ticket → AFIP WSAA: submits login ticket (evidence: `src/lib/AfipSoap.ts`)
