How ron86i/go-siat works
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: ports Ports · siat.go SIAT client · siat SIAT domain · utils Utils
Components 22
Public SDK
Entry points and caller-facing types.
- SIAT client · Main SDK entrypoint for consumers.
siat.go - Config · Public configuration and runtime settings.
config.go - HTTP config · HTTP-level settings for SOAP requests.
http_config.go - Middleware · Public hook layer for request/response interception.
middleware.go - Errors · Exported error surface for callers.
errors.go
Internal core
Ports, domain models, middleware, and errors.
- Ports · Interfaces that define service and config contracts.
internal/core/ports - SIAT domain · Canonical typed payloads for SIAT service domains.
internal/core/domain/siat - Documents · Sector and document-specific internal document shapes.
internal/core/domain/documents - SOAP envelope · SOAP envelope and transport message structures.
internal/core/domain/datatype/soap/envelope.go - Core middleware · Internal middleware composition for SDK execution.
internal/core/middleware/middleware.go - Core errors · Internal error normalization and classification.
internal/core/errors/errors.go
Transport adapters
Concrete SIAT service implementations and HTTP boundary.
- Códigos · CUIS/CUFD, NIT validation, communication checks, revocation notices.
internal/adapter/services/siat_codigos_service.go - Sincronización · Catalog and reference-data synchronization services.
internal/adapter/services/siat_sincronizacion_service.go - Operaciones · Point-of-sale operations and significant events.
internal/adapter/services/siat_operaciones_service.go - Facturación · Invoicing, validation, annulment, package and mass-reception flows.
internal/adapter/services/siat_facturacion_service.go - Ajuste docs · Credit/debit and adjustment document workflows.
internal/adapter/services/siat_documento_ajuste_service.go - Boleto aéreo · Air-ticket specific SIAT service surface.
internal/adapter/services/siat_boleto_aereo_service.go - Recepción compras · Purchase-reception service boundary.
internal/adapter/services/siat_recepcion_compras_service.go
Support packages
Public models and shared utilities.
- Public models · Public request builders and typed service models.
pkg/models - Invoice models · Sector-specific invoice request and document builders.
pkg/models/invoices - Utils · Signing, CUF generation, crypto, encoding, and parsing helpers.
pkg/utils
Other components
- SIAT SOAP · Bolivia SIAT SOAP web service endpoints.
Connections 29
- 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.