Skip to main content

Overview

The Project Management use cases handle creating, adding, cloning, switching, and removing projects in Chapi Assistant.

AddProjectUseCase

Adds an existing project directory to Chapi Assistant’s workspace.

Method Signature

public async Task<Result> ExecuteAsync(string projectPath)
projectPath
string
required
The absolute path to the project directory to add
Result
Result
A Result object indicating success or failure

Example Usage

var addProjectUseCase = new AddProjectUseCase(projectRepository);
var result = await addProjectUseCase.ExecuteAsync("/path/to/project");

if (result.IsSuccess)
{
    Console.WriteLine("Project added successfully");
}
else
{
    Console.WriteLine($"Error: {result.Error}");
}

CreateProjectUseCase

Creates a new project from a template repository, renaming files and initializing Git.

Request Model

public record CreateProjectRequest(
    string ProjectName,
    string ParentDirectory,
    string TemplateUrl,
    string RemoteUrl = null
);

Method Signature

public async Task<Result<string>> ExecuteAsync(
    CreateProjectRequest request, 
    Action<string> onProgress = null
)
request
CreateProjectRequest
required
Configuration for the new project
onProgress
Action<string>
Optional callback for progress updates during project creation
Result<string>
Result<string>
Result containing the path to the created project

Example Usage

var createProjectUseCase = new CreateProjectUseCase(
    gitRepository, 
    templateService, 
    projectRepository
);

var request = new CreateProjectRequest(
    ProjectName: "MyNewApp",
    ParentDirectory: "C:\\Projects",
    TemplateUrl: "https://github.com/template/clean-architecture",
    RemoteUrl: "https://github.com/myorg/mynewapp"
);

var result = await createProjectUseCase.ExecuteAsync(
    request, 
    progress => Console.WriteLine(progress)
);

if (result.IsSuccess)
{
    Console.WriteLine($"Project created at: {result.Data}");
}

Process Flow

  1. Clones the template repository
  2. Removes original .git folder
  3. Renames files and directories to match the new project name
  4. Initializes a new Git repository
  5. Associates remote repository if provided
  6. Registers the project in Chapi

CloneProjectUseCase

Clones a Git repository and adds it to Chapi’s workspace.

Method Signature

public async Task<Result<string>> ExecuteAsync(string repoUrl, string parentDirectory)
repoUrl
string
required
The Git repository URL to clone
parentDirectory
string
required
The directory where the repository will be cloned
Result<string>
Result<string>
Result containing the path to the cloned project

Example Usage

var cloneProjectUseCase = new CloneProjectUseCase(gitRepository, projectRepository);
var result = await cloneProjectUseCase.ExecuteAsync(
    "https://github.com/user/repo.git",
    "C:\\Projects"
);

if (result.IsSuccess)
{
    Console.WriteLine($"Project cloned to: {result.Data}");
}

LoadProjectsUseCase

Retrieves all projects registered in Chapi Assistant.

Method Signature

public async Task<Result<IEnumerable<Project>>> ExecuteAsync()
Result<IEnumerable<Project>>
Result<IEnumerable<Project>>
Result containing the list of projects

Project Entity

public class Project
{
    public string FullPath { get; set; }
    public string Name { get; set; }
    public string CurrentBranch { get; set; }
    public int AheadCount { get; set; }
    public int BehindCount { get; set; }
}

Example Usage

var loadProjectsUseCase = new LoadProjectsUseCase(projectRepository);
var result = await loadProjectsUseCase.ExecuteAsync();

if (result.IsSuccess)
{
    foreach (var project in result.Data)
    {
        Console.WriteLine($"{project.Name} - {project.CurrentBranch}");
    }
}

RemoveProjectUseCase

Removes a project from Chapi’s workspace (does not delete files).

Method Signature

public async Task<Result> ExecuteAsync(string projectPath)
projectPath
string
required
The path of the project to remove from the workspace
Result
Result
A Result object indicating success or failure

Example Usage

var removeProjectUseCase = new RemoveProjectUseCase(projectRepository);
var result = await removeProjectUseCase.ExecuteAsync("/path/to/project");

if (result.IsSuccess)
{
    Console.WriteLine("Project removed from workspace");
}

SwitchProjectUseCase

Switches the active project in Chapi Assistant.

Method Signature

public async Task<Result<Project>> ExecuteAsync(string projectPath)
projectPath
string
required
The path of the project to switch to
Result<Project>
Result<Project>
Result containing the switched project

Example Usage

var switchProjectUseCase = new SwitchProjectUseCase(projectRepository);
var result = await switchProjectUseCase.ExecuteAsync("/path/to/project");

if (result.IsSuccess)
{
    Console.WriteLine($"Switched to: {result.Data.Name}");
}

Build docs developers (and LLMs) love