Project Overview
Factus API is a FastAPI-based REST API for interacting with the Factus Colombian e-invoicing system. The project follows clean architecture principles with domain-driven design patterns to ensure maintainability, testability, and separation of concerns.Technology Stack
The project is built with modern Python technologies:FastAPI
High-performance async web framework with automatic OpenAPI documentation
httpx
Modern async HTTP client for external API communication
Pydantic
Data validation and settings management using Python type annotations
python-jose
JWT token handling for authentication and authorization
Core Dependencies
requirements.txt
Project Structure
The codebase is organized into clear layers following clean architecture principles:Layer Responsibilities
API Layer (api/)
API Layer (api/)
Handles HTTP requests and responses. Contains FastAPI route handlers, request/response schemas, and dependency injection setup.
- endpoints/: FastAPI router definitions
- schemas/: Pydantic models for API validation
- deps.py: Shared dependencies like authentication
Core Layer (core/)
Core Layer (core/)
Provides cross-cutting concerns and shared utilities used throughout the application.
- config.py: Environment-based configuration
- security.py: Authentication and cryptography
- responses.py: Standardized API responses
Domain Layer (domain/)
Domain Layer (domain/)
Contains business logic and domain models. No framework dependencies - pure Python.
- models/: Domain entities (Invoice, AuthToken, etc.)
- interfaces/: Abstract base classes defining contracts (ports)
Infrastructure Layer (infrastructure/)
Infrastructure Layer (infrastructure/)
Implements external integrations and data persistence.
- gateways/: Factus API client implementations
- repositories/: Database access patterns
- db/: Database connection management
Key Design Decisions
1. Clean Architecture
The project strictly separates business logic from infrastructure concerns. Domain models have zero dependencies on FastAPI, httpx, or any external libraries.2. Async-First Architecture
All I/O operations use Python’sasync/await pattern for maximum concurrency and performance:
- FastAPI route handlers are
async def - HTTP requests use
httpx.AsyncClient - Gateway methods are asynchronous
- Database operations support async (when implemented)
3. Type Safety
The codebase uses strict type annotations throughout:4. Dependency Injection
FastAPI’s dependency injection system decouples components and enables easy testing:app/src/api/deps.py
5. Environment-Based Configuration
All configuration is managed through environment variables usingpydantic-settings:
app/src/core/config.py
Application Initialization
The FastAPI application is created using a factory pattern:app/src/main.py
The root path
/ automatically redirects to the interactive API documentation at /api/v1/docs.Running the Application
Next Steps
Clean Architecture
Learn about the ports and adapters pattern implementation
Configuration
Understand environment variables and settings management
Authentication API
Explore the complete API documentation
Quickstart Guide
Set up your development environment
