FastAPI starter framework
ZENLEAF: a FastAPI starter framework for reusable services.
ZENLEAF is a FastAPI starter that gives every new project the same predefined services, folder pattern and generator. Your team writes the business logic, and the common platform services come built in.
What ZENLEAF reuses in every project
Each platform service is set up once, then reused. Your team focuses on the rules that make your product different.
| Service | Package | Purpose |
|---|---|---|
| Database access | SQLAlchemy 2, async | Async models and queries for each service |
| Authentication | fastapi-users | Login with OAuth2 and JWT tokens, with ready endpoints |
| Single sign-on | Fief | One login across several applications |
| Pagination and filters | fastapi-query | The same paging and filter rules on every list endpoint |
| Access control | RBAC | Roles and permissions applied per service |
| Logging | Loguru | One logging setup for all services |
| Workflows | Prefect | Repeatable data and background jobs |
| Eventing | Apache Kafka | Services publish and react to events |
| Scheduling | rrule | Recurring tasks written as recurrence rules |
Folder structure for each service
ZENLEAF uses a microservice folder pattern. Each business service has the same files, so any developer can find their way around.
| File | What it holds |
|---|---|
| model.py | Database models for the service |
| schema.py | Request and response shapes |
| event.py | Events the service publishes or listens to |
| dependency.py | Shared dependencies, such as the current user |
| service.py | Business logic that runs the use case |
| repository.py | Database reads and writes |
| rule.py | Business rules, kept apart from the service flow |
| router.py | The API endpoints for the service |
A generator that builds the service folders
The generator uses templates to create the folder structure and basic CRUD for each service. It starts from a JSON description of the service.
01
Describe the service in JSON: its name, fields and relations.
02
Run the generator. It writes the folder for the service, with model, schema, repository, service and router files.
03
Add your business rules to rule.py and service.py. The generated CRUD endpoints stay in place.
Where your team adds value
The platform handles the common parts. Your team owns the decisions that are specific to your business.
Business logic
Written in rule.py and service.py, where it is easy to test and review.
Your data model
Designed per service, with the shared database setup underneath.
Your integrations
Connected through events and dependencies, not through shared code paths.
Your front end
Kept in the frontend folder, separate from the backend services.
What is a FastAPI starter framework?
It is a project base for FastAPI, the Python web framework. It sets up the folders, database access, authentication and common services once, so each new project starts from the same base.
Which parts of ZENLEAF are reused in every project?
Database access, authentication, pagination and filters, access control, logging, workflows, eventing and scheduling. Each project uses the same setup for these services.
How does the JSON generator work?
You describe a service in a JSON file. The generator fills in templates and writes the service folder with basic create, read, update and delete endpoints. Your team then adds the business rules.
Can ZENLEAF handle authentication and single sign-on?
Yes. Authentication uses OAuth2 and JWT tokens through fastapi-users. Fief provides single sign-on, so users can sign in once across several applications.
Do we own the code ZENLEAF produces?
Yes. The code you get is yours, agreed in writing before work starts.
Starting several Python projects?
Tell us what you are building. We will show how a shared base would fit your team and your next release.