CtrlK
BlogDocsLog inGet started
Tessl Logo
SkillPublic

scaffold-slice

Scaffolding guide for building clean CQRS vertical use-case slices in FinanceHub (.NET 10), covering Application Commands/Queries, Handler Interfaces, Rich Domain Models, and Minimal API endpoints.

Quality

81%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide
SecuritybySnyk

Passed

No findings from the security scan

SKILL.md
Quality
Evals
Security

.NET 10 Vertical Slice Scaffolding Skill — FinanceHub

⚡ Trigger / Slash Command

/scaffold-slice <Service> <UseCase>

Use esta habilidade para criar novos Vertical Slices CQRS. Lembre-se: Interface (I<Name>Handler.cs) e Implementação (<Name>Handler.cs) DEVEM residir em arquivos .cs separados.


1. Directory Structure Conventions

In FinanceHub microservices, code is organized by Clean Architecture layers with clear vertical Use-Case slicing inside Application and API projects:

src/Services/FinanceHub.<ServiceName>/
├── FinanceHub.<ServiceName>.Domain/
│   ├── Entities/                 // Aggregate Roots & Rich Domain Entities
│   ├── ValueObjects/              // Immutable Value Objects (Records)
│   ├── Exceptions/                // Strongly-typed Domain Exceptions
│   └── Events/                    // Domain Events
├── FinanceHub.<ServiceName>.Application/
│   ├── Commands/                  // Command DTOs & Handlers
│   │   └── IngestTransaction/
│   │       ├── IngestTransactionCommand.cs
│   │       ├── IngestTransactionCommandHandler.cs
│   │       └── IIngestTransactionCommandHandler.cs
│   ├── Queries/                   // Query DTOs & Handlers
│   │   └── GetTransactions/
│   │       ├── GetTransactionsQuery.cs
│   │       ├── GetTransactionsQueryHandler.cs
│   │       └── IGetTransactionsQueryHandler.cs
│   ├── Interfaces/                // Repository & Infrastructure Interfaces
│   └── DTOs/                      // Output/Read DTOs
├── FinanceHub.<ServiceName>.Infrastructure/
│   ├── Persistence/               // DbContext, EF Core Configurations & Repositories
│   └── DependencyInjection.cs
└── FinanceHub.<ServiceName>.Api/
    ├── Endpoints/                 // Minimal API Endpoint Mappings
    ├── Middleware/                // GlobalExceptionHandler (RFC 7807)
    ├── Program.cs                 // Top-Level Statements + namespaced Program
    └── DependencyInjection.cs

2. Architectural Guidelines & Hard Rules

  1. Rich Domain Model (No Anemic Entities):

    • Invariants and validations MUST be encapsulated 100% inside Domain Aggregate Roots and Value Objects.
    • Domain errors throw strongly-typed exceptions derived from DomainException (e.g. InvalidCurrencyDomainException, TransactionNotFoundDomainException).
    • Zero FluentValidation classes — validation logic resides exclusively in the Domain layer.
  2. Strict Dependency Inversion Principle (DIP):

    • Every Command Handler and Query Handler MUST define and implement a dedicated interface (e.g. IIngestTransactionCommandHandler, IGetTransactionsQueryHandler).
    • Endpoints MUST inject Handler interfaces (IIngestTransactionCommandHandler), never concrete implementation classes.
  3. Global Exception Handling (RFC 7807 ProblemDetails):

    • APIs handle domain and system exceptions globally via IExceptionHandler (GlobalExceptionHandler).
    • Responses return RFC 7807 ProblemDetails with traceId and errorCode. Endpoints perform ZERO manual try/catch blocks.
  4. Environment Configuration Loading:

    • Environment variables must be loaded from .env via DotNetEnv.Env.TraversePath().Load() on Program.cs startup.
    • Zero inline hardcoded fallback defaults in code. Fail-fast if required environment variables are missing.

3. Step-by-Step Feature Scaffolding Workflow

Step 1: Define Domain Logic & Exception (Domain Layer)

Encapsulate invariants directly inside Aggregate Root or Value Objects:

namespace FinanceHub.TransactionAggregator.Domain.Entities;

