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:
@@ -0,0 +1,24 @@
|
||||
<Project>
|
||||
|
||||
<!-- Inherit the repo-root Directory.Build.props (MSBuild stops at the first one it finds
|
||||
walking up, so test projects must import the parent explicitly), then add the shared
|
||||
test settings + the common xUnit v3 package set. -->
|
||||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
|
||||
|
||||
<PropertyGroup>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<OutputType>Exe</OutputType>
|
||||
<!-- Analyzer rules that fight idiomatic test code:
|
||||
CA1707 underscored test names · CA1711 xUnit [CollectionDefinition] "Collection" suffix
|
||||
· xUnit1051 TestContext cancellation token (not needed for these short tests). -->
|
||||
<NoWarn>$(NoWarn);CA1707;CA1711;xUnit1051</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="xunit.v3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Reflection;
|
||||
using TeamUp.Bootstrap;
|
||||
using TeamUp.Infrastructure.Persistence;
|
||||
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.ArchitectureTests;
|
||||
|
||||
/// <summary>
|
||||
/// Handles to the production assemblies. The boundary tests assert on real assembly references
|
||||
/// (<see cref="Assembly.GetReferencedAssemblies"/>) — reflection is deterministic and needs no
|
||||
/// third-party arch-test framework. Because each module is its own assembly, an assembly-level
|
||||
/// reference check is exactly the "no cross-module access" boundary.
|
||||
/// </summary>
|
||||
internal static class ArchitectureFixture
|
||||
{
|
||||
public static readonly Assembly SharedKernel = typeof(IModule).Assembly;
|
||||
public static readonly Assembly Infrastructure = typeof(MigrationRunner).Assembly;
|
||||
public static readonly Assembly Bootstrap = typeof(ModuleCatalog).Assembly;
|
||||
|
||||
public static readonly Assembly[] ModuleAssemblies =
|
||||
[
|
||||
typeof(IdentityModule).Assembly,
|
||||
typeof(OrgBoardModule).Assembly,
|
||||
typeof(SkillsModule).Assembly,
|
||||
typeof(IntegrationsModule).Assembly,
|
||||
typeof(MemoryModule).Assembly,
|
||||
typeof(AssemblerModule).Assembly,
|
||||
typeof(GovernanceModule).Assembly,
|
||||
];
|
||||
|
||||
public static HashSet<string> ReferencedAssemblyNames(this Assembly assembly) =>
|
||||
assembly.GetReferencedAssemblies()
|
||||
.Select(name => name.Name!)
|
||||
.ToHashSet(StringComparer.Ordinal);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using Xunit;
|
||||
|
||||
namespace TeamUp.ArchitectureTests;
|
||||
|
||||
/// <summary>
|
||||
/// Encodes the non-negotiable "no cross-module table access" discipline as build-time rules.
|
||||
/// The <c>internal</c>-per-assembly design is the hard wall (another module's entities/DbContext
|
||||
/// aren't even visible); these reference checks guard the gate the compiler can't: a module
|
||||
/// adding a project reference to another module, or to shared Infrastructure/Bootstrap/hosts.
|
||||
/// </summary>
|
||||
public sealed class ModuleBoundaryTests
|
||||
{
|
||||
[Fact]
|
||||
public void Modules_do_not_reference_each_other()
|
||||
{
|
||||
foreach (var module in ArchitectureFixture.ModuleAssemblies)
|
||||
{
|
||||
var references = module.ReferencedAssemblyNames();
|
||||
|
||||
foreach (var other in ArchitectureFixture.ModuleAssemblies)
|
||||
{
|
||||
if (ReferenceEquals(module, other))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var otherName = other.GetName().Name!;
|
||||
Assert.False(
|
||||
references.Contains(otherName),
|
||||
$"{module.GetName().Name} must not reference module {otherName} — collaborate via abstractions in DI.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Modules_do_not_reference_infrastructure_bootstrap_or_hosts()
|
||||
{
|
||||
string[] forbidden = ["TeamUp.Infrastructure", "TeamUp.Bootstrap", "TeamUp.Web", "TeamUp.Worker"];
|
||||
|
||||
foreach (var module in ArchitectureFixture.ModuleAssemblies)
|
||||
{
|
||||
var references = module.ReferencedAssemblyNames();
|
||||
|
||||
foreach (var name in forbidden)
|
||||
{
|
||||
Assert.False(
|
||||
references.Contains(name),
|
||||
$"{module.GetName().Name} must not reference {name} — only SharedKernel is allowed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Every_module_references_sharedkernel()
|
||||
{
|
||||
// Sanity: each module genuinely sits on the kernel (uses IModule / ModulePing).
|
||||
foreach (var module in ArchitectureFixture.ModuleAssemblies)
|
||||
{
|
||||
Assert.Contains("TeamUp.SharedKernel", module.ReferencedAssemblyNames());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SharedKernel_references_no_teamup_projects()
|
||||
{
|
||||
var teamUpReferences = ArchitectureFixture.SharedKernel.ReferencedAssemblyNames()
|
||||
.Where(name => name.StartsWith("TeamUp.", StringComparison.Ordinal));
|
||||
|
||||
Assert.Empty(teamUpReferences);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Infrastructure_references_only_sharedkernel_among_teamup_projects()
|
||||
{
|
||||
var teamUpReferences = ArchitectureFixture.Infrastructure.ReferencedAssemblyNames()
|
||||
.Where(name => name.StartsWith("TeamUp.", StringComparison.Ordinal))
|
||||
.OrderBy(name => name, StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
|
||||
Assert.Equal(["TeamUp.SharedKernel"], teamUpReferences);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TeamUp.Bootstrap;
|
||||
using TeamUp.Infrastructure.Persistence;
|
||||
using TeamUp.SharedKernel.Modularity;
|
||||
using Xunit;
|
||||
|
||||
namespace TeamUp.ArchitectureTests;
|
||||
|
||||
/// <summary>
|
||||
/// Guards persistence encapsulation and module shape. A module's DbContext/entities are its
|
||||
/// private business — never public — and each module exposes exactly one registration seam.
|
||||
/// </summary>
|
||||
public sealed class PersistenceEncapsulationTests
|
||||
{
|
||||
private static readonly System.Reflection.Assembly[] AllProductionAssemblies =
|
||||
[
|
||||
typeof(IModule).Assembly,
|
||||
typeof(MigrationRunner).Assembly,
|
||||
typeof(ModuleCatalog).Assembly,
|
||||
.. ArchitectureFixture.ModuleAssemblies,
|
||||
];
|
||||
|
||||
[Fact]
|
||||
public void No_DbContext_is_publicly_visible()
|
||||
{
|
||||
var publicContexts = AllProductionAssemblies
|
||||
.SelectMany(assembly => assembly.GetTypes())
|
||||
.Where(type => typeof(DbContext).IsAssignableFrom(type) && type.IsPublic)
|
||||
.Select(type => type.FullName)
|
||||
.ToList();
|
||||
|
||||
Assert.True(
|
||||
publicContexts.Count == 0,
|
||||
$"A DbContext must be internal to its module. Public contexts found: {string.Join(", ", publicContexts)}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Each_module_assembly_exposes_exactly_one_IModule()
|
||||
{
|
||||
foreach (var assembly in ArchitectureFixture.ModuleAssemblies)
|
||||
{
|
||||
var implementations = assembly.GetTypes()
|
||||
.Where(type => typeof(IModule).IsAssignableFrom(type)
|
||||
&& type is { IsInterface: false, IsAbstract: false })
|
||||
.ToList();
|
||||
|
||||
Assert.True(
|
||||
implementations.Count == 1,
|
||||
$"{assembly.GetName().Name} must expose exactly one IModule; found {implementations.Count}.");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ModuleCatalog_lists_every_module_with_a_unique_name()
|
||||
{
|
||||
var modules = ModuleCatalog.All;
|
||||
|
||||
Assert.Equal(ArchitectureFixture.ModuleAssemblies.Length, modules.Count);
|
||||
|
||||
var names = modules.Select(module => module.Name).ToList();
|
||||
Assert.All(names, name => Assert.False(string.IsNullOrWhiteSpace(name)));
|
||||
Assert.Equal(names.Count, names.Distinct(StringComparer.Ordinal).Count());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!-- References Bootstrap, which transitively pulls SharedKernel, Infrastructure, and all 7
|
||||
module assemblies into the output — everything ArchUnitNET needs to analyse the boundary.
|
||||
Hosts are intentionally NOT referenced (avoids the duplicate top-level `Program` type);
|
||||
host-direction rules are expressed via namespace targets. -->
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Bootstrap\TeamUp.Bootstrap\TeamUp.Bootstrap.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,91 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using Npgsql;
|
||||
using Xunit;
|
||||
|
||||
namespace TeamUp.IntegrationTests;
|
||||
|
||||
/// <summary>
|
||||
/// End-to-end skeleton proof: the web host boots, the platform migration applies (vector
|
||||
/// extension + the 7 module schemas), health is green, every module endpoint seam is wired, and
|
||||
/// the OpenAPI document is served. All tests share one container (sequential, same collection).
|
||||
/// </summary>
|
||||
[Collection(PostgresCollection.Name)]
|
||||
public sealed class BootAndMigrateTests(PostgresFixture postgres)
|
||||
{
|
||||
private static readonly string[] ExpectedSchemas =
|
||||
["identity", "orgboard", "skills", "integrations", "memory", "assembler", "governance"];
|
||||
|
||||
[Fact]
|
||||
public async Task Health_endpoint_reports_200()
|
||||
{
|
||||
await using var factory = new TeamUpWebFactory(postgres.ConnectionString);
|
||||
using var client = factory.CreateClient();
|
||||
|
||||
var response = await client.GetAsync("/health");
|
||||
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Startup_migration_creates_vector_extension_and_module_schemas()
|
||||
{
|
||||
await using var factory = new TeamUpWebFactory(postgres.ConnectionString);
|
||||
using (factory.CreateClient())
|
||||
{
|
||||
// Creating the client forces the host to start, which applies the migration.
|
||||
}
|
||||
|
||||
await using var connection = new NpgsqlConnection(postgres.ConnectionString);
|
||||
await connection.OpenAsync();
|
||||
|
||||
await using (var extensionCmd =
|
||||
new NpgsqlCommand("SELECT 1 FROM pg_extension WHERE extname = 'vector'", connection))
|
||||
{
|
||||
Assert.NotNull(await extensionCmd.ExecuteScalarAsync());
|
||||
}
|
||||
|
||||
foreach (var schema in ExpectedSchemas)
|
||||
{
|
||||
await using var schemaCmd = new NpgsqlCommand(
|
||||
"SELECT 1 FROM information_schema.schemata WHERE schema_name = @schema", connection);
|
||||
schemaCmd.Parameters.AddWithValue("schema", schema);
|
||||
Assert.NotNull(await schemaCmd.ExecuteScalarAsync());
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("identity")]
|
||||
[InlineData("orgboard")]
|
||||
[InlineData("skills")]
|
||||
[InlineData("integrations")]
|
||||
[InlineData("memory")]
|
||||
[InlineData("assembler")]
|
||||
[InlineData("governance")]
|
||||
public async Task Module_ping_endpoint_responds(string module)
|
||||
{
|
||||
await using var factory = new TeamUpWebFactory(postgres.ConnectionString);
|
||||
using var client = factory.CreateClient();
|
||||
|
||||
var response = await client.GetAsync($"/api/{module}/ping");
|
||||
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var payload = await response.Content.ReadFromJsonAsync<ModulePingResponse>();
|
||||
Assert.NotNull(payload);
|
||||
Assert.Equal(module, payload!.Module);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OpenApi_document_is_served()
|
||||
{
|
||||
await using var factory = new TeamUpWebFactory(postgres.ConnectionString);
|
||||
using var client = factory.CreateClient();
|
||||
|
||||
var response = await client.GetAsync("/openapi/v1.json");
|
||||
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
}
|
||||
|
||||
private sealed record ModulePingResponse(string Module, string Status);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Testcontainers.PostgreSql;
|
||||
using Xunit;
|
||||
|
||||
namespace TeamUp.IntegrationTests;
|
||||
|
||||
/// <summary>A throwaway Postgres 17 + pgvector container, shared across the integration tests.</summary>
|
||||
public sealed class PostgresFixture : IAsyncLifetime
|
||||
{
|
||||
private readonly PostgreSqlContainer _container = new PostgreSqlBuilder()
|
||||
.WithImage("pgvector/pgvector:pg17")
|
||||
.WithDatabase("teamup")
|
||||
.WithUsername("teamup")
|
||||
.WithPassword("teamup")
|
||||
.Build();
|
||||
|
||||
public string ConnectionString => _container.GetConnectionString();
|
||||
|
||||
public async ValueTask InitializeAsync() => await _container.StartAsync();
|
||||
|
||||
public async ValueTask DisposeAsync() => await _container.DisposeAsync();
|
||||
}
|
||||
|
||||
[CollectionDefinition(Name)]
|
||||
public sealed class PostgresCollection : ICollectionFixture<PostgresFixture>
|
||||
{
|
||||
public const string Name = "postgres";
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!-- Boots the real web host (WebApplicationFactory) against a throwaway pgvector container
|
||||
(Testcontainers). References ONLY the web host — not the worker — so there is a single,
|
||||
unambiguous top-level `Program` to drive. Needs a running Docker daemon. -->
|
||||
<PropertyGroup>
|
||||
<!-- Testcontainers 4.12 deprecated the parameterless PostgreSqlBuilder() ctor in favour of an
|
||||
image-parameter ctor; the documented .WithImage(...) fluent path still works. -->
|
||||
<NoWarn>$(NoWarn);CS0618</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
|
||||
<PackageReference Include="Testcontainers.PostgreSql" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Hosts\TeamUp.Web\TeamUp.Web.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,19 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
|
||||
namespace TeamUp.IntegrationTests;
|
||||
|
||||
/// <summary>
|
||||
/// Drives the real <see cref="Program"/> web host against the test container, in Development so
|
||||
/// migrations apply on startup and the OpenAPI document is mapped.
|
||||
/// </summary>
|
||||
public sealed class TeamUpWebFactory(string connectionString) : WebApplicationFactory<Program>
|
||||
{
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
builder.UseEnvironment("Development");
|
||||
builder.UseSetting("ConnectionStrings:Postgres", connectionString);
|
||||
builder.UseSetting("Database:ApplyMigrationsOnStartup", "true");
|
||||
builder.UseSetting("OpenTelemetry:OtlpEndpoint", string.Empty);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user