Flavors
Flavors are the fundamental building blocks of Tasteful applications. They represent modular, self-contained components that can be composed together to create complete applications. Each flavor encapsulates a specific domain or feature area with its own HTTP interface, business logic, and data access patterns.What is a Flavor?
A Flavor is a collection of related functionality organized into distinct layers:- Controllers - HTTP endpoints and request/response handling
- Services - Business logic and orchestration
- Repositories - Data access and persistence
- Configuration - Flavor-specific settings and dependencies
Basic Flavor Structure
A complete flavor consists of four main components working together:- Controller handles HTTP requests and delegates to services
- Service contains all business logic and coordinates with repositories
- Repository manages data access and persistence
- Configuration provides settings and dependencies
Key Features
1. Constructor-Based Initialization
Flavors use constructor-based initialization where you specify the components that make up your flavor:- Controller: Handles HTTP endpoints and routing (required)
- Services: Business logic components (optional)
- Repositories: Data access layer (optional)
- Configuration: Configuration class (optional)
2. HTTP Route Decorators
Controllers use decorators to define HTTP endpoints. These decorators mirror FastAPI’s functionality while integrating with Tasteful’s architecture:3. URL Prefixing and Organization
All routes in a controller are automatically prefixed based on the controller configuration, providing clean URL organization:4. Dependency Injection
Flavors leverage Tasteful’s dependency injection system to automatically wire up components. Dependencies are resolved based on constructor parameters:Built-in Flavors
Tasteful comes with several pre-built flavors for common functionality:- Health Flavor: Health checks and monitoring endpoints
- Identity Flavor: Authentication and user management
- Worker Flavor: Background task processing
Flavor Composition
Combine multiple flavors to build complete applications:Best Practices
1. Single Responsibility Principle
Each flavor should have a single, well-defined responsibility that aligns with a specific domain or feature area:2. Meaningful Naming
Use descriptive names that clearly communicate the purpose of flavors and their components:Migration from Microservices
When migrating from microservices to flavors:- Map service boundaries - Each microservice typically becomes a flavor
- Consolidate shared logic - Move common code to shared services or base classes
- Simplify data access - Replace multiple databases with shared repositories where appropriate
- Replace HTTP calls - Convert inter-service HTTP calls to direct service method calls
- Maintain transaction boundaries - Ensure data consistency is preserved during migration