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,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>