feat: implement strangler-fig-demo Session 1 (backend + smoke script)
Builds the four-seam, three-write-path reference demo backend: case-framework (seam D stand-in), legacy-backend/frontend (SQL Server, seams A/B/C targets), and new-backend (Domain/Application/Infrastructure.*/Api implementing the source resolver, take/release-ownership, write-through translator, and owned assessment flow), wired together via docker-compose with a plain placeholder frontend standing in for the Angular portal until Session 2. All 11 Architecture.Tests pass and scripts/smoke.sh passes end-to-end against a fresh `docker compose up`, covering acceptance criteria 1-3 and 7-22. Fixes two real domain bugs found only once the stack ran for real: the BSN eleven-proof checksum trivially passes all-zero digits, and the adoption mapper silently treated a partial legacy address as absent instead of failing loudly. Also fixes several environment-specific integration issues (rootless Podman/SELinux bind-mount permissions, a buildah NuGet layer-caching bug, SqlClient's invariant-globalization incompatibility, and an nginx path-prefix mismatch for the legacy frontend). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
|
||||
WORKDIR /src
|
||||
|
||||
COPY src/CaseFramework.Api/ src/CaseFramework.Api/
|
||||
# restore+publish combined in one RUN/layer - see legacy/src/Legacy.Api/Dockerfile for why.
|
||||
RUN dotnet restore src/CaseFramework.Api/CaseFramework.Api.csproj && \
|
||||
dotnet publish src/CaseFramework.Api/CaseFramework.Api.csproj -c Release -o /app/publish --no-restore
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
COPY --from=build /app/publish .
|
||||
ENTRYPOINT ["dotnet", "CaseFramework.Api.dll"]
|
||||
@@ -0,0 +1,40 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CaseFramework.Api;
|
||||
|
||||
public class CaseDbContext(DbContextOptions<CaseDbContext> options) : DbContext(options)
|
||||
{
|
||||
public DbSet<CaseEntity> Cases => Set<CaseEntity>();
|
||||
public DbSet<CaseTaskEntity> Tasks => Set<CaseTaskEntity>();
|
||||
public DbSet<TimelineEntryEntity> TimelineEntries => Set<TimelineEntryEntity>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<CaseEntity>(entity =>
|
||||
{
|
||||
entity.HasKey(c => c.Id);
|
||||
// Npgsql maps List<string> to a native Postgres text[] column.
|
||||
entity.Property(c => c.Participants).HasColumnType("text[]");
|
||||
|
||||
entity.HasMany(c => c.Tasks)
|
||||
.WithOne()
|
||||
.HasForeignKey(t => t.CaseId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
entity.HasMany(c => c.TimelineEntries)
|
||||
.WithOne()
|
||||
.HasForeignKey(t => t.CaseId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<CaseTaskEntity>(entity =>
|
||||
{
|
||||
entity.HasKey(t => t.Id);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<TimelineEntryEntity>(entity =>
|
||||
{
|
||||
entity.HasKey(t => t.Id);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,52 @@
|
||||
namespace CaseFramework.Api;
|
||||
|
||||
/// <summary>
|
||||
/// A case managed by the framework. This is the framework's own aggregate;
|
||||
/// callers reference it by <see cref="Id"/> and may attach their own
|
||||
/// <see cref="ExternalReference"/> for correlation.
|
||||
/// </summary>
|
||||
public class CaseEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string CaseTypeCode { get; set; } = string.Empty;
|
||||
public string ExternalReference { get; set; } = string.Empty;
|
||||
public string ProcessStatus { get; set; } = string.Empty;
|
||||
public List<string> Participants { get; set; } = new();
|
||||
|
||||
public List<CaseTaskEntity> Tasks { get; set; } = new();
|
||||
public List<TimelineEntryEntity> TimelineEntries { get; set; } = new();
|
||||
}
|
||||
|
||||
/// <summary>A unit of work that must be completed before a case may be closed.</summary>
|
||||
public class CaseTaskEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid CaseId { get; set; }
|
||||
public string Code { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public bool IsOpen { get; set; } = true;
|
||||
}
|
||||
|
||||
/// <summary>An immutable audit entry appended to a case's history.</summary>
|
||||
public class TimelineEntryEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid CaseId { get; set; }
|
||||
public DateTimeOffset At { get; set; }
|
||||
public string Kind { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public static class ProcessStatus
|
||||
{
|
||||
public const string InBehandeling = "InBehandeling";
|
||||
public const string Afgesloten = "Afgesloten";
|
||||
}
|
||||
|
||||
public static class TimelineKind
|
||||
{
|
||||
public const string CaseCreated = "CaseCreated";
|
||||
public const string TaskOpened = "TaskOpened";
|
||||
public const string TaskCompleted = "TaskCompleted";
|
||||
public const string CaseClosed = "CaseClosed";
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
using CaseFramework.Api;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddDbContext<CaseDbContext>(options =>
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("CaseFramework")));
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Self-provision schema against an empty Postgres database on first boot.
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<CaseDbContext>();
|
||||
await dbContext.Database.EnsureCreatedAsync();
|
||||
}
|
||||
|
||||
app.MapPost("/cases", async (CreateCaseRequest request, CaseDbContext db) =>
|
||||
{
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
var caseEntity = new CaseEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
CaseTypeCode = request.CaseTypeCode,
|
||||
ExternalReference = request.ExternalReference,
|
||||
ProcessStatus = ProcessStatus.InBehandeling,
|
||||
Participants = request.Participants?.ToList() ?? new List<string>(),
|
||||
};
|
||||
caseEntity.TimelineEntries.Add(new TimelineEntryEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
CaseId = caseEntity.Id,
|
||||
At = now,
|
||||
Kind = TimelineKind.CaseCreated,
|
||||
Description = $"Case created with type '{caseEntity.CaseTypeCode}'.",
|
||||
});
|
||||
|
||||
db.Cases.Add(caseEntity);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Results.Ok(new CreateCaseResponse(caseEntity.Id, caseEntity.ProcessStatus));
|
||||
});
|
||||
|
||||
app.MapGet("/cases/{id:guid}", async (Guid id, CaseDbContext db) =>
|
||||
{
|
||||
var caseEntity = await db.Cases.AsNoTracking().FirstOrDefaultAsync(c => c.Id == id);
|
||||
if (caseEntity is null)
|
||||
{
|
||||
return Results.NotFound();
|
||||
}
|
||||
|
||||
return Results.Ok(new CaseResponse(
|
||||
caseEntity.Id,
|
||||
caseEntity.CaseTypeCode,
|
||||
caseEntity.ExternalReference,
|
||||
caseEntity.ProcessStatus,
|
||||
caseEntity.Participants));
|
||||
});
|
||||
|
||||
app.MapGet("/cases/{id:guid}/timeline", async (Guid id, CaseDbContext db) =>
|
||||
{
|
||||
var caseExists = await db.Cases.AnyAsync(c => c.Id == id);
|
||||
if (!caseExists)
|
||||
{
|
||||
return Results.NotFound();
|
||||
}
|
||||
|
||||
var entries = await db.TimelineEntries
|
||||
.AsNoTracking()
|
||||
.Where(t => t.CaseId == id)
|
||||
.OrderBy(t => t.At)
|
||||
.Select(t => new TimelineEntryResponse(t.At, t.Kind, t.Description))
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Ok(new TimelineResponse(entries));
|
||||
});
|
||||
|
||||
app.MapPost("/cases/{id:guid}/tasks", async (Guid id, CreateTaskRequest request, CaseDbContext db) =>
|
||||
{
|
||||
var caseEntity = await db.Cases.FirstOrDefaultAsync(c => c.Id == id);
|
||||
if (caseEntity is null)
|
||||
{
|
||||
return Results.NotFound();
|
||||
}
|
||||
|
||||
var task = new CaseTaskEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
CaseId = id,
|
||||
Code = request.Code,
|
||||
Description = request.Description,
|
||||
IsOpen = true,
|
||||
};
|
||||
db.Tasks.Add(task);
|
||||
db.TimelineEntries.Add(new TimelineEntryEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
CaseId = id,
|
||||
At = DateTimeOffset.UtcNow,
|
||||
Kind = TimelineKind.TaskOpened,
|
||||
Description = $"Task '{task.Code}' opened: {task.Description}",
|
||||
});
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Results.Ok(new CreateTaskResponse(task.Id, task.IsOpen));
|
||||
});
|
||||
|
||||
app.MapPost("/cases/{id:guid}/tasks/{taskId:guid}/complete", async (Guid id, Guid taskId, CaseDbContext db) =>
|
||||
{
|
||||
var caseExists = await db.Cases.AnyAsync(c => c.Id == id);
|
||||
if (!caseExists)
|
||||
{
|
||||
return Results.NotFound();
|
||||
}
|
||||
|
||||
var task = await db.Tasks.FirstOrDefaultAsync(t => t.Id == taskId && t.CaseId == id);
|
||||
if (task is null)
|
||||
{
|
||||
return Results.NotFound();
|
||||
}
|
||||
|
||||
task.IsOpen = false;
|
||||
db.TimelineEntries.Add(new TimelineEntryEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
CaseId = id,
|
||||
At = DateTimeOffset.UtcNow,
|
||||
Kind = TimelineKind.TaskCompleted,
|
||||
Description = $"Task '{task.Code}' completed.",
|
||||
});
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Results.NoContent();
|
||||
});
|
||||
|
||||
app.MapPost("/cases/{id:guid}/closure-request", async (Guid id, CaseDbContext db) =>
|
||||
{
|
||||
var caseEntity = await db.Cases.FirstOrDefaultAsync(c => c.Id == id);
|
||||
if (caseEntity is null)
|
||||
{
|
||||
return Results.NotFound();
|
||||
}
|
||||
|
||||
var hasOpenTasks = await db.Tasks.AnyAsync(t => t.CaseId == id && t.IsOpen);
|
||||
if (hasOpenTasks)
|
||||
{
|
||||
return Results.Conflict();
|
||||
}
|
||||
|
||||
caseEntity.ProcessStatus = ProcessStatus.Afgesloten;
|
||||
db.TimelineEntries.Add(new TimelineEntryEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
CaseId = id,
|
||||
At = DateTimeOffset.UtcNow,
|
||||
Kind = TimelineKind.CaseClosed,
|
||||
Description = "Case closed.",
|
||||
});
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return Results.NoContent();
|
||||
});
|
||||
|
||||
app.Run();
|
||||
|
||||
internal record CreateCaseRequest(string CaseTypeCode, string ExternalReference, List<string>? Participants);
|
||||
|
||||
internal record CreateCaseResponse(Guid Id, string ProcessStatus);
|
||||
|
||||
internal record CaseResponse(
|
||||
Guid Id,
|
||||
string CaseTypeCode,
|
||||
string ExternalReference,
|
||||
string ProcessStatus,
|
||||
List<string> Participants);
|
||||
|
||||
internal record CreateTaskRequest(string Code, string Description);
|
||||
|
||||
internal record CreateTaskResponse(Guid TaskId, bool Open);
|
||||
|
||||
internal record TimelineEntryResponse(DateTimeOffset At, string Kind, string Description);
|
||||
|
||||
internal record TimelineResponse(List<TimelineEntryResponse> Entries);
|
||||
Reference in New Issue
Block a user