Scaffold the Before-M1 repo skeleton

Stand up the modular-monolith skeleton per docs/V1_BUILD_PLAN.md: one .NET 10
solution with web + worker hosts sharing seven interface-bounded module projects,
PostgreSQL 17 + pgvector via EF Core 10, a React 19 + Vite SPA built into wwwroot,
and Docker Compose for one-command local dev. Skeleton only — no feature code.

Architecture
- One project per module (OrgBoard, Identity, Skills, Assembler, Governance,
  Memory, Integrations); each is its own assembly so non-public types (entities,
  DbContext) are invisible across modules at compile time.
- TeamUp.Bootstrap is the only library that references all modules; both hosts
  reference only Bootstrap. SharedKernel/Infrastructure never reference modules.
- IModule seam: Register(...) runs in both hosts; MapEndpoints(...) only in web.
- PlatformDbContext owns the pgvector extension + the seven module schemas
  (InitialPlatform migration); MigrationRunner applies it then any module context.
- One image, two roles selected by RUN_MODE at the Docker entrypoint.

Verified
- dotnet build green (nullable + warnings-as-errors).
- ArchitectureTests 8/8 — reflection-based boundary rules (no module -> module,
  -> Infrastructure, -> Bootstrap, or -> host references).
- IntegrationTests 10/10 — Testcontainers boots the host against real pgvector:
  migration applies, vector extension + 7 schemas exist, /health 200, every
  /api/<module>/ping 200, /openapi/v1.json served.
- client builds clean (Vite 6 — pinned for Node 22.3.0; Vite 8 needs Node >=22.12).

