Skip to main content
Chapi Assistant uses Git-based templates to scaffold new projects with Clean Architecture. Templates provide a consistent starting point with proper folder structure, dependencies, and configuration.

Default Template

Chapi’s default template for .NET projects:
https://github.com/Start-Z/CleanArchitecture-Template.git
This template provides:
  • Clean Architecture structure
  • Dependency Injection configuration
  • Entity Framework Core setup
  • CQRS pattern implementation
  • Repository pattern interfaces

Template Structure

A Chapi-compatible template follows this structure:
CleanArchitecture-Template/
├── API/
│   ├── Controllers/          # Classic architecture
│   │   └── [Module]/
│   │       └── [Module]Controller.cs
│   ├── Endpoints/            # Ardalis architecture
│   │   └── [Module]/
│   │       ├── Get.cs
│   │       ├── Post.cs
│   │       └── GetById.cs
│   ├── Config/
│   │   ├── DependencyInjection.cs
│   │   └── DatabaseConfiguration.cs
│   ├── Program.cs
│   └── appsettings.json
├── Application/
│   ├── UseCases/
│   ├── Services/
│   └── DTOs/
├── Domain/
│   ├── Entities/
│   ├── Interfaces/
│   ├── Common/
│   │   └── Result.cs
│   └── Enums/
├── Infrastructure/
│   ├── Persistence/
│   │   ├── [DbName]Context.cs
│   │   └── Repositories/
│   ├── Services/
│   └── Configuration/
└── Tests/
    ├── UnitTests/
    └── IntegrationTests/

Template Processing

When creating a project from a template, Chapi performs these steps:
1

Clone Template

The template repository is cloned:
var cloneResult = await _gitRepository.CloneAsync(
    templateUrl, 
    targetPath
);
Example:
git clone https://github.com/Start-Z/CleanArchitecture-Template.git \
    C:\Projects\MyApiProject
2

Remove Git Metadata

Original Git history is removed:
string gitPath = Path.Combine(targetPath, ".git");
if (Directory.Exists(gitPath))
{
    DeleteDirectory(gitPath);
}
This ensures your project starts with a clean Git history.
3

Rename Template Structure

The template service renames all references:
string oldName = Path.GetFileNameWithoutExtension(templateUrl);
// oldName: "CleanArchitecture-Template"
// newName: "MyApiProject"

await _templateService.RenameTemplateAsync(
    targetPath, 
    oldName, 
    projectName, 
    onProgress
);
This includes:
  • Folder names: CleanArchitecture-Template.APIMyApiProject.API
  • File names: CleanArchitecture-Template.csprojMyApiProject.csproj
  • Namespaces: using CleanArchitecture-Template.Domainusing MyApiProject.Domain
  • References: All project references updated
4

Initialize Git Repository

A fresh Git repository is created:
await _gitRepository.InitAsync(targetPath);
This creates a new .git folder and initial commit.
5

Add Remote Origin

If a remote URL was provided:
if (!string.IsNullOrWhiteSpace(remoteUrl))
{
    await _gitRepository.AddRemoteAsync(
        targetPath, 
        "origin", 
        remoteUrl
    );
}

Architecture Detection

Chapi detects the template’s architecture style:
string apiProjectPath = FindApiDirectory.GetDirectory(projectDirectory);
bool isArdalis = Directory.Exists(
    Path.Combine(apiProjectPath, "Endpoints")
);
string apiSubFolder = isArdalis ? "Endpoints" : "Controllers";
If API/Endpoints/ folder exists:
✓ Ardalis (Endpoints) architecture detected
✓ Using generic repository pattern
✓ Scrutor auto-discovery enabled
✓ Minimal API style
Generated modules will use:
  • FastEndpoints or Ardalis.Endpoints
  • IRepository<T> generic interface
  • Automatic DI registration

Creating Custom Templates

You can create your own templates:
1

Create Repository

  1. Create a new Git repository (GitHub/GitLab)
  2. Name it descriptively (e.g., MyCompany-DDD-Template)
  3. Make it public or accessible to Chapi
2

Define Structure

Create your preferred structure:
MyTemplate/
├── src/
│   ├── MyTemplate.API/
│   ├── MyTemplate.Application/
│   ├── MyTemplate.Domain/
│   └── MyTemplate.Infrastructure/
├── tests/
│   └── MyTemplate.Tests/
├── docs/
├── .gitignore
└── README.md
3

Add Core Files

Include essential files:API/Program.cs:
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddApplicationServices();
builder.Services.AddInfrastructureServices();

var app = builder.Build();
app.MapControllers();
app.Run();
Domain/Common/Result.cs:
public class Result<T>
{
    public bool IsSuccess { get; set; }
    public T Data { get; set; }
    public string Error { get; set; }
    
    public static Result<T> Success(T data) => 
        new() { IsSuccess = true, Data = data };
    
    public static Result<T> Fail(string error) => 
        new() { IsSuccess = false, Error = error };
}
4

Configure Dependencies

Add NuGet packages:
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Ardalis.Result" Version="8.0.0" />
5

Use Your Template

Specify your template URL when creating projects:
var request = new CreateProjectRequest(
    projectName: "MyNewProject",
    parentDirectory: "C:\\Projects",
    templateUrl: "https://github.com/YourOrg/MyTemplate.git",
    remoteUrl: "https://github.com/YourOrg/MyNewProject.git"
);

Template Best Practices

Don’t hardcode project names in templates:Bad:
namespace MySpecificProject.Domain;
Good:
namespace TemplateName.Domain;
// Will be renamed to: YourProject.Domain
Provide documentation:
# Project Template

## Structure
- API: Web API layer
- Application: Business logic
- Domain: Core entities
- Infrastructure: External dependencies

## Getting Started
1. Restore packages: `dotnet restore`
2. Update connection string in appsettings.json
3. Run migrations: `dotnet ef database update`
4. Start: `dotnet run`
Include only essential packages:
  • Entity Framework Core
  • Dependency Injection
  • Common libraries (e.g., Ardalis.Result)
Let users add specific packages as needed.
Provide sample configurations:
// appsettings.json
{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=MyDb;Trusted_Connection=True;"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    }
  }
}

Template Variants

Traditional Clean Architecture:
├── API (Presentation)
├── Application (Use Cases)
├── Domain (Entities, Interfaces)
└── Infrastructure (Data, External)
Best for: Enterprise applications, maintainability

Template Registry

Commonly used templates:

Chapi Default

https://github.com/Start-Z/
CleanArchitecture-Template.git
Clean Architecture with Controllers/Endpoints support

Custom Template

Create your own template repository and use its URL during project creation

Troubleshooting

Template clone fails: Ensure:
  • Repository is public or you have access
  • URL is correct (ends with .git)
  • Internet connection is stable
Rename fails: Ensure template uses consistent naming conventions (template name in all files/folders)
Build fails after creation:
  • Restore NuGet packages: dotnet restore
  • Check for missing dependencies
  • Verify .NET SDK version compatibility

Template Validation

Before using a template, verify:
# Clone template locally
git clone https://github.com/YourOrg/YourTemplate.git
cd YourTemplate

# Test build
dotnet restore
dotnet build

# Check structure
tree /F

# Test rename manually
# (rename folders and update namespaces)

Next Steps

Creating Projects

Learn how to create projects from templates

Generating Modules

Scaffold modules in your template-based project

Build docs developers (and LLMs) love