Backend02 architecture and design
Business Logic Layer (BLL) (extra)
Separating business rules from data access
What is Business Logic Layer?
Business Logic Layer (BLL) is the part of the application that contains:
- Core rules of the system
- Validation logic
- Decision making
- Calculations
- Workflows
It is the brain of the application.
Where It Sits in Architecture
Typical layered architecture:
- Controller Layer (API Layer)
- Business Logic Layer
- Data Access Layer (Database Layer)
Flow:
Request → Controller → Business Logic → Database → Response
What Should Be Inside BLL?
- Business rules
- Data validation (domain level)
- Calculations
- Orchestration between multiple services
- Transaction handling
Example:
Creating an order:
- Check if user exists
- Check if product is in stock
- Calculate total price
- Apply discount
- Save order
- Reduce inventory
All this belongs in Business Logic Layer.
What Should NOT Be Inside BLL?
- HTTP request parsing
- Response formatting
- Database queries (raw SQL)
- Framework-specific code
BLL should not depend on web framework.
Why Separate Business Logic?
- Reusability
- Testability
- Clean architecture
- Easy maintenance
- Separation of concerns
Example (Simple Structure)
Controller:
- Accept request
- Call service method
- Return response
Service (Business Logic):
- Validate rules
- Perform operations
- Call repository
Repository:
- Handle database queries
Key Principle
Controllers should be thin.
Business logic should be inside services.
If logic grows inside controller, move it to BLL.