Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ node node_modules/@angular/cli/bin/ng.js build --configuration development
node node_modules/@angular/cli/bin/ng.js test --watch=false
```

There is no lint script. Backend test projects currently contain no tests.
There is no lint script. Infrastructure tests require Docker with Linux containers
and use a temporary PostgreSQL container; other backend test projects are empty.
AppHost starts containers, installs frontend dependencies and applies migrations;
do not use it as a substitute for build/test verification. See README.md for setup.

Expand Down
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<PackageVersion Include="Aspire.Hosting.PostgreSQL" Version="13.6.5" />
<PackageVersion Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="13.6.5" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.15" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="10.0.15" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.15" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="10.0.15" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="10.0.15" />
Expand All @@ -23,5 +24,6 @@
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.21.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="4.0.1" />
<PackageVersion Include="xunit.v3" Version="3.2.2" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.14.0" />
</ItemGroup>
</Project>
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ All projects use the `ChessRealms.Platform` prefix:
- `src/ChessRealms.Platform.MigrationWorker` — console host that applies migrations and exits; references Infrastructure and ServiceDefaults.
- `orchestration/ChessRealms.Platform.AppHost` — PostgreSQL, migration worker, API, and Angular frontend orchestration.
- `orchestration/ChessRealms.Platform.ServiceDefaults` — shared telemetry, health checks, service discovery, and HTTP resilience.
- `tests/` — separate empty xUnit v3 projects referencing Api, Application, Domain, and Infrastructure respectively.
- `tests/` — xUnit v3 projects referencing Api, Application, Domain, and Infrastructure respectively.

`Infrastructure` leaves room for integrations beyond persistence. `PlatformDbContext` currently has no entities. An empty `InitialCreate` migration establishes the migration pipeline without adding business tables.

The isolated `Infrastructure/Identity` module provides ASP.NET Core Identity stores
in a separate `IdentityDbContext`, using the `identity` schema in the same PostgreSQL
database. See [architecture decisions](docs/architecture.md) for boundaries and scope.

### Build and test

Run from the repository root:
Expand All @@ -70,7 +74,10 @@ dotnet build ChessRealms.Platform.slnx --no-restore
dotnet test ChessRealms.Platform.slnx --no-build --no-restore
```

The test projects intentionally contain no tests, so the runner currently reports that no tests were found. Package versions are centralized and each project has a NuGet lock file.
Infrastructure tests require Docker with Linux containers. Testcontainers starts a
temporary PostgreSQL 18.3 container and verifies migrations and Identity persistence;
it does not use the development database or AppHost. The other test projects are
currently empty. Package versions are centralized and each project has a NuGet lock file.

For the frontend:

Expand All @@ -85,7 +92,7 @@ The Angular app stays outside the .NET solution; Aspire runs it directly from it

### Continuous integration

The [CI workflow](.github/workflows/ci.yml) runs on every push and pull request with separate backend and frontend jobs on Ubuntu. The backend uses the SDK from `global.json`, restores with `--locked-mode`, builds, and runs tests without restoring or rebuilding. The frontend uses Node.js 26 and the npm version from `package.json`, installs with `npm ci`, builds the development configuration, and runs Vitest without watch mode. CI does not start AppHost or containers.
The [CI workflow](.github/workflows/ci.yml) runs on every push and pull request with separate backend and frontend jobs on Ubuntu. The backend uses the SDK from `global.json`, restores with `--locked-mode`, builds, and runs tests without restoring or rebuilding. Infrastructure tests use the runner's Docker daemon for temporary PostgreSQL containers. The frontend uses Node.js 26 and the npm version from `package.json`, installs with `npm ci`, builds the development configuration, and runs Vitest without watch mode. CI does not start AppHost.

### Run locally

