How mehdibennis/bookly works
Bookly is a FastAPI books-and-authors API. Clients call versioned CRUD and pagination endpoints; routes validate and map DTOs, services apply domain rules, and repositories read or mutate PostgreSQL through the async unit of work. Paginated collections use Redis caching. Protected operations use Keycloak JWT authentication, while admin-user routes and system health endpoints are separate API branches. The tree and excerpts support these main boundaries; some route, dependency, and integration wiring is documented but not sampled, so uncertain call edges are omitted.
Main entry points: main.py FastAPI App · books.py Book Routes · authors.py Author Routes · book_service.py Book Service
Components 27
HTTP API
- FastAPI App
app/main.py - Book Routes
app/api/v1/routes/books.py - Author Routes
app/api/v1/routes/authors.py - Admin User Routes
app/api/v1/routes/admin_users.py - System Endpoints
app/api/system.py - Request Schemas
app/schemas - API Mappers
app/api/mappers.py - Service Dependencies
app/api/dependencies.py
Domain Services
- Book Service
app/services/book_service.py - Author Service
app/services/author_service.py - Domain Contracts
app/domain
Persistence
- Book Repository
app/repositories/book_repository.py - Author Repository
app/repositories/author_repository.py - Unit of Work
app/db/unit_of_work.py - Async DB Session
app/db/session.py - Book Author Models
app/db/models - PostgreSQL
Platform Integrations
- Redis Cache
app/core/cache_service.py - Redis
- JWT Authentication
app/core/keycloak_auth.py - Keycloak Admin
app/core/keycloak_admin.py - Keycloak
- Request Middleware
app/core/middleware.py - Rate Limiter
app/core/limiter.py - Error Handlers
app/core/error_handlers.py - Logging & Monitoring
app/core/observability.py
Other components
- API Client
Connections 38
- API Client → FastAPI App: sends HTTP
- FastAPI App → Book Routes: dispatches
- FastAPI App → Author Routes: dispatches
- FastAPI App → Admin User Routes: dispatches
- FastAPI App → System Endpoints: dispatches
- FastAPI App → Request Middleware: installs middleware
- FastAPI App → Rate Limiter: registers limits
- FastAPI App → Error Handlers: registers handlers
- FastAPI App → Logging & Monitoring: configures monitoring
- Book Routes → Request Schemas: validates DTOs
- Author Routes → Request Schemas: validates DTOs
- Book Routes → API Mappers: maps data
- Author Routes → API Mappers: maps data
- Book Routes → Service Dependencies: resolves services
- Author Routes → Service Dependencies: resolves services
- Book Routes → Book Service: calls
- Author Routes → Author Service: calls
- Admin User Routes → JWT Authentication: authenticates
- Book Routes → JWT Authentication: authenticates protected calls
- Author Routes → JWT Authentication: authenticates protected calls
- Admin User Routes → Keycloak Admin: manages users
- JWT Authentication → Keycloak: validates tokens
- Keycloak Admin → Keycloak: admin requests
- Book Service → Book Repository: reads and writes
- Author Service → Author Repository: reads and writes
- Book Service → Unit of Work: runs transactions
- Author Service → Unit of Work: runs transactions
- Book Service → Redis Cache: gets and invalidates
- Author Service → Redis Cache: gets and sets
- Book Service → Domain Contracts: uses contracts
- Author Service → Domain Contracts: uses contracts
- Book Repository → Async DB Session: executes queries
- Author Repository → Async DB Session: executes queries
- Unit of Work → Async DB Session: controls transaction
- Async DB Session → PostgreSQL: queries
- Book Repository → Book Author Models: maps entities
- Author Repository → Book Author Models: maps entities
- Redis Cache → Redis: reads and writes pages