πŸ”„Flexbase Control Flow

🎯 Overview

This document explains the complete control flow for Flexbase features - from API call to execution completion. We'll cover one Insert (POST) and one Query (GET) example.


πŸ“ Insert Feature Flow: AddOrder

1. API Request

POST /api/Orders/AddOrder
Content-Type: application/json

{
  "customerId": "12345",
  "totalAmount": 299.99,
  "orderItems": [...]
}

2. Controller Layer

[HttpPost]
[Route("AddOrder")]
public async Task<IActionResult> AddOrder([FromBody] AddOrderDto dto)
{
    return await RunService(201, dto, _processOrdersService.AddOrder);
}

What happens: Controller receives request, validates DTO, calls service

3. Service Layer

What happens: Service creates command, calls handler

4. Command Handler

What happens: Handler orchestrates the operation, calls domain, persists data, publishes events

5. Domain Method (Your Business Logic)

What happens: Domain validates business rules, applies logic, returns entity

6. Database Persistence

What happens: Entity Framework saves to database

7. Event Publishing

What happens: Domain events published to message bus for side effects

8. Response


πŸ” Query Feature Flow: GetOrders

1. API Request

2. Controller Layer

What happens: Controller receives request, calls service

3. Service Layer

What happens: Service calls query handler

4. Query Handler

What happens: Handler executes optimized database query with projection

5. Database Query

What happens: Only required fields fetched from database

6. Projection Mapping

What happens: Database results mapped to DTO

7. Response


πŸ”„ Complete Flow Summary

Insert Flow:

Query Flow:


🎯 Key Points

Insert Features:

  • Command Pattern - Encapsulates operation

  • Domain Logic - Business rules in domain layer

  • Event Publishing - Side effects handled asynchronously

  • Transaction Management - Automatic rollback on errors

Query Features:

  • Projection-Based - Only fetch required fields

  • Optimized SQL - Generated automatically

  • Type Safety - Compile-time validation

  • Performance - Database-level optimization

Common Benefits:

  • Separation of Concerns - Each layer has single responsibility

  • Testability - Each layer can be tested independently

  • Maintainability - Clear, readable code structure

  • Consistency - Same pattern across all features


This control flow ensures reliable, maintainable, and performant enterprise applications with Flexbase.

Last updated