Packages and base images route through the Nexus mirror (mirror.soroushasadi.com),
reachable from Iran when nuget.org / Docker Hub / MCR are not. CI is intentionally
deferred to a later session.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
soroush.asadi
2026-06-09 06:41:28 +03:30
commit 36fe158b43
89 changed files with 7329 additions and 0 deletions
@@ -0,0 +1,29 @@
using TeamUp.Modules.Assembler;
using TeamUp.Modules.Governance;
using TeamUp.Modules.Identity;
using TeamUp.Modules.Integrations;
using TeamUp.Modules.Memory;
using TeamUp.Modules.OrgBoard;
using TeamUp.Modules.Skills;
using TeamUp.SharedKernel.Modularity;
namespace TeamUp.Bootstrap;
/// <summary>
/// The explicit, ordered list of modules. Explicit (not assembly-scanned) on purpose:
/// deterministic, trim/AOT-safe, reviewable, and order-controlled (Identity first, since other
/// modules will depend on its auth services). Adding a module is a one-line change here.
/// </summary>
public static class ModuleCatalog
{
public static IReadOnlyList<IModule> All { get; } =
[
new IdentityModule(),
new OrgBoardModule(),
new SkillsModule(),
new IntegrationsModule(),
new MemoryModule(),
new AssemblerModule(),
new GovernanceModule(),
];
}
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- The ONLY composition library that references every module. Both hosts reference Bootstrap
(and nothing else of the module graph), so the module list stays DRY across web + worker.
Infrastructure and SharedKernel must never reference modules — Bootstrap is where that
knowledge is allowed to live. -->
<ItemGroup>
<ProjectReference Include="..\..\Shared\TeamUp.SharedKernel\TeamUp.SharedKernel.csproj" />
<ProjectReference Include="..\..\Shared\TeamUp.Infrastructure\TeamUp.Infrastructure.csproj" />
<ProjectReference Include="..\..\Modules\TeamUp.Modules.Identity\TeamUp.Modules.Identity.csproj" />
<ProjectReference Include="..\..\Modules\TeamUp.Modules.OrgBoard\TeamUp.Modules.OrgBoard.csproj" />
<ProjectReference Include="..\..\Modules\TeamUp.Modules.Skills\TeamUp.Modules.Skills.csproj" />
<ProjectReference Include="..\..\Modules\TeamUp.Modules.Integrations\TeamUp.Modules.Integrations.csproj" />
<ProjectReference Include="..\..\Modules\TeamUp.Modules.Memory\TeamUp.Modules.Memory.csproj" />
<ProjectReference Include="..\..\Modules\TeamUp.Modules.Assembler\TeamUp.Modules.Assembler.csproj" />
<ProjectReference Include="..\..\Modules\TeamUp.Modules.Governance\TeamUp.Modules.Governance.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace TeamUp.Bootstrap;
public static class TeamUpModuleExtensions
{
/// <summary>Runs every module's <c>Register</c>. Called by BOTH hosts.</summary>
public static IServiceCollection AddTeamUpModules(
this IServiceCollection services,
IConfiguration configuration)
{
foreach (var module in ModuleCatalog.All)
{
module.Register(services, configuration);
}
return services;
}
/// <summary>Runs every module's <c>MapEndpoints</c>. Called by the WEB host only.</summary>
public static IEndpointRouteBuilder MapTeamUpModules(this IEndpointRouteBuilder endpoints)
{
foreach (var module in ModuleCatalog.All)
{
module.MapEndpoints(endpoints);
}
return endpoints;
}
}
+56
View File
@@ -0,0 +1,56 @@
using OpenTelemetry.Trace;
using Serilog;
using TeamUp.Bootstrap;
using TeamUp.Infrastructure.Observability;
using TeamUp.Infrastructure.Persistence;
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog((context, services, configuration) => configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services));
builder.Services.AddOpenApi();
builder.Services.AddTeamUpObservability(
builder.Configuration,
serviceName: "teamup-web",
configureTracing: tracing => tracing.AddAspNetCoreInstrumentation());
builder.Services.AddTeamUpPersistence(builder.Configuration);
builder.Services.AddTeamUpModules(builder.Configuration);
var app = builder.Build();
// Apply migrations on startup when configured (default: in Development). EF Core takes a
// DB-wide lock, so the web and worker applying concurrently is safe.
if (app.Configuration.GetValue("Database:ApplyMigrationsOnStartup", app.Environment.IsDevelopment()))
{
await MigrationRunner.MigrateAllAsync(app.Services);
}
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseSerilogRequestLogging();
// Serve the built SPA from wwwroot (single deployable). UseStaticFiles (not MapStaticAssets)
// because the SPA is copied into wwwroot at publish/Docker time, after the build-time asset
// manifest is computed.
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapHealthChecks("/health");
app.MapTeamUpModules();
// SPA deep links (client-side routing) fall back to index.html.
app.MapFallbackToFile("index.html");
app.Run();
/// <summary>Exposed so the integration tests can drive the host via WebApplicationFactory.</summary>
public partial class Program
{
}
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5180",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7180;http://localhost:5180",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
+36
View File
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<!-- Path to the Vite SPA. The publish target below builds it into the published wwwroot.
Set BuildClient=false to skip (the Docker build builds the SPA in a dedicated node
stage and copies it in, so it passes -p:BuildClient=false). -->
<ClientDir>$(MSBuildProjectDirectory)\..\..\..\client</ClientDir>
<BuildClient Condition="'$(BuildClient)' == ''">true</BuildClient>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Bootstrap\TeamUp.Bootstrap\TeamUp.Bootstrap.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
<PackageReference Include="Serilog.AspNetCore" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
</ItemGroup>
<!-- Build the Vite SPA and copy it into the published wwwroot for a single deployable.
Runs only on `dotnet publish` (never on build/test, so node isn't needed for CI tests). -->
<Target Name="PublishClientSpa" AfterTargets="Publish"
Condition="'$(BuildClient)' == 'true' AND Exists('$(ClientDir)\package.json')">
<Message Importance="high" Text="Building Vite SPA from $(ClientDir) ..." />
<Exec Command="npm ci" WorkingDirectory="$(ClientDir)" />
<Exec Command="npm run build" WorkingDirectory="$(ClientDir)" />
<ItemGroup>
<_SpaDist Include="$(ClientDir)\dist\**\*" />
</ItemGroup>
<Copy SourceFiles="@(_SpaDist)"
DestinationFiles="@(_SpaDist->'$(PublishDir)wwwroot\%(RecursiveDir)%(Filename)%(Extension)')"
SkipUnchangedFiles="true" />
</Target>
</Project>
@@ -0,0 +1,14 @@
{
"Database": {
"ApplyMigrationsOnStartup": true
},
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft.AspNetCore": "Information",
"Microsoft.EntityFrameworkCore": "Warning"
}
}
}
}
+25
View File
@@ -0,0 +1,25 @@
{
"ConnectionStrings": {
"Postgres": "Host=localhost;Port=5432;Database=teamup;Username=teamup;Password=teamup"
},
"Database": {
"ApplyMigrationsOnStartup": false
},
"OpenTelemetry": {
"OtlpEndpoint": ""
},
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft.AspNetCore": "Warning",
"Microsoft.EntityFrameworkCore": "Warning"
}
},
"Enrich": [ "FromLogContext" ],
"WriteTo": [
{ "Name": "Console" }
]
},
"AllowedHosts": "*"
}
+35
View File
@@ -0,0 +1,35 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>TeamUp.AI</title>
<style>
:root { color-scheme: dark; }
body {
margin: 0; min-height: 100vh; display: grid; place-items: center;
font-family: "Hanken Grotesk", system-ui, sans-serif;
background: #1e1b4b; color: #e2e8f0;
}
main { text-align: center; padding: 2rem; }
h1 { font-weight: 700; letter-spacing: -0.02em; margin: 0 0 .25rem; }
p { color: #a5b4fc; margin: .25rem 0; }
code { background: #312e81; padding: .15rem .4rem; border-radius: .25rem; }
#status { margin-top: 1.25rem; font-size: .9rem; }
</style>
</head>
<body>
<main>
<h1>TeamUp.AI</h1>
<p>Build human + AI teams.</p>
<p>API host is running. This placeholder is replaced by the React SPA on publish.</p>
<p id="status">checking <code>/health</code></p>
</main>
<script>
fetch("/health")
.then((r) => (r.ok ? "healthy" : "unhealthy (" + r.status + ")"))
.catch(() => "unreachable")
.then((s) => { document.getElementById("status").textContent = "/health: " + s; });
</script>
</body>
</html>
@@ -0,0 +1,39 @@
using Microsoft.Extensions.Diagnostics.HealthChecks;
namespace TeamUp.Worker;
/// <summary>
/// Skeleton placeholder for the future agent-run job drainer (M4: a Postgres <c>jobs</c> table
/// drained with <c>FOR UPDATE SKIP LOCKED</c>). For now it proves the worker host boots, shares
/// the domain modules, and can reach the database — by running the registered health checks on a
/// timer. Internal: defined in and visible only to the worker assembly.
/// </summary>
internal sealed class HeartbeatService(
ILogger<HeartbeatService> logger,
IServiceScopeFactory scopeFactory) : BackgroundService
{
private static readonly TimeSpan Interval = TimeSpan.FromSeconds(30);
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
logger.LogInformation("Worker started; heartbeat every {Seconds}s.", Interval.TotalSeconds);
using var timer = new PeriodicTimer(Interval);
while (!stoppingToken.IsCancellationRequested)
{
try
{
await using var scope = scopeFactory.CreateAsyncScope();
var health = scope.ServiceProvider.GetRequiredService<HealthCheckService>();
var report = await health.CheckHealthAsync(stoppingToken);
logger.LogInformation("Worker heartbeat — DB health: {Status}", report.Status);
await timer.WaitForNextTickAsync(stoppingToken);
}
catch (OperationCanceledException)
{
break;
}
}
}
}
+27
View File
@@ -0,0 +1,27 @@
using Serilog;
using TeamUp.Bootstrap;
using TeamUp.Infrastructure.Observability;
using TeamUp.Infrastructure.Persistence;
using TeamUp.Worker;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddSerilog((services, configuration) => configuration
.ReadFrom.Configuration(builder.Configuration)
.ReadFrom.Services(services));
builder.Services.AddTeamUpObservability(builder.Configuration, serviceName: "teamup-worker");
builder.Services.AddTeamUpPersistence(builder.Configuration);
builder.Services.AddTeamUpModules(builder.Configuration);
builder.Services.AddHostedService<HeartbeatService>();
var host = builder.Build();
// Default: web applies migrations; the worker leaves it off in compose. Locally (Development)
// it defaults on, but EF's DB-wide migration lock makes a concurrent apply safe and idempotent.
if (builder.Configuration.GetValue("Database:ApplyMigrationsOnStartup", builder.Environment.IsDevelopment()))
{
await MigrationRunner.MigrateAllAsync(host.Services);
}
host.Run();
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<!-- The worker role. Same image as the web host, selected at the Docker entrypoint by RUN_MODE.
Shares all domain modules via Bootstrap; contributes zero HTTP surface. OpenTelemetry flows
transitively from Infrastructure; Serilog.AspNetCore provides AddSerilog + config binding. -->
<ItemGroup>
<ProjectReference Include="..\..\Bootstrap\TeamUp.Bootstrap\TeamUp.Bootstrap.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Serilog.AspNetCore" />
</ItemGroup>
</Project>
@@ -0,0 +1,13 @@
{
"Database": {
"ApplyMigrationsOnStartup": true
},
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft.EntityFrameworkCore": "Warning"
}
}
}
}
+23
View File
@@ -0,0 +1,23 @@
{
"ConnectionStrings": {
"Postgres": "Host=localhost;Port=5432;Database=teamup;Username=teamup;Password=teamup"
},
"Database": {
"ApplyMigrationsOnStartup": false
},
"OpenTelemetry": {
"OtlpEndpoint": ""
},
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft.EntityFrameworkCore": "Warning"
}
},
"Enrich": [ "FromLogContext" ],
"WriteTo": [
{ "Name": "Console" }
]
}
}
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TeamUp.SharedKernel.Modularity;
namespace TeamUp.Modules.Assembler;
/// <summary>Context assembly, the model call, output parsing, prompt caching — runs in the worker (M4).</summary>
public sealed class AssemblerModule : IModule
{
public string Name => "assembler";
public void Register(IServiceCollection services, IConfiguration configuration)
{
// Skeleton: no services yet. M4 introduces the jobs table (FOR UPDATE SKIP LOCKED),
// the AgentRun context, and the assembler pipeline (registered for the worker host).
}
public void MapEndpoints(IEndpointRouteBuilder endpoints)
{
endpoints.MapGroup($"/api/{Name}")
.WithTags("Assembler")
.MapGet("/ping", () => TypedResults.Ok(new ModulePing(Name)));
}
}
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- A self-contained module. References SharedKernel ONLY (ASP.NET flows transitively for the
IModule seam). M1 adds this module's EF/Npgsql/FluentValidation/Mapperly packages when it
gains an (internal) DbContext and validators. It must never reference another module.
NOTE: this module hosts the runtime assembler + job-drain logic in the worker (M4); the AI
model-client packages are deferred to M3-M4 and are not referenced in the skeleton. -->
<ItemGroup>
<ProjectReference Include="..\..\Shared\TeamUp.SharedKernel\TeamUp.SharedKernel.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TeamUp.SharedKernel.Modularity;
namespace TeamUp.Modules.Governance;
/// <summary>Autonomy dial, the action gate, the review inbox, the audit log (M5).</summary>
public sealed class GovernanceModule : IModule
{
public string Name => "governance";
public void Register(IServiceCollection services, IConfiguration configuration)
{
// Skeleton: no services yet. M5 introduces the action gate, ReviewItem context,
// edit-distance capture, and the immutable audit log here.
}
public void MapEndpoints(IEndpointRouteBuilder endpoints)
{
endpoints.MapGroup($"/api/{Name}")
.WithTags("Governance")
.MapGet("/ping", () => TypedResults.Ok(new ModulePing(Name)));
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- A self-contained module. References SharedKernel ONLY (ASP.NET flows transitively for the
IModule seam). M1 adds this module's EF/Npgsql/FluentValidation/Mapperly packages when it
gains an (internal) DbContext and validators. It must never reference another module. -->
<ItemGroup>
<ProjectReference Include="..\..\Shared\TeamUp.SharedKernel\TeamUp.SharedKernel.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TeamUp.SharedKernel.Modularity;
namespace TeamUp.Modules.Identity;
/// <summary>Identity &amp; access: members, memberships, roles, permission enforcement (M1).</summary>
public sealed class IdentityModule : IModule
{
public string Name => "identity";
public void Register(IServiceCollection services, IConfiguration configuration)
{
// Skeleton: no services yet. M1 introduces this module's (internal) DbContext,
// FluentValidation validators, and domain services here.
}
public void MapEndpoints(IEndpointRouteBuilder endpoints)
{
endpoints.MapGroup($"/api/{Name}")
.WithTags("Identity")
.MapGet("/ping", () => TypedResults.Ok(new ModulePing(Name)));
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- A self-contained module. References SharedKernel ONLY (ASP.NET flows transitively for the
IModule seam). M1 adds this module's EF/Npgsql/FluentValidation/Mapperly packages when it
gains an (internal) DbContext and validators. It must never reference another module. -->
<ItemGroup>
<ProjectReference Include="..\..\Shared\TeamUp.SharedKernel\TeamUp.SharedKernel.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TeamUp.SharedKernel.Modularity;
namespace TeamUp.Modules.Integrations;
/// <summary>BYOK API configs, the Git connection, the encrypted-credential store (M3).</summary>
public sealed class IntegrationsModule : IModule
{
public string Name => "integrations";
public void Register(IServiceCollection services, IConfiguration configuration)
{
// Skeleton: no services yet. M3 introduces this module's (internal) DbContext, the
// encrypted ApiConfig store, and the provider-agnostic model-client seam interface.
// The concrete model client (Microsoft.Extensions.AI) is deferred to M3-M4.
}
public void MapEndpoints(IEndpointRouteBuilder endpoints)
{
endpoints.MapGroup($"/api/{Name}")
.WithTags("Integrations")
.MapGet("/ping", () => TypedResults.Ok(new ModulePing(Name)));
}
}
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- A self-contained module. References SharedKernel ONLY (ASP.NET flows transitively for the
IModule seam). M1 adds this module's EF/Npgsql/FluentValidation/Mapperly packages when it
gains an (internal) DbContext and validators. It must never reference another module.
NOTE: the AI model-client packages (Microsoft.Extensions.AI, ONNX) are deferred to M3-M4;
this module exposes only seam interfaces in V1, no concrete model client. -->
<ItemGroup>
<ProjectReference Include="..\..\Shared\TeamUp.SharedKernel\TeamUp.SharedKernel.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TeamUp.SharedKernel.Modularity;
namespace TeamUp.Modules.Memory;
/// <summary>Team-scoped working memory: read at assembly, written on approval (M6, pgvector).</summary>
public sealed class MemoryModule : IModule
{
public string Name => "memory";
public void Register(IServiceCollection services, IConfiguration configuration)
{
// Skeleton: no services yet. M6 introduces this module's (internal) DbContext with a
// pgvector-backed MemoryEntry table and the working-memory read/write services.
}
public void MapEndpoints(IEndpointRouteBuilder endpoints)
{
endpoints.MapGroup($"/api/{Name}")
.WithTags("Memory")
.MapGet("/ping", () => TypedResults.Ok(new ModulePing(Name)));
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- A self-contained module. References SharedKernel ONLY (ASP.NET flows transitively for the
IModule seam). M1 adds this module's EF/Npgsql/FluentValidation/Mapperly packages when it
gains an (internal) DbContext and validators. It must never reference another module. -->
<ItemGroup>
<ProjectReference Include="..\..\Shared\TeamUp.SharedKernel\TeamUp.SharedKernel.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TeamUp.SharedKernel.Modularity;
namespace TeamUp.Modules.OrgBoard;
/// <summary>Org, products, teams, seats, and the task/board model (M1).</summary>
public sealed class OrgBoardModule : IModule
{
public string Name => "orgboard";
public void Register(IServiceCollection services, IConfiguration configuration)
{
// Skeleton: no services yet. M1 introduces this module's (internal) DbContext,
// FluentValidation validators, and domain services here.
}
public void MapEndpoints(IEndpointRouteBuilder endpoints)
{
endpoints.MapGroup($"/api/{Name}")
.WithTags("OrgBoard")
.MapGet("/ping", () => TypedResults.Ok(new ModulePing(Name)));
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- A self-contained module. References SharedKernel ONLY (ASP.NET flows transitively for the
IModule seam). M1 adds this module's EF/Npgsql/FluentValidation/Mapperly packages when it
gains an (internal) DbContext and validators. It must never reference another module. -->
<ItemGroup>
<ProjectReference Include="..\..\Shared\TeamUp.SharedKernel\TeamUp.SharedKernel.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TeamUp.SharedKernel.Modularity;
namespace TeamUp.Modules.Skills;
/// <summary>Git-sourced skill registry: sync, the queryable atom index, versioning, evals (M2).</summary>
public sealed class SkillsModule : IModule
{
public string Name => "skills";
public void Register(IServiceCollection services, IConfiguration configuration)
{
// Skeleton: no services yet. M2 introduces this module's (internal) DbContext,
// FluentValidation validators, and domain services here.
}
public void MapEndpoints(IEndpointRouteBuilder endpoints)
{
endpoints.MapGroup($"/api/{Name}")
.WithTags("Skills")
.MapGet("/ping", () => TypedResults.Ok(new ModulePing(Name)));
}
}
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- A self-contained module. References SharedKernel ONLY (ASP.NET flows transitively for the
IModule seam). M1 adds this module's EF/Npgsql/FluentValidation/Mapperly packages when it
gains an (internal) DbContext and validators. It must never reference another module. -->
<ItemGroup>
<ProjectReference Include="..\..\Shared\TeamUp.SharedKernel\TeamUp.SharedKernel.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,50 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
namespace TeamUp.Infrastructure.Observability;
public static class ObservabilityExtensions
{
/// <summary>
/// Wires OpenTelemetry tracing + metrics with a service-name resource and runtime metrics.
/// The OTLP exporter is attached only when an endpoint is configured (so local dev stays
/// quiet). Hosts pass <paramref name="configureTracing"/> to add role-specific
/// instrumentation (e.g. the web host adds ASP.NET Core instrumentation).
/// </summary>
public static IServiceCollection AddTeamUpObservability(
this IServiceCollection services,
IConfiguration configuration,
string serviceName,
Action<TracerProviderBuilder>? configureTracing = null,
Action<MeterProviderBuilder>? configureMetrics = null)
{
var otlpEndpoint = configuration["OpenTelemetry:OtlpEndpoint"]
?? Environment.GetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT");
var exportOtlp = !string.IsNullOrWhiteSpace(otlpEndpoint);
services.AddOpenTelemetry()
.ConfigureResource(resource => resource.AddService(serviceName))
.WithTracing(tracing =>
{
configureTracing?.Invoke(tracing);
if (exportOtlp)
{
tracing.AddOtlpExporter();
}
})
.WithMetrics(metrics =>
{
metrics.AddRuntimeInstrumentation();
configureMetrics?.Invoke(metrics);
if (exportOtlp)
{
metrics.AddOtlpExporter();
}
});
return services;
}
}
@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using TeamUp.SharedKernel.Persistence;
namespace TeamUp.Infrastructure.Persistence;
public static class MigrationRunner
{
/// <summary>
/// Applies the platform migration first (vector extension + module schemas), then every
/// module DbContext discovered from DI. In the skeleton only the platform context exists;
/// the module loop is already wired so M1+ contexts apply with no change here.
/// </summary>
public static async Task MigrateAllAsync(
IServiceProvider services,
CancellationToken cancellationToken = default)
{
await using var scope = services.CreateAsyncScope();
var provider = scope.ServiceProvider;
await provider.GetRequiredService<PlatformDbContext>()
.Database.MigrateAsync(cancellationToken);
foreach (var moduleContext in provider.GetServices<IModuleDbContext>())
{
await ((DbContext)moduleContext).Database.MigrateAsync(cancellationToken);
}
}
}
@@ -0,0 +1,30 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using TeamUp.Infrastructure.Persistence;
#nullable disable
namespace TeamUp.Infrastructure.Persistence.Migrations
{
[DbContext(typeof(PlatformDbContext))]
[Migration("20260609030024_InitialPlatform")]
partial class InitialPlatform
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "vector");
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace TeamUp.Infrastructure.Persistence.Migrations
{
/// <inheritdoc />
public partial class InitialPlatform : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
// Enable the pgvector extension (database-global).
migrationBuilder.AlterDatabase()
.Annotation("Npgsql:PostgresExtension:vector", ",,");
// Create one schema per module; each module's DbContext (M1+) maps into its own schema.
foreach (var schema in PlatformDbContext.ModuleSchemas)
{
migrationBuilder.Sql($"CREATE SCHEMA IF NOT EXISTS \"{schema}\";");
}
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
foreach (var schema in PlatformDbContext.ModuleSchemas)
{
migrationBuilder.Sql($"DROP SCHEMA IF EXISTS \"{schema}\" CASCADE;");
}
}
}
}
@@ -0,0 +1,27 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using TeamUp.Infrastructure.Persistence;
#nullable disable
namespace TeamUp.Infrastructure.Persistence.Migrations
{
[DbContext(typeof(PlatformDbContext))]
partial class PlatformDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.8")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "vector");
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace TeamUp.Infrastructure.Persistence;
public static class PersistenceExtensions
{
/// <summary>
/// Registers the platform persistence: the bootstrap context (with the pgvector type handler)
/// and a DB health check. Module contexts are registered by their own modules at M1+.
/// </summary>
public static IServiceCollection AddTeamUpPersistence(
this IServiceCollection services,
IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString("Postgres")
?? throw new InvalidOperationException(
"Missing connection string 'ConnectionStrings:Postgres'.");
services.AddDbContext<PlatformDbContext>(options =>
options.UseNpgsql(connectionString, npgsql => npgsql.UseVector()));
services.AddHealthChecks()
.AddDbContextCheck<PlatformDbContext>("postgres");
return services;
}
}
@@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore;
namespace TeamUp.Infrastructure.Persistence;
/// <summary>
/// The bootstrap context. Owns only database-global concerns: the pgvector extension and the
/// per-module schemas. It holds ZERO domain tables — each module owns its own tables via its
/// own (internal) DbContext. Internal so no other assembly can touch it directly.
/// </summary>
internal sealed class PlatformDbContext(DbContextOptions<PlatformDbContext> options)
: DbContext(options)
{
/// <summary>The module schemas created by the initial migration. The single source of truth.</summary>
public static readonly string[] ModuleSchemas =
[
"identity",
"orgboard",
"skills",
"integrations",
"memory",
"assembler",
"governance",
];
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// The vector extension is database-global, not schema-scoped — this is the ONE place
// it is declared. Module contexts assume it already exists and never re-declare it.
modelBuilder.HasPostgresExtension("vector");
}
}
@@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
namespace TeamUp.Infrastructure.Persistence;
/// <summary>
/// Design-time factory so `dotnet ef migrations add ...` can construct the (internal) context
/// without booting a host. Reads the connection string from the environment with a localhost
/// dev fallback — the value only matters for `migrations add`, not at runtime.
/// </summary>
internal sealed class PlatformDbContextFactory : IDesignTimeDbContextFactory<PlatformDbContext>
{
public PlatformDbContext CreateDbContext(string[] args)
{
var connectionString =
Environment.GetEnvironmentVariable("ConnectionStrings__Postgres")
?? "Host=localhost;Port=5432;Database=teamup;Username=teamup;Password=teamup";
var options = new DbContextOptionsBuilder<PlatformDbContext>()
.UseNpgsql(connectionString, npgsql => npgsql.UseVector())
.Options;
return new PlatformDbContext(options);
}
}
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<!--
Shared platform infrastructure: the bootstrap PlatformDbContext (owns the pgvector
extension + module schemas), the migration runner, and persistence/observability wiring.
References SharedKernel only — NEVER any module (enforced by the architecture tests).
-->
<ItemGroup>
<ProjectReference Include="..\TeamUp.SharedKernel\TeamUp.SharedKernel.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" PrivateAssets="all" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
<PackageReference Include="Pgvector.EntityFrameworkCore" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
</ItemGroup>
</Project>
@@ -0,0 +1,10 @@
namespace TeamUp.SharedKernel.Domain;
/// <summary>
/// Base class for domain entities. Uses a UUIDv7 identifier — time-ordered, so it keeps
/// B-tree index locality (unlike a random v4) while remaining globally unique.
/// </summary>
public abstract class Entity
{
public Guid Id { get; protected set; } = Guid.CreateVersion7();
}
@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace TeamUp.SharedKernel.Modularity;
/// <summary>
/// The contract every domain module implements. A module is a self-contained slice of the
/// monolith with its own persistence and services. Modules collaborate only through public
/// abstractions resolved from DI — never by referencing each other's internals.
/// </summary>
public interface IModule
{
/// <summary>Stable lowercase key used for the module's DB schema and in logs (e.g. "orgboard").</summary>
string Name { get; }
/// <summary>
/// Register the module's services, validators, DbContext, etc. Runs in BOTH the web and
/// worker hosts, so a module's background-capable services are available to the worker.
/// </summary>
void Register(IServiceCollection services, IConfiguration configuration);
/// <summary>
/// Contribute Minimal-API endpoint groups. Called by the WEB host only — the worker never
/// invokes this, so modules contribute zero HTTP surface to the worker. Default is a no-op.
/// </summary>
void MapEndpoints(IEndpointRouteBuilder endpoints)
{
}
}
@@ -0,0 +1,4 @@
namespace TeamUp.SharedKernel.Modularity;
/// <summary>Response of a module's skeleton liveness endpoint — proves the module seam is wired.</summary>
public sealed record ModulePing(string Module, string Status = "ok");
@@ -0,0 +1,8 @@
namespace TeamUp.SharedKernel.Persistence;
/// <summary>
/// Marker implemented by each module's (internal) DbContext so the migration runner can
/// discover every module context from DI and apply its migrations uniformly. Keeping this in
/// SharedKernel lets Infrastructure migrate module contexts without referencing the modules.
/// </summary>
public interface IModuleDbContext;
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<!--
The dependency-light core. Defines the IModule seam and base domain/persistence
abstractions. The ASP.NET framework reference is here ONLY so IModule can name
IEndpointRouteBuilder / IServiceCollection / IConfiguration. No package deps,
no project deps — every module references this and nothing else of ours.
-->
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</Project>