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.
81%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
/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.
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.csRich Domain Model (No Anemic Entities):
DomainException (e.g. InvalidCurrencyDomainException, TransactionNotFoundDomainException).Strict Dependency Inversion Principle (DIP):
IIngestTransactionCommandHandler, IGetTransactionsQueryHandler).IIngestTransactionCommandHandler), never concrete implementation classes.Global Exception Handling (RFC 7807 ProblemDetails):
IExceptionHandler (GlobalExceptionHandler).ProblemDetails with traceId and errorCode. Endpoints perform ZERO manual try/catch blocks.Environment Configuration Loading:
.env via DotNetEnv.Env.TraversePath().Load() on Program.cs startup.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;
}
}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>andpublic class <Name>in the same.csfile. This rule applies to all handlers, repositories, and services. Follow the pattern established inFinanceHub.PluggyIntegration.Application(e.g.,ISyncAllPluggyAccountsCommandHandler.csandSyncAllPluggyAccountsCommandHandler.csas separate files).
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);
}
}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;
}
}DependencyInjection.cs (services.AddScoped<ICategorizeTransactionCommandHandler, CategorizeTransactionCommandHandler>();).NSubstitute mocks), and API endpoints (WebApplicationFactory).dotnet test to confirm 100% GREEN build and test execution.JoseMD12/finance-hub
2ca9a0b
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.