# sisuani/gowsfe architecture

> Architecture diagram of the GitHub repository sisuani/gowsfe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sisuani/gowsfe
- Repository: https://github.com/sisuani/gowsfe

## Overview

##### Project Type & Purpose
- This is a backend integration library (not a full-stack web app).
- Its purpose is to wrap AFIP’s SOAP web services (WSFE and WSAFIP) in Go and expose them as a C‐callable shared library (.so / .dll).

##### File Structure
- Top-level directories
- cmd/ – two entry points:
– cmd/main.go – (optional CLI/executable)
– cmd/lib/main.go – builds the shared library via cgo (`-buildmode=c-shared`).
- pkg/ – core library code organized by functional modules:
– pkg/afip/wsfe – electronic invoicing service client
– pkg/afip/wsafip – authentication & ancillary services client
– pkg/certs – certificate/key loading & management utilities
- Config/build artifacts
- go.mod, go.sum – dependency management
- README.md – build instructions and WSDL code generation steps via gowsdl

##### README for Architecture Clues
- Builds a C-shared object to be embedded in non-Go languages
- Relies on auto-generated SOAP client stubs from WSDL (via gowsdl)
- Interacts with two external HTTPS SOAP endpoints (production/homologation)

##### Main Components & Interactions
a. **Entry Layer (cmd/)**
- Shared‐lib entrypoint (cmd/lib/main.go) – exported C functions (e.g., Init, CallWSFE)
- Optional CLI (cmd/main.go)
b. **Certificate Management (pkg/certs)**
- Loads .pem/.p12, provides TLS config
c. **Service Layer (pkg/afip/…)**
- wsafip – handles login/auth token retrieval
- wsfe – performs electronic invoice operations (FECAEDetRequest, etc.)
d. **SOAP Client Stubs (pkg/afip/wsfe/wsfe.go & wsafip generated files)**
- Auto-generated via gowsdl, contain data structures & transport code
e. **External Services**
- AFIP SOAP endpoints (production & testing URLs)

##### Architectural & Design Patterns
- Layered architecture: CLI/Shared-lib → Service Layer → SOAP Stubs → External SOAP
- Single codebase, multi-binary outputs (static exe vs. c-shared lib)
- Dependency injection for cert store into SOAP clients
- Use of code generation (gowsdl) for SOAP bindings

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Layer
    subgraph "Entry Layer"
        CLI["CLI Executable"] 
        CSHARED["C-shared Library Entrypoint\n(Go + cgo)"] 
    end

    %% Certificate Management
    subgraph "Certificate Management"
        Certs["Certificate Management"] 
    end

    %% Service Layer
    subgraph "Service Layer"
        WSAFIP_Login["WSAFIP Login Client"] 
        WSAFIP_Service["WSAFIP Service Core"] 
        WSFE_Service["WSFE Service Core"] 
    end

    %% SOAP Stubs
    subgraph "SOAP Stubs"
        WSFE_Stubs["WSFE SOAP Client Stubs\n(gowsdl-generated)"] 
    end

    %% External AFIP Systems
    subgraph "External AFIP Services"
        Prod["Production Endpoint\n(HTTPS/WSDL)"] 
        Test["Testing Endpoint\n(HTTPS/WSDL)"] 
    end

    %% Configuration & Build
    subgraph "Config & Build Artifacts"
        GoMod["go.mod"] 
        GoSum["go.sum"] 
        Readme["README.md"] 
    end

    %% Flows
    CLI -->|"invokes"| WSAFIP_Service
    CLI -->|"invokes"| WSFE_Service
    CSHARED -->|"exports C API"| WSAFIP_Service
    CSHARED -->|"exports C API"| WSFE_Service

    Certs -->|"provides TLS config"| WSAFIP_Service
    Certs -->|"provides TLS config"| WSFE_Service

    WSAFIP_Service -->|calls| WSAFIP_Login
    WSAFIP_Service -->|uses SOAP stubs| Prod
    WSAFIP_Service -->|uses SOAP stubs| Test

    WSFE_Service -->|calls| WSFE_Stubs
    WSFE_Stubs -->|HTTPS/WSDL| Prod
    WSFE_Stubs -->|HTTPS/WSDL| Test

    %% Click Events
    click CLI "https://github.com/sisuani/gowsfe/blob/main/cmd/main.go"
    click CSHARED "https://github.com/sisuani/gowsfe/blob/main/cmd/lib/main.go"
    click Certs "https://github.com/sisuani/gowsfe/blob/main/pkg/certs/certs.go"
    click WSAFIP_Login "https://github.com/sisuani/gowsfe/blob/main/pkg/afip/wsafip/login.go"
    click WSAFIP_Service "https://github.com/sisuani/gowsfe/blob/main/pkg/afip/wsafip/service.go"
    click WSFE_Service "https://github.com/sisuani/gowsfe/blob/main/pkg/afip/wsfe/service.go"
    click WSFE_Stubs "https://github.com/sisuani/gowsfe/blob/main/pkg/afip/wsfe/wsfe.go"
    click GoMod "https://github.com/sisuani/gowsfe/blob/main/go.mod"
    click GoSum "https://github.com/sisuani/gowsfe/blob/main/go.sum"
    click Readme "https://github.com/sisuani/gowsfe/blob/main/README.md"

    %% Styles
    classDef entry fill:#f9d5a2,stroke:#333,stroke-width:1px
    classDef code fill:#a8dadc,stroke:#333,stroke-width:1px
    classDef stub fill:#e9c46a,stroke:#333,stroke-width:1px
    classDef external fill:#a8e6cf,stroke:#333,stroke-width:1px
    classDef config fill:#d3d3d3,stroke:#333,stroke-width:1px

    class CLI,CSHARED entry
    class Certs code
    class WSAFIP_Login,WSAFIP_Service,WSFE_Service code
    class WSFE_Stubs stub
    class Prod,Test external
    class GoMod,GoSum,Readme config
```
