DIAN REST API is built on Hexagonal Architecture (Ports & Adapters), a design philosophy that enforces strict layer separation between business logic and infrastructure concerns. The domain — tax calculations, tip handling, invoice totals, and buyer identity — lives in pure Python entities with zero external dependencies. An application layer of use cases and port interfaces sits above the domain, defining the contracts that infrastructure must fulfill. FastAPI controllers, the zeep SOAP client, and the PostgreSQL audit logger are all interchangeable adapters that plug in at the edges. Every layer is async-first: FastAPI’s async route handlers, zeep’sDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/farojas85/fast-rest-api/llms.txt
Use this file to discover all available pages before exploring further.
AsyncTransport backed by httpx, and SQLAlchemy’s async engine ensure no thread is ever blocked waiting on I/O. This architecture makes each concern independently testable, replaceable, and auditable.
Tech Stack
| Component | Role |
|---|---|
| FastAPI (Python 3.10+) | Primary REST framework — high-performance ASGI, auto OpenAPI docs, async route handlers |
| Pydantic v2 | DTO validation for all incoming HTTP payloads and outgoing response models |
| SQLAlchemy Async + Alembic | Async ORM for PostgreSQL access; Alembic manages schema migrations |
| zeep + httpx AsyncTransport | Async SOAP client for communicating with DIAN web services without blocking the event loop |
| PostgreSQL | Relational storage for the full audit log of every invoice attempt and its DIAN response |
| asyncpg | High-performance async PostgreSQL driver used by SQLAlchemy’s async engine for non-blocking database I/O |
| lxml | XML processing library required by zeep for SOAP envelope serialisation and parsing |
| cryptography | Loads PFX certificates at startup via pkcs12.load_key_and_certificates — fails fast if the cert or password is invalid |
| uv | Fast dependency management and virtual environment tooling (replaces pip/virtualenv) |
| ruff | Linting and code formatting enforced across the entire codebase |
Directory Structure
Three Layers at a Glance
Domain
Pure Pydantic entities (
PedidoLocal, ItemPedido, ConceptoImpuesto, MetodoPago, Adquirente) that represent the billing domain with no imports from infrastructure or application layers. This is the innermost layer — the business rules live here.Application
Use cases (
FacturarPedidoLocalUseCase) orchestrate business operations. Port interfaces (IDianSoapPort, IInvoiceLogRepositoryPort) declare the contracts that infrastructure must implement — the application layer never imports a concrete adapter directly.Infrastructure
Driving adapters (FastAPI controllers) translate HTTP requests into use case calls. Driven adapters (
DianSoapAdapter) translate use case calls into outbound SOAP requests and PostgreSQL writes. All wired together via FastAPI’s Depends() dependency injection.