Expand All @@ -105,10 +112,12 @@ The worker has a two-minute timeout, configurable through `Migration__Timeout` (
### Add a migration

```shell
dotnet ef migrations add MigrationName --project src/ChessRealms.Platform.Infrastructure --output-dir Persistence/Migrations
dotnet ef migrations add MigrationName --context PlatformDbContext --project src/ChessRealms.Platform.Infrastructure --output-dir Persistence/Migrations
```

The design-time factory allows scaffolding without starting PostgreSQL or AppHost. For EF commands that connect to a database, set `ConnectionStrings__platform` to the connection string shown in the Aspire dashboard. Apply migrations through MigrationWorker; the API does not migrate the database on startup.
For Identity migrations, use `--context IdentityDbContext --output-dir Identity/Persistence/Migrations` instead.

The design-time factories allow scaffolding without starting PostgreSQL or AppHost. For EF commands that connect to a database, set `ConnectionStrings__platform` to the connection string shown in the Aspire dashboard. Apply migrations through MigrationWorker, which migrates both contexts; the API does not migrate the database on startup.

Documentation is maintained in English.

Expand Down
58 changes: 58 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Platform architecture decisions

## Boundaries

The platform remains a modular monolith. Domain has no project dependencies;
Application references Domain, Infrastructure references Application, and Api
composes the application and infrastructure. PostgreSQL and EF Core provide persistence.

Identity is an isolated module under `Infrastructure/Identity`, not a microservice.
It owns `PlatformUser`, its EF stores, DI registration, and migrations. Its separate
`IdentityDbContext` uses the same database as `PlatformDbContext`, but owns the
`identity` schema and its own migration history. MigrationWorker applies platform
migrations followed by Identity migrations; Api never migrates on startup.
These are separate migration operations, not one cross-context transaction.

ASP.NET Core Identity types must not enter Domain or Application. Future application
use cases should access identity through narrow application contracts and stable
user IDs. Game participants will not require an `IdentityUser` object.

## Accounts and authentication

Accounts use GUID identifiers and ASP.NET Core Identity for password hashing,
validation, and persistence. Email must be unique (including a database constraint
on normalized email). Confirmed email is configured as a prerequisite for sign-in;
future login code must enforce it before issuing tokens. Roles are not required yet,
so the context uses the user-only Identity model.

The chosen direction is application-issued JWT access tokens, rotating refresh
tokens, and revocation of individual or all login sessions, without a separate
OAuth authorization server. Token lifetimes, refresh transport, concurrency handling,
and immediate versus expiry-based access-token revocation remain to be specified.
Google login is optional and can be added later.

This foundation registers Identity core services and EF stores only. It does not
enable authentication schemes, expose endpoints, issue tokens, or provide email
confirmation/reset flows. Token providers, email delivery, abuse protection, and
Angular integration belong to subsequent work.

## Game functionality

Chess rules come from ChessRealms/Engine. Guests are temporary participants without
an ASP.NET Core Identity record, but require a protected guest session. They can play
with guests or registered users. Login sessions, lobbies, and chess games are distinct
concepts. Private lobbies will support invitations to registered users, an opt-out
for incoming invitations, optional passwords, and invitation spam protection.

Clock requirements and guest-to-account conversion remain open. Playing against the
computer remains part of the initial product milestone. Branch protection and
repository rules will be configured manually later.

## Delivery order

1. Identity persistence and integration verification (this foundation).
2. Registration/email confirmation, JWT and refresh sessions, revocation, and recovery.
3. Angular authentication integration.
4. Engine integration and persistent game state.
5. Online games, reconnects, guests, lobbies, and invitations.
6. Computer opponent; optional Google login and additional Identity features separately.
10 changes: 10 additions & 0 deletions src/ChessRealms.Platform.Api/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
"dependencies": {
"Aspire.Npgsql.EntityFrameworkCore.PostgreSQL": "[13.6.5, )",
"ChessRealms.Platform.Application": "[1.0.0, )",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.15, )",
"Microsoft.EntityFrameworkCore": "[10.0.15, )",
"Microsoft.EntityFrameworkCore.Relational": "[10.0.15, )",
"Npgsql.EntityFrameworkCore.PostgreSQL": "[10.0.3, )"
Expand Down Expand Up @@ -212,6 +213,15 @@
"OpenTelemetry.Extensions.Hosting": "1.17.0"
}
},
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": {
"type": "CentralTransitive",
"requested": "[10.0.15, )",
"resolved": "10.0.15",
"contentHash": "vazYMsviWu/+efWfWiD95ZHZZ/SUf10MAfWeJ8ADK8oa5SjLO41NE7ii0eVQhHqWBBXh4s0zMQor2F8J25Oh5g==",
"dependencies": {
"Microsoft.EntityFrameworkCore.Relational": "10.0.15"
}
},
"Microsoft.EntityFrameworkCore": {
"type": "CentralTransitive",
"requested": "[10.0.15, )",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ItemGroup>
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" />
<PackageReference Include="Microsoft.EntityFrameworkCore" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" PrivateAssets="all" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using ChessRealms.Platform.Infrastructure.Identity;
using ChessRealms.Platform.Infrastructure.Persistence;

using Microsoft.Extensions.Hosting;
Expand All @@ -10,6 +11,7 @@ public static TBuilder AddInfrastructure<TBuilder>(this TBuilder builder)
where TBuilder : IHostApplicationBuilder
{
builder.AddNpgsqlDbContext<PlatformDbContext>("platform");
builder.AddPlatformIdentity();
return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using ChessRealms.Platform.Infrastructure.Identity.Persistence;

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace ChessRealms.Platform.Infrastructure.Identity;

public static class DependencyInjection
{
public static TBuilder AddPlatformIdentity<TBuilder>(this TBuilder builder)
where TBuilder : IHostApplicationBuilder
{
builder.AddNpgsqlDbContext<IdentityDbContext>("platform",
configureDbContextOptions: options => options.UseNpgsql(postgres =>
postgres.MigrationsHistoryTable("__EFMigrationsHistory", IdentityDbContext.Schema)));

builder.Services.AddIdentityCore<PlatformUser>(options =>
{
options.User.RequireUniqueEmail = true;
options.SignIn.RequireConfirmedEmail = true;
}).AddEntityFrameworkStores<IdentityDbContext>();

return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.EntityFrameworkCore;

namespace ChessRealms.Platform.Infrastructure.Identity.Persistence;

public sealed class IdentityDbContext(DbContextOptions<IdentityDbContext> options)
: Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserContext<PlatformUser, Guid>(options)
{
public const string Schema = "identity";

protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.HasDefaultSchema(Schema);
builder.Entity<PlatformUser>().HasIndex(user => user.NormalizedEmail)
.IsUnique();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

namespace ChessRealms.Platform.Infrastructure.Identity.Persistence;

public sealed class IdentityDbContextFactory : IDesignTimeDbContextFactory<IdentityDbContext>
{
public IdentityDbContext CreateDbContext(string[] args)
{
string connectionString = Environment.GetEnvironmentVariable("ConnectionStrings__platform")
?? "Host=localhost;Database=platform;Username=postgres";
DbContextOptions<IdentityDbContext> options = new DbContextOptionsBuilder<IdentityDbContext>()
.UseNpgsql(connectionString, postgres =>
postgres.MigrationsHistoryTable("__EFMigrationsHistory", IdentityDbContext.Schema))
.Options;

return new IdentityDbContext(options);
}
}
Loading
Loading