Skip to main content

Overview

Chapi Assistant provides powerful code generation capabilities for .NET WPF projects, automatically creating modules with Domain, Application, Infrastructure, and API layers following Clean Architecture principles.
Code generation is powered by Roslyn-based code analysis and manipulation for type-safe, production-ready code.

Module Generation

Generate Complete Modules

Create full-stack modules with all architectural layers in one command:
var result = await generateModuleUseCase.ExecuteAsync(
    projectDirectory: @"C:\Projects\MyApp",
    moduleNames: "Customer;Product;Order",
    dbChoice: "P" // P = Postgres, S = Sybase
);
Generate a single module:
await generateModuleUseCase.ExecuteAsync(
    @"C:\Projects\MyApp",
    "Customer",
    "P"
);
Creates:
  • Domain entities and value objects
  • Application use cases
  • Infrastructure repositories
  • API controllers and endpoints

API Endpoint Generation

Add Individual Endpoints

Generate specific API endpoints for existing modules:
var result = addApiEndpointUseCase.Execute(
    projectPath: @"C:\Projects\MyApp",
    moduleName: "Customer",
    operation: "Create",
    methodName: "CreateCustomer",
    includeAppLayer: true
);
projectPath
string
required
Path to the project root directory.
moduleName
string
required
Name of the module (e.g., “Customer”, “Product”).
operation
string
required
HTTP operation type: “Create”, “Read”, “Update”, “Delete”, “List”.
methodName
string
required
Name of the API method to generate.
includeAppLayer
boolean
Whether to generate the corresponding Application layer use case (default: false).

Supported Operations

Create

POST endpoint for creating new entities
[HttpPost]
public async Task<IActionResult> CreateCustomer(...)

Read

GET endpoint for retrieving a single entity
[HttpGet("{id}")]
public async Task<IActionResult> GetCustomer(int id)

Update

PUT endpoint for updating existing entities
[HttpPut("{id}")]
public async Task<IActionResult> UpdateCustomer(...)

Delete

DELETE endpoint for removing entities
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteCustomer(int id)

List

GET endpoint for retrieving multiple entities
[HttpGet]
public async Task<IActionResult> ListCustomers(...)

Layer-Specific Generation

Generate code for specific architectural layers:
Add application layer methods (use cases):
var result = addApplicationMethodUseCase.Execute(
    projectPath: @"C:\Projects\MyApp",
    moduleName: "Customer",
    operation: "Create",
    methodName: "CreateCustomer"
);
Generates:
  • Use case class
  • Request/Response DTOs
  • Validation logic

Dependency Injection Setup

Automatically configure dependency injection for generated modules:
var result = addDependencyInjectionUseCase.Execute(
    projectPath: @"C:\Projects\MyApp",
    moduleName: "Customer",
    operations: new[] { "Create", "Read", "Update", "Delete" }
);
This adds service registrations to your DI container for all specified operations.

What Gets Registered

// Application layer
services.AddScoped<ICreateCustomerUseCase, CreateCustomerUseCase>();
services.AddScoped<IReadCustomerUseCase, ReadCustomerUseCase>();

// Infrastructure layer
services.AddScoped<ICustomerRepository, CustomerRepository>();

Rollback Support

Code generation includes automatic rollback capabilities:
var rollbackEntry = new RollbackManager.RollbackEntry();

var result = addApiEndpointUseCase.Execute(
    projectPath,
    moduleName,
    operation,
    methodName,
    rollbackEntry: rollbackEntry
);

if (result.IsSuccess)
{
    // Rollback entry contains information to undo changes
    var entry = result.Value;
}
Rollback entries track all file modifications and additions, allowing you to undo code generation if needed.

Generated Code Structure

When you generate a module named “Customer”, Chapi creates:
MyApp/
├── Domain/
│   └── Entities/
│       └── Customer.cs
├── Application/
│   └── UseCases/
│       └── Customers/
│           ├── CreateCustomerUseCase.cs
│           ├── GetCustomerUseCase.cs
│           └── UpdateCustomerUseCase.cs
├── Infrastructure/
│   └── Repositories/
│       └── CustomerRepository.cs
└── API/
    └── Controllers/
        └── CustomersController.cs

Best Practices

  • Use singular names (“Customer” not “Customers”)
  • Use PascalCase
  • Keep names concise and descriptive
  • Avoid abbreviations unless widely understood
  • Start with basic CRUD operations
  • Add custom operations as needed
  • Group related operations in the same module
  • Use descriptive method names for custom operations
  • Review generated code before committing
  • Customize validation logic as needed
  • Add business rules to domain layer
  • Adjust DTOs to match your requirements
  • Choose the correct database provider upfront
  • Changing database provider later requires manual updates
  • Ensure connection strings are configured
  • Test repository methods after generation

Error Handling

if (!result.IsSuccess)
{
    // "No hay proyecto seleccionado"
    // "Debe ingresar al menos un nombre de módulo"
    // "La ruta del proyecto no puede estar vacía"
    // "El nombre del módulo no puede estar vacío"
    // "No se pudo agregar el endpoint API"
    
    Console.WriteLine($"Error: {result.Error}");
}

Advanced Features

Custom Templates

Chapi uses Roslyn-based code generation, allowing customization of templates and patterns.

Batch Generation

Generate multiple modules simultaneously with semicolon-separated names.

Incremental Updates

Add endpoints to existing modules without regenerating everything.

Type Safety

All generated code is type-safe and follows C# best practices.

Project Creation

Create projects with templates ready for code generation

AI Assistant

Use AI to suggest module structures and operations

Build docs developers (and LLMs) love