Here’s a detailed summary of the StarterTemplate Architecture Documentation, crafted specifically for Reddit, along with examples for better understanding:


StarterTemplate: A Feature-Based Vertical Slice Architecture for .NET APIs

The StarterTemplate repository is designed to simplify scalable .NET API development by adopting a Feature-Based Vertical Slice Architecture. This approach emphasizes organizing code by business features and ensuring separation of concerns.

Core Highlights of the Architecture

  1. Feature-Based Organization:

  2. Vertical Slices:

  3. Automatic Registration:

  4. Minimal API with CQRS-like Pattern:

  5. Decorators for Validation and Caching:

Examples

Here are some practical examples to demonstrate the architecture:

1. Creating a Product Feature

2. Endpoints for Product Operations

3. Get Products with Pagination

public class GetProducts : SliceHandler<IResult, GetProducts>
{
    private readonly StarterTemplateContext _context;

    public GetProducts(StarterTemplateContext context) => _context = context;

    public override async Task<IResult> HandleAsync(CancellationToken cancellationToken = default)
    {
        var query = _context.Set<Product>().AsNoTracking().OrderBy(p => p.Name);

        var request = QueryBinder.Bind<CursorPaginationParams>();
        var paginatedResult = await query
            .Select(p => new GetProductDto
            {
                Id = p.Id,
                Name = p.Name,
                Description = p.Description,
                Price = p.Price,
                Status = p.Status,
                CreatedAt = p.CreatedAt
            })
            .PaginateAsync(request, cancellationToken);

        return Results.Ok(paginatedResult);
    }
}