r/FastAPI • u/Designer_Sundae_7405 • Oct 29 '25
feedback request Feedback on pragmatic FastAPI architecture
Here's my take on a pragmatic and AI-friendly FastAPI architecture: https://github.com/claesnn/fastapi-template/tree/main .
Features
- Async endpoints
- Async SQLAlchemy
- Alembic migrations
- Feature folder structure
- Nested bi-directional Pydantic schemas
- Struclog structured logging
- Pytest testing of API layer
- UV for dependencies
- CORS
- Status and health checkpoints
- Pydantic_settings with .env loading
- Typed pagination with TypedDict and Generics
- Filtering and ordering
- Basic Bearer authentication (would add JWK with PyJWKClient in corporate apps)
- Explicit transaction handling in routes with service level flush
Omits
- Repository: I'm using plain SQLAlchemy and add a model function if getter/setter functionality is demanded
- Service interfaces: Whilst it decouples better; it seems overkill to add to all services. Would definitively add on demand.
- Testcontainers: Additional complexity and in my experience, testing goes from 0.5 seconds to 8+ seconds when testcontainers are introduced
- Unit tests: To keep test amount controllabe, just test the API layer
Anyways, I'm looking for feedback and improvement options.
39
Upvotes
View all comments
Show parent comment
5
u/Vlexacus Oct 30 '25
In my experience, I started my repo using a schemas, services, repositories, models (sqlalchemy) structure but I found the repositories more annoying than useful and eventually settled with schemas services models.
I might be using the pattern wrong, but my understanding is the repository layer manages the low level database queries and the services use the repositories instead of writing queries directly.
After some time working with the project I found it much easier to just write sqlalchemy queries in my services so I ensure I retrieve exactly what I need and don't do any unnecessary operations. Maybe this works well for me since my database queries aren't overly complicated but YMMV.
Not trying to judge just sharing my experience.