# ron86i/go-siat architecture

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

- Interactive diagram: https://gitdiagram.com/ron86i/go-siat
- Repository: https://github.com/ron86i/go-siat

## Overview

1. **What this repository is**
   - `go-siat` is a Go SDK, not an application server. Its job is to hide the SOAP/XML complexity of Bolivia’s SIAT tax services behind typed Go APIs.
   - The architecture is centered on request construction, SOAP transport, response decoding, and helper utilities for signature/encoding tasks.

2. **Top-level public API**
   - The root package (`siat.go`, `config.go`, `http_config.go`, `middleware.go`, `code.go`, `errors.go`, `constants.go`) is the entry point for consumers.
   - It exposes client construction, configuration, service accessors, shared error types, and cross-cutting hooks such as middleware and HTTP settings.

3. **Core architectural style**
   - The repo uses a **hexagonal / ports-and-adapters** shape.
   - `internal/core/ports` defines the contracts the SDK uses internally, while `internal/adapter/services` contains the concrete SIAT service implementations that satisfy those contracts.
   - This keeps the domain/request models insulated from transport details.

4. **Service boundary by SIAT domain**
   - The main integration surface is split into service groups:
     - `codigos` for CUIS/CUFD, NIT validation, communication checks, certificate revocation notices.
     - `sincronizacion` for catalogs and reference data.
     - `operaciones` for POS/point-of-sale operations and significant events.
     - `facturacion` for invoicing flows, validation, annulment, packages, mass reception, and related checks.
     - `documento_ajuste` for credit/debit and adjustment-document workflows.
     - `compra_venta`, `boleto_aereo`, and other specialized service areas.
   - This service partitioning is the main architectural boundary an engineer would diagram.

5. **Request/response model layer**
   - `pkg/models` is the public type surface for callers.
   - It contains request builders and typed models for service calls, especially the large `pkg/models/invoices` set covering many regulated sectors.
   - The models are intentionally sector-specific, which matters because SIAT’s invoice schemas vary heavily by industry.

6. **Internal SIAT domain models**
   - `internal/core/domain/siat` mirrors the service taxonomy with strongly typed domain structs for SIAT request/response payloads.
   - `internal/core/domain/documents` contains the document variants used by invoicing and sector-specific electronic documents.
   - These internal domain types are the canonical shape used inside the SDK before transport serialization.

7. **Transport and SOAP boundary**
   - `internal/core/domain/datatype/soap` defines SOAP envelope structures.
   - `internal/adapter/services/http_config.go` and related config types imply the HTTP layer is configurable and is the boundary where SOAP requests are sent to SIAT endpoints.
   - The data flow is: caller model → internal domain payload → SOAP envelope → HTTP request → SIAT SOAP response → decoded Go structs.

8. **Cross-cutting utilities**
   - `pkg/utils` provides the non-domain machinery needed by SIAT integrations:
     - XML signing (`signXML.go`)
     - CUF generation (`cuf.go`)
     - crypto helpers (`crypto.go`)
     - encoding/compression/export helpers
     - parsing and math utilities
   - These are essential because SIAT integrations require digital certificates, XMLDSig, and deterministic identifier generation.

9. **Configuration and runtime concerns**
   - Configuration is driven by values such as token, NIT, system code, environment, and base URL, as shown in the README and `config.go`/`internal/core/ports/config.go`.
   - The SDK is context-aware at the call site, which indicates request timeout/cancellation is expected to be handled by the consumer.
   - There is no evidence of long-lived background workers or persistence; the architecture is request/response oriented.

10. **Middleware and extensibility**
   - `internal/core/middleware` plus the root `middleware.go` indicate a hook layer for request/response interception.
   - This is likely where consumers can add logging, tracing, auth decoration, or request mutation without touching the service adapters.

11. **Error handling**
   - Errors are split between exported/root errors and `internal/core/errors`.
   - This suggests the SDK normalizes transport, SOAP, validation, and SIAT business errors into a consistent error surface for callers.

12. **Testing and documentation as part of the architecture**
   - The repository uses extensive tests in both `pkg/models/invoices/*_test.go` and `internal/adapter/services/*_test.go`.
   - The README and `docs/en` / `docs/es` act as the architecture and usage reference, while the tests serve as executable examples of the service flows.
   - CI workflows (`codeql.yml`, `release.yml`) show this is packaged as a maintained library with security scanning and release automation.

13. **Main external dependency**
   - The only major external system is SIAT’s SOAP web service ecosystem.
   - The SDK’s responsibility is to translate typed Go inputs into SIAT-compliant SOAP/XML requests, including signature and encoding requirements, then map SIAT responses back into Go models.