public class CanonicalTransaction
{
    public Guid Id { get; private set; }
    public string UserId { get; private set; }
    public Money Amount { get; private set; }
    public Guid CategoryId { get; private set; }

    public void CategorizeManually(Guid newCategoryId)
    {
        if (newCategoryId == Guid.Empty)
        {
            throw new InvalidCategoryIdDomainException();
        }

        CategoryId = newCategoryId;
    }
}

Step 2: Define Command DTO (Application Layer)

The Command or Query record is defined in its own file alongside the handler, but the interface contract MUST always live in a separate dedicated file:

CategorizeTransactionCommand.cs:

namespace FinanceHub.TransactionAggregator.Application.Commands.CategorizeTransaction;

public record CategorizeTransactionCommand(
    Guid TransactionId,
    string UserId,
    Guid NewCategoryId,
    bool CreateCustomRule);

ICategorizeTransactionCommandHandler.cs ← dedicated contract file:

namespace FinanceHub.TransactionAggregator.Application.Commands.CategorizeTransaction;

public interface ICategorizeTransactionCommandHandler
{
    Task Handle(CategorizeTransactionCommand command, CancellationToken cancellationToken);
}

[!IMPORTANT] Interface and implementation MUST ALWAYS be in separate files. Never co-locate a public interface I<Name> and public class <Name> in the same .cs file. This rule applies to all handlers, repositories, and services. Follow the pattern established in FinanceHub.PluggyIntegration.Application (e.g., ISyncAllPluggyAccountsCommandHandler.cs and SyncAllPluggyAccountsCommandHandler.cs as separate files).

Step 3: Implement Handler Class (Application Layer)

namespace FinanceHub.TransactionAggregator.Application.Commands.CategorizeTransaction;

public class CategorizeTransactionCommandHandler : ICategorizeTransactionCommandHandler
{
    private readonly ITransactionRepository _transactionRepository;

    public CategorizeTransactionCommandHandler(ITransactionRepository transactionRepository)
    {
        _transactionRepository = transactionRepository;
    }

    public async Task Handle(CategorizeTransactionCommand command, CancellationToken cancellationToken)
    {
        var transaction = await _transactionRepository.GetByIdAsync(command.TransactionId, cancellationToken);
        if (transaction == null)
        {
            throw new TransactionNotFoundDomainException(command.TransactionId);
        }

        transaction.CategorizeManually(command.NewCategoryId);
        await _transactionRepository.UpdateAsync(transaction, cancellationToken);
    }
}

Step 4: Map Minimal API Endpoint (API Layer)

namespace FinanceHub.TransactionAggregator.Api.Endpoints;

public static class TransactionEndpoints
{
    public static IEndpointRouteBuilder MapTransactionEndpoints(this IEndpointRouteBuilder endpoints)
    {
        var group = endpoints.MapGroup("/api/v1/transactions")
            .WithTags("Transactions");

        group.MapPatch("/{id:guid}/categorize", async (
            Guid id,
            CategorizeTransactionRequest request,
            ICategorizeTransactionCommandHandler handler,
            CancellationToken cancellationToken) =>
        {
            var command = new CategorizeTransactionCommand(
                id,
                request.UserId,
                request.NewCategoryId,
                request.CreateCustomRule);

            await handler.Handle(command, cancellationToken);
            return Results.NoContent();
        })
        .WithName("CategorizeTransaction")
        .Produces(StatusCodes.Status204NoContent)
        .ProducesProblem(StatusCodes.Status404NotFound);

        return endpoints;
    }
}

4. Verification Checklist

  1. Interface Binding: Register interface + implementation in DependencyInjection.cs (services.AddScoped<ICategorizeTransactionCommandHandler, CategorizeTransactionCommandHandler>();).
  2. Unit Tests: Add unit tests for Domain entity methods, Application Handlers (with NSubstitute mocks), and API endpoints (WebApplicationFactory).
  3. Execution: Run dotnet test to confirm 100% GREEN build and test execution.
Repository

JoseMD12/finance-hub

Path

.agents/skills/scaffold-slice/SKILL.md

Last updated
First committed

Is this your skill?

If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.