Extending the API¶
FastAPI¶
FastAPI is a high-performant REST API framework for Python. It's built on top of Starlette, an ASGI (Asynchronous Server Gateway Interface) implementation for Python, and it uses Pydantic for data validation. It can generate OpenAPI documentation from your code and also produces a Swagger UI that you can use to test your application. OpenAPI uses a subset of JSON Schema to describe APIs and define the validation rules of the API payloads and parameters.
To run FastAPI applications, we use the process manager uvicorn. Check out the official documentation for more details.

Codebase structure¶
The API is grouped by features.

The API has a feature-based folder structure following the principles of Clean Architecture.
├── api/
│ └── src/
│ ├── common/
│ ├── entities/
│ ├── features/
│ │ ├── health_check/
│ │ ├── todo/
│ │ ├── whoami/
│ │ └── ...
│ ├── data_providers/
│ └── tests/
│ ├── unit/
│ └── integration/
└── ...
commoncontains shared code like authentication, exceptions, response decoratorentitiescontains all entities, enums, exceptions, interfaces, types and logic specific to the domain layerfeaturescontains use-cases (application logic), repository interfaces, and controllersdata providerscontains classes for accessing external resources such as databases, file systems, web services, and repository implementationstestscontains unit and integrations tests
Get started¶
- Create the domain model by adding entities
- Extend the API by adding features
- Add a use case to handle application logic
- Add a controller to handle API requests
- Add an endpoint to the controller that executes the use case
- Add a data provider, repository interface and repository to handle communication to external services such as databases.
Note
Entities and data providers can be shared between features (the entrypoints and use-cases).
Configuration¶
All configuration parameters are expected to be environment variables, and are defined in this file api/src/config.py.
--8<-- "api/src/app/config.py"
See configuration for a description of the different configuration options available.