dotnet-vertical-slice

.NET 10 Vertical Slice Architecture

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "dotnet-vertical-slice" with this command: npx skills add akires47/agent-skills/akires47-agent-skills-dotnet-vertical-slice

.NET 10 Vertical Slice Architecture

Organize code by feature, not by layer. Each feature is self-contained with its endpoint, request/response, validation, and handler in a single file.

Project Structure

src/ ├── Features/ │ ├── Products/ │ │ ├── GetProduct.cs │ │ ├── CreateProduct.cs │ │ └── ProductMapper.cs │ └── Orders/ │ └── ... ├── Shared/ │ ├── Results/ │ │ ├── Result.cs │ │ └── Error.cs │ └── Validation/ │ └── ValidationResult.cs ├── Entities/ └── Program.cs

Feature Slice Pattern

One file per operation containing everything needed:

// Features/Products/CreateProduct.cs public static class CreateProduct { public sealed record Request(string Name, decimal Price); public sealed record Response(int Id, string Name, decimal Price);

public static async Task<Result<Response>> HandleAsync(
    Request request, AppDbContext db, CancellationToken ct)
{
    var validation = Validate(request);
    if (!validation.IsValid)
        return validation.ToResult<Response>(null!);

    var product = new Product { Name = request.Name, Price = request.Price };
    db.Products.Add(product);
    await db.SaveChangesAsync(ct);

    return new Response(product.Id, product.Name, product.Price);
}

private static ValidationResult Validate(Request request) =>
    ValidationExtensions.Validate()
        .NotEmpty(request.Name, "Name")
        .GreaterThan(request.Price, 0, "Price");

public static void MapEndpoint(IEndpointRouteBuilder app) => app
    .MapPost("/api/products", async (Request request, AppDbContext db, CancellationToken ct) =>
        (await HandleAsync(request, db, ct)).ToCreatedResponse(r => $"/api/products/{r.Id}"))
    .WithName("CreateProduct")
    .WithTags("Products");

}

Core Principles

  • Result pattern only - Never throw exceptions, return Result<T> or Result

  • Static handlers - Use public static async Task<Result<T>> HandleAsync(...)

  • Inline validation - Validate at handler start, return early on failure

  • Manual mapping - Use extension methods in *Mapper.cs files

  • Projections - Use .Select() for queries, avoid loading full entities

References

See detailed implementations in the references/ folder:

  • Result Pattern - Error types, Result class, HTTP mapping

  • Validation - ValidationResult, fluent extensions

  • Feature Examples - CRUD, filtering, pagination

Guidelines

  • One feature = one file (endpoint + request/response + validation + handler)

  • Name files by operation: CreateProduct.cs , GetProducts.cs

  • Keep entities in shared folder (only cross-cutting concern)

  • Use [AsParameters] for query parameters

  • Group endpoints with .WithTags() for OpenAPI

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

vercel-composition-patterns

React composition patterns that scale. Use when refactoring components with boolean prop proliferation, building flexible component libraries, or designing reusable APIs. Triggers on tasks involving compound components, render props, context providers, or component architecture. Includes React 19 API changes.

Repository Source
86.7K23Kvercel
Automation

vercel-react-native-skills

React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.

Repository Source
60.8K23Kvercel
Automation

supabase-postgres-best-practices

Postgres performance optimization and best practices from Supabase. Use this skill when writing, reviewing, or optimizing Postgres queries, schema designs, or database configurations.

Repository Source
35.5K1.6Ksupabase
Automation

sleek-design-mobile-apps

Use when the user wants to design a mobile app, create screens, build UI, or interact with their Sleek projects. Covers high-level requests ("design an app that does X") and specific ones ("list my projects", "create a new project", "screenshot that screen").

Repository Source