FastAPI Application Design
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The OdooConnectorAPI is a RESTful application built using the FastAPI framework. Its primary purpose is to act as an intermediary layer, facilitating asynchronous communication between external clients and an Odoo ERP system. By leveraging FastAPI, the system provides a high-performance interface for retrieving and managing Odoo data.
Sources: README.md:3-5, app/main.py:1-6
The application design emphasizes portability and scalability, utilizing Docker for containerization and Helm charts for deployment into Kubernetes environments. The core logic is centralized in a main application module that handles configuration through environment variables and interacts with Odoo via the odoorpc library.
Sources: README.md:5-7, requirements.txt:3, charts/odooconnectorapi/templates/deployment.yaml:14-25
Core Architecture and Components
The application follows a standard FastAPI structure where the instance is initialized in the main.py module. It uses environment-based configuration to establish connections with the Odoo backend.
Component Interaction
The following diagram illustrates the high-level architecture of the OdooConnectorAPI:
This diagram shows the flow from an external client through the FastAPI application to the Odoo ERP system.
Sources: app/main.py:9-35, docker-compose.yml:10-14
Configuration Management
Configuration is handled via environment variables, allowing the application to remain agnostic of its deployment environment (Local, Docker, or Kubernetes).
| Variable | Description | Default Value |
|---|---|---|
ODOO_URL | The hostname or IP of the Odoo server | localhost |
ODOO_DB | The name of the Odoo database to connect to | mydb |
ODOO_USERNAME | The username for Odoo authentication | admin |
ODOO_PASSWORD | The password for Odoo authentication | admin |
Sources: app/main.py:11-14, charts/odooconnectorapi/values.yaml:15-19
API Endpoints and Data Flow
The application currently implements basic endpoints to verify connectivity and retrieve partner information.
Endpoint Specifications
| Endpoint | Method | Description | Return Type |
|---|---|---|---|
/ | GET | Root endpoint returning a welcome message | {"message": "Hello World"} |
/get/partners | GET | Fetches name and email for all partners in Odoo | {"partners": List[Dict]} |
Sources: app/main.py:17-37
Data Retrieval Flow
When a request is made to /get/partners, the application performs a sequence of operations to authenticate and query the Odoo RPC layer.
This sequence diagram details the interaction between the API and the Odoo server using the RPC protocol.
Sources: app/main.py:25-37
Deployment Infrastructure
The application design includes comprehensive support for containerized deployment.
Docker and Docker Compose
For local development and testing, a docker-compose.yml file defines the web service, which builds the application and exposes port 8000. It maps environment variables from a local .env file to the container.
Sources: docker-compose.yml:3-14
Kubernetes (Helm)
The project includes a Helm chart located in charts/odooconnectorapi. The deployment template ensures that the FastAPI application is managed as a set of replicas with the necessary environment variables injected from the values.yaml file.
# Example Environment Injection in Deployment
- name: ODOO_URL
value: {{ .Values.env.ODOO_URL }}
- name: ODOO_DB
value: {{ .Values.env.ODOO_DB }}
Sources: charts/odooconnectorapi/templates/deployment.yaml:14-25, charts/odooconnectorapi/values.yaml:14-19
Summary
The FastAPI application design within the OdooConnectorAPI project focuses on creating a slim, scalable bridge to Odoo ERP. By utilizing odoorpc for backend communication and standardizing configuration through environment variables, the system ensures ease of deployment across diverse environments ranging from local Docker setups to production Kubernetes clusters.
Sources: README.md:1-10, app/main.py:1-15