Scaffold a complete microservice with Controller-Service-Repository pattern for RH-OptimERP
Generate a complete .NET 8 microservice following the RH-OptimERP Controller-Service-Repository pattern.
Parse arguments: Extract service name, entity list, and port.
Create directory structure:
src/backend/{ServiceName}/
Controllers/ -- One per entity
Services/
Interfaces/ -- I{Entity}Service.cs
{Entity}Service.cs
Repositories/
Interfaces/ -- I{Entity}Repository.cs
{Entity}Repository.cs
Models/
{Entity}.cs -- Domain models
DTOs/
{Entity}Dto.cs -- With ToDomain() and FromDomain()
Program.cs -- DI, CORS, Swagger, health checks
{ServiceName}.csproj -- .NET 8, CosmosDB SDK 3.54
appsettings.json
appsettings.Development.json
Dockerfile
src/backend/Tests/{ServiceName}Tests/
{Entity}ServiceTests.cs
{ServiceName}Tests.csproj
Generate each file following these patterns:
Controller (HTTP concerns only):
[ApiController]
[Route("api/[controller]")]
public class {Entity}Controller : ControllerBase
{
private readonly I{Entity}Service _service;
public {Entity}Controller(I{Entity}Service service) => _service = service;
[HttpGet("{id}")]
public async Task<ActionResult<{Entity}Dto>> GetById(string id) { ... }
[HttpGet]
public async Task<ActionResult<PagedResult<{Entity}Dto>>> GetAll([FromQuery] int page = 1, [FromQuery] int size = 20) { ... }
[HttpPost]
public async Task<ActionResult<{Entity}Dto>> Create([FromBody] Create{Entity}Dto dto) { ... }
}
Service (business logic + validation):
public class {Entity}Service : I{Entity}Service
{
private readonly I{Entity}Repository _repository;
public {Entity}Service(I{Entity}Repository repository) => _repository = repository;
}
Repository (CosmosDB SDK 3.54 direct):
public class {Entity}Repository : I{Entity}Repository
{
private readonly Container _container;
public {Entity}Repository(CosmosClient client, IOptions<CosmosDbSettings> settings)
{
var db = client.GetDatabase(settings.Value.DatabaseName);
_container = db.GetContainer("{entities}");
}
}
DTO (static mapping methods):
public class {Entity}Dto
{
public static {Entity}Dto FromDomain({Entity} entity) => new() { ... };
public {Entity} ToDomain() => new() { ... };
}
Program.cs must include:
Dockerfile (multi-stage):
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY . .
RUN dotnet publish -c Release -o /app
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app .
EXPOSE {port}
ENTRYPOINT ["dotnet", "{ServiceName}.dll"]
Verify: dotnet build succeeds with zero warnings.
For entities containing personal data, add:
AnonymizeXxx() methodIsAnonymized flag<service-name>: Name of the microservice (PascalCase)--entities=<list>: Comma-separated entity names--port=<n>: HTTP port (default: 5000)--with-gdpr: Add GDPR compliance to all entities--with-tests: Generate test project (default: true)Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer
Tags:scaffold, microservice, dotnet, architecture, codegen