AppTo.CodeGen 1.1.0

dotnet tool install --global AppTo.CodeGen --version 1.1.0
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local AppTo.CodeGen --version 1.1.0
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=AppTo.CodeGen&version=1.1.0
                    
nuke :add-package AppTo.CodeGen --version 1.1.0
                    

AppTo.CodeGen

A powerful .NET global tool for generating CQRS (Command Query Responsibility Segregation) pattern code following Clean Architecture principles.

πŸš€ Features

  • Command & Query Generation: Generate Command, CommandHandler, Query, and QueryHandler classes
  • Validator Generation: Automatically create Command and Query validators
  • Request & Response Models: Automatically create Request and Response classes
  • API Endpoints: Generate REST API endpoints with proper HTTP methods
  • Smart Project Detection: Automatically detect project structure and naming
  • Flexible Configuration: Support for custom project names and endpoint controllers
  • Clean Architecture: Follows Clean Architecture folder structure conventions
  • Modern Architecture: Built with Clean Architecture, Dependency Injection, and SOLID principles

πŸ—οΈ Architecture

This tool is built using modern software architecture principles:

  • Clean Architecture: Separation of concerns with Core, Application, Infrastructure, and Presentation layers
  • Dependency Injection: Built-in DI container for better testability and maintainability
  • SOLID Principles: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion
  • CQRS Pattern: Command Query Responsibility Segregation for better separation of concerns
  • Template Engine: Pluggable template system for code generation

πŸ“¦ Installation

dotnet tool install --global AppTo.CodeGen

🎯 Usage

Basic Command Generation

# Generate a command with automatic project detection
codegen add feature QrSale --type command --ep Sale

# Generate a query
codegen add feature GetUser --type query --ep User

# Generate without validator (validator is enabled by default)
codegen add feature Login --type command --validator:false

Advanced Usage

# Specify custom project name
codegen add feature AddCard --type command --ep Card --projectName Metropol.LUKE

# Generate query with custom project name
codegen add feature GetProducts --type query --ep Product --projectName MyCompany.API

πŸ“ Generated Structure

When you run codegen add feature QrSale --type command --ep Sale, it creates:

Application/
└── QrSale/
    └── Commands/
        β”œβ”€β”€ QrSaleCommand.cs
        β”œβ”€β”€ QrSaleCommandHandler.cs
        └── QrSaleCommandValidator.cs

Abstraction/
└── QrSale/
    β”œβ”€β”€ Request/
    β”‚   └── QrSaleRequest.cs
    └── Response/
        └── QrSaleResponse.cs

Controllers/
└── SaleController.cs (endpoint added)

πŸ”§ Command Options

Option Description Example
featureName Name of the feature to generate QrSale
--type Type: command or query --type command
--ep Endpoint controller name --ep Sale
--projectName Custom project name (optional) --projectName Metropol.LUKE
--prop-req Request ΓΆzellikleri --prop-req "Name:string,Email:string,Age:int,OrderId:int"
--prop-resp Response ΓΆzellikleri --prop-resp "Name:string,Email:string,Age:int,OrderId:int"
--validator Validator oluştur (varsayılan: true) --validator:false

πŸ“ Properties Examples

# Sadece Request properties
codegen add feature UserRegistration --type command --prop-req "Name:string,Email:string,Age:int,OrderId:int"

# Sadece Response properties
codegen add feature GetUser --type query --prop-resp "Name:string,Email:string,Age:int,OrderId:int"

# Hem Request hem Response properties
codegen add feature CreateProduct --type command --prop-req "Name:string,Price:decimal" --prop-resp "Id:int,Name:string,Price:decimal,CreatedDate:DateTime"

# Hiçbir property belirtmezseniz (boş sınıflar)
codegen add feature SimpleCommand --type command

πŸ“ Generated Code Examples

Request Class

namespace MyProject.Abstraction.UserRegistration.Request;

public class UserRegistrationRequest
{
    public string Name { get; set; }
    public string Email { get; set; }
    public int Age { get; set; }
    public int OrderId { get; set; }
}

Response Class

namespace MyProject.Abstraction.UserRegistration.Response;

public class UserRegistrationResponse
{
    public string Name { get; set; }
    public string Email { get; set; }
    public int Age { get; set; }
    public int OrderId { get; set; }
}

Command Class

using MyProject.Infrastructure.CQRS.Concrete;
using MyProject.Abstraction.QrSale.Response;

namespace MyProject.Application.QrSale.Commands;

public class QrSaleCommand : MetropolCommand<QrSaleResponse>
{
    // TODO: Add Business Logic here.
}

Command Handler

using MyProject.Infrastructure.CQRS.Concrete;
using MyProject.Abstraction.QrSale.Response;

namespace MyProject.Application.QrSale.Commands;

public class QrSaleCommandHandler : MetropolCommandHandler<QrSaleCommand, QrSaleResponse>
{
    public override async Task<QrSaleResponse?> Handle(QrSaleCommand request, CancellationToken cancellationToken)
    {
        // TODO: Add Business Logic here.
        return new QrSaleResponse();
    }
}

Command Validator

using MyProject.Infrastructure.Validation;

namespace MyProject.Application.QrSale.Commands;

public class QrSaleCommandValidator : MetropolValidator<QrSaleCommand>
{
    public QrSaleCommandValidator()
    {

    }
}

API Endpoint

[HttpPost]
[Route("qr-sale")]
[ProducesResponseType(typeof(MetropolApiResponse<QrSaleResponse>), (int)System.Net.HttpStatusCode.OK)]
public async Task<MetropolApiResponse<QrSaleResponse>> QrSale(
    [FromBody] QrSaleRequest request,
    CancellationToken cancellationToken)
{
    var response = await _cqrsProcessor.ProcessAsync(new QrSaleCommand(), cancellationToken);
    return SetResponse(response);
}

πŸ—οΈ Project Structure Requirements

The tool expects the following folder structure:

YourProject/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ YourProject.Application/
β”‚   β”œβ”€β”€ YourProject.Abstraction/
β”‚   └── YourProject.Controllers/
└── YourProject.sln

πŸ” Project Name Detection

The tool automatically detects your project name using this priority:

  1. src/ folder: Uses the first directory name in the src/ folder
  2. Manual override: Use --projectName parameter to specify custom name

πŸ› οΈ Requirements

  • .NET 9.0 or later
  • Clean Architecture project structure
  • CQRS pattern implementation

Made with ❀️ by Batuhan Kayaoğlu

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
1.1.0 174 10/16/2025
1.0.1 176 10/13/2025
1.0.0 169 10/13/2025