14. **How to draw the architecture**
   - At the center, place the public `siat` client.
   - On one side, place consumer applications using `pkg/models` builders and invoking service methods.
   - Inside the SDK, show ports/domain/utils feeding adapter services.
   - On the other side, show SOAP/HTTP transport to SIAT endpoints.
   - Add a separate cross-cutting lane for middleware, config, errors, and XML signature/CUF utilities.

Main entry points: [`internal/core/ports`](https://github.com/ron86i/go-siat/tree/main/internal/core/ports) (Ports), [`siat.go`](https://github.com/ron86i/go-siat/blob/main/siat.go) (SIAT client), [`internal/core/domain/siat`](https://github.com/ron86i/go-siat/tree/main/internal/core/domain/siat) (SIAT domain), [`pkg/utils`](https://github.com/ron86i/go-siat/tree/main/pkg/utils) (Utils)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_public["Public SDK"]
  node_n_siat["SIAT client<br/>public entrypoint<br/>[siat.go]"]
  node_n_config["Config<br/>[config.go]"]
  node_n_httpcfg["HTTP config<br/>transport config<br/>[http_config.go]"]
  node_n_middleware_api["Middleware<br/>extensibility hooks<br/>[middleware.go]"]
  node_n_errors_api["Errors<br/>[errors.go]"]
end

subgraph group_grp_internal["Internal core"]
  node_n_ports["Ports<br/>internal contracts"]
  node_n_domain_siat["SIAT domain<br/>request/response models"]
  node_n_domain_docs["Documents<br/>invoice variants"]
  node_n_soap["SOAP envelope<br/>soap types<br/>[envelope.go]"]
  node_n_middleware_core["Core middleware<br/>interceptors<br/>[middleware.go]"]
  node_n_core_errors["Core errors<br/>normalized errors<br/>[errors.go]"]
end

subgraph group_grp_adapter["Transport adapters"]
  node_n_codigos["Códigos<br/>service adapter"]
  node_n_sinc["Sincronización<br/>service adapter"]
  node_n_oper["Operaciones<br/>service adapter"]
  node_n_fact["Facturación<br/>service adapter"]
  node_n_adj["Ajuste docs<br/>service adapter"]
  node_n_boleto["Boleto aéreo<br/>service adapter"]
  node_n_recep_comp["Recepción compras<br/>service adapter"]
end

subgraph group_grp_support["Support packages"]
  node_n_models["Public models<br/>caller payloads"]
  node_n_invoice_models["Invoice models<br/>sector schemas"]
  node_n_utils["Utils<br/>helpers"]
end

node_n_siat_ext[("SIAT SOAP<br/>external system")]

node_n_siat -->|"uses"| node_n_config
node_n_siat -->|"uses"| node_n_httpcfg
node_n_siat -->|"exposes"| node_n_middleware_api
node_n_siat -->|"surfaces"| node_n_errors_api
node_n_siat -->|"depends on"| node_n_ports
node_n_models -->|"calls"| node_n_siat
node_n_invoice_models -->|"specializes"| node_n_models
node_n_models -->|"maps to"| node_n_domain_siat
node_n_domain_siat -->|"serializes into"| node_n_soap
node_n_soap -->|"sent to"| node_n_siat_ext
node_n_codigos -->|"implements"| node_n_ports
node_n_sinc -->|"implements"| node_n_ports
node_n_oper -->|"implements"| node_n_ports
node_n_fact -->|"implements"| node_n_ports
node_n_adj -->|"implements"| node_n_ports
node_n_boleto -->|"implements"| node_n_ports
node_n_recep_comp -->|"implements"| node_n_ports
node_n_ports -->|"uses"| node_n_domain_siat
node_n_ports -->|"uses"| node_n_domain_docs
node_n_fact -->|"uses"| node_n_utils
node_n_codigos -->|"uses"| node_n_utils
node_n_domain_siat -->|"validated by"| node_n_core_errors
node_n_middleware_core -->|"wraps"| node_n_ports
node_n_middleware_api -->|"delegates to"| node_n_middleware_core
node_n_httpcfg -->|"configures"| node_n_ports
node_n_utils -->|"supports"| node_n_domain_docs
node_n_utils -->|"supports"| node_n_soap
node_n_errors_api -->|"adapts"| node_n_core_errors
node_n_domain_docs -->|"mirrors"| node_n_invoice_models

click node_n_siat "https://github.com/ron86i/go-siat/blob/main/siat.go"
click node_n_config "https://github.com/ron86i/go-siat/blob/main/config.go"
click node_n_httpcfg "https://github.com/ron86i/go-siat/blob/main/http_config.go"
click node_n_middleware_api "https://github.com/ron86i/go-siat/blob/main/middleware.go"
click node_n_errors_api "https://github.com/ron86i/go-siat/blob/main/errors.go"
click node_n_ports "https://github.com/ron86i/go-siat/tree/main/internal/core/ports"
click node_n_domain_siat "https://github.com/ron86i/go-siat/tree/main/internal/core/domain/siat"
click node_n_domain_docs "https://github.com/ron86i/go-siat/tree/main/internal/core/domain/documents"
click node_n_soap "https://github.com/ron86i/go-siat/blob/main/internal/core/domain/datatype/soap/envelope.go"
click node_n_middleware_core "https://github.com/ron86i/go-siat/blob/main/internal/core/middleware/middleware.go"
click node_n_core_errors "https://github.com/ron86i/go-siat/blob/main/internal/core/errors/errors.go"
click node_n_codigos "https://github.com/ron86i/go-siat/blob/main/internal/adapter/services/siat_codigos_service.go"
click node_n_sinc "https://github.com/ron86i/go-siat/blob/main/internal/adapter/services/siat_sincronizacion_service.go"
click node_n_oper "https://github.com/ron86i/go-siat/blob/main/internal/adapter/services/siat_operaciones_service.go"
click node_n_fact "https://github.com/ron86i/go-siat/blob/main/internal/adapter/services/siat_facturacion_service.go"
click node_n_adj "https://github.com/ron86i/go-siat/blob/main/internal/adapter/services/siat_documento_ajuste_service.go"
click node_n_boleto "https://github.com/ron86i/go-siat/blob/main/internal/adapter/services/siat_boleto_aereo_service.go"
click node_n_recep_comp "https://github.com/ron86i/go-siat/blob/main/internal/adapter/services/siat_recepcion_compras_service.go"
click node_n_models "https://github.com/ron86i/go-siat/tree/main/pkg/models"
click node_n_invoice_models "https://github.com/ron86i/go-siat/tree/main/pkg/models/invoices"
click node_n_utils "https://github.com/ron86i/go-siat/tree/main/pkg/utils"

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_n_siat,node_n_config,node_n_httpcfg,node_n_middleware_api,node_n_errors_api toneBlue
class node_n_ports,node_n_domain_siat,node_n_domain_docs,node_n_soap,node_n_middleware_core,node_n_core_errors toneAmber
class node_n_codigos,node_n_sinc,node_n_oper,node_n_fact,node_n_adj,node_n_boleto,node_n_recep_comp toneMint
class node_n_models,node_n_invoice_models,node_n_utils toneRose
class node_n_siat_ext toneNeutral
```

## Components

### Public SDK

Entry points and caller-facing types.

- [SIAT client](https://github.com/ron86i/go-siat/blob/main/siat.go): public entrypoint · Main SDK entrypoint for consumers. · `siat.go`
- [Config](https://github.com/ron86i/go-siat/blob/main/config.go): sdk config · Public configuration and runtime settings. · `config.go`
- [HTTP config](https://github.com/ron86i/go-siat/blob/main/http_config.go): transport config · HTTP-level settings for SOAP requests. · `http_config.go`
- [Middleware](https://github.com/ron86i/go-siat/blob/main/middleware.go): extensibility hooks · Public hook layer for request/response interception. · `middleware.go`
- [Errors](https://github.com/ron86i/go-siat/blob/main/errors.go): public errors · Exported error surface for callers. · `errors.go`

### Internal core

Ports, domain models, middleware, and errors.

- [Ports](https://github.com/ron86i/go-siat/tree/main/internal/core/ports): internal contracts · Interfaces that define service and config contracts. · `internal/core/ports`
- [SIAT domain](https://github.com/ron86i/go-siat/tree/main/internal/core/domain/siat): request/response models · Canonical typed payloads for SIAT service domains. · `internal/core/domain/siat`
- [Documents](https://github.com/ron86i/go-siat/tree/main/internal/core/domain/documents): invoice variants · Sector and document-specific internal document shapes. · `internal/core/domain/documents`
- [SOAP envelope](https://github.com/ron86i/go-siat/blob/main/internal/core/domain/datatype/soap/envelope.go): soap types · SOAP envelope and transport message structures. · `internal/core/domain/datatype/soap/envelope.go`
- [Core middleware](https://github.com/ron86i/go-siat/blob/main/internal/core/middleware/middleware.go): interceptors · Internal middleware composition for SDK execution. · `internal/core/middleware/middleware.go`
- [Core errors](https://github.com/ron86i/go-siat/blob/main/internal/core/errors/errors.go): normalized errors · Internal error normalization and classification. · `internal/core/errors/errors.go`

### Transport adapters

Concrete SIAT service implementations and HTTP boundary.

- [Códigos](https://github.com/ron86i/go-siat/blob/main/internal/adapter/services/siat_codigos_service.go): service adapter · CUIS/CUFD, NIT validation, communication checks, revocation notices. · `internal/adapter/services/siat_codigos_service.go`
- [Sincronización](https://github.com/ron86i/go-siat/blob/main/internal/adapter/services/siat_sincronizacion_service.go): service adapter · Catalog and reference-data synchronization services. · `internal/adapter/services/siat_sincronizacion_service.go`
- [Operaciones](https://github.com/ron86i/go-siat/blob/main/internal/adapter/services/siat_operaciones_service.go): service adapter · Point-of-sale operations and significant events. · `internal/adapter/services/siat_operaciones_service.go`
- [Facturación](https://github.com/ron86i/go-siat/blob/main/internal/adapter/services/siat_facturacion_service.go): service adapter · Invoicing, validation, annulment, package and mass-reception flows. · `internal/adapter/services/siat_facturacion_service.go`
- [Ajuste docs](https://github.com/ron86i/go-siat/blob/main/internal/adapter/services/siat_documento_ajuste_service.go): service adapter · Credit/debit and adjustment document workflows. · `internal/adapter/services/siat_documento_ajuste_service.go`
- [Boleto aéreo](https://github.com/ron86i/go-siat/blob/main/internal/adapter/services/siat_boleto_aereo_service.go): service adapter · Air-ticket specific SIAT service surface. · `internal/adapter/services/siat_boleto_aereo_service.go`
- [Recepción compras](https://github.com/ron86i/go-siat/blob/main/internal/adapter/services/siat_recepcion_compras_service.go): service adapter · Purchase-reception service boundary. · `internal/adapter/services/siat_recepcion_compras_service.go`

### Support packages

Public models and shared utilities.

- [Public models](https://github.com/ron86i/go-siat/tree/main/pkg/models): caller payloads · Public request builders and typed service models. · `pkg/models`
- [Invoice models](https://github.com/ron86i/go-siat/tree/main/pkg/models/invoices): sector schemas · Sector-specific invoice request and document builders. · `pkg/models/invoices`
- [Utils](https://github.com/ron86i/go-siat/tree/main/pkg/utils): helpers · Signing, CUF generation, crypto, encoding, and parsing helpers. · `pkg/utils`

### Other components

- **SIAT SOAP**: external system · Bolivia SIAT SOAP web service endpoints.

## Connections

- SIAT client → Config: uses · Client construction and runtime settings.
- SIAT client → HTTP config: uses · Configures transport behavior.
- SIAT client → Middleware: exposes · Allows interception and decoration.
- SIAT client → Errors: surfaces · Returns normalized SDK errors.
- SIAT client → Ports: depends on · Client is wired through internal contracts.
- Public models → SIAT client: calls · Consumers build payloads and invoke service methods.
- Invoice models → Public models: specializes · Sector-specific invoice builders extend the public model layer.
- Public models → SIAT domain: maps to · Public request shapes are adapted into internal payloads.
- SIAT domain → SOAP envelope: serializes into · Domain payloads are wrapped for SOAP transport.
- SOAP envelope → SIAT SOAP: sent to · SOAP envelopes are transmitted over HTTP.
- Códigos → Ports: implements · Concrete service adapter behind port contracts.
- Sincronización → Ports: implements · Concrete service adapter behind port contracts.
- Operaciones → Ports: implements · Concrete service adapter behind port contracts.
- Facturación → Ports: implements · Concrete service adapter behind port contracts.
- Ajuste docs → Ports: implements · Concrete service adapter behind port contracts.
- Boleto aéreo → Ports: implements · Concrete service adapter behind port contracts.
- Recepción compras → Ports: implements · Concrete service adapter behind port contracts.
- Ports → SIAT domain: uses · Ports define operations over canonical SIAT payloads.
- Ports → Documents: uses · Service contracts reference document variants.
- Facturación → Utils: uses · Invoice flows rely on signatures and CUF helpers.
- Códigos → Utils: uses · Code services depend on encoding and crypto helpers.
- SIAT domain → Core errors: validated by · Domain-level validation and normalization.
- Core middleware → Ports: wraps · Internal execution pipeline around service calls.
- Middleware → Core middleware: delegates to · Public hook layer feeds core middleware composition.
- HTTP config → Ports: configures · Transport settings are passed into service execution.
- Utils → Documents: supports · Helpers support document generation and serialization.
- Utils → SOAP envelope: supports · Helpers assist SOAP/XML construction and signing.
- Errors → Core errors: adapts · Public error types mirror internal normalization.
- Documents → Invoice models: mirrors · Internal and public invoice schemas track each other.
