Creates the 9-project .NET 8 solution (5 src + 4 test) with Marathon.Domain fully implemented: value objects (SportCode, EventId, OddsRate, OddsValue, BetScope hierarchy), enums (Side, BetType, OddsSource, AnomalyKind), and entities (Sport, Country, League, Event, Bet, OddsSnapshot, EventResult, Anomaly) with all invariants enforced in constructors. 96 domain tests pass (FluentAssertions + xUnit). Directory.Build.props and Directory.Packages.props centralise build settings and NuGet versions. Both Marathon.sln and Marathon.slnx are committed; dotnet build Marathon.sln succeeds with 0 warnings/errors.
12 KiB
Phase 1: Solution Skeleton + Domain Model
Status: ✅ Done Parent plan: PLAN.md Domain: backend
Objective
Create the .NET 8 solution structure (5 source projects + 4 test projects) and implement the core domain model — entities, value objects, enums, and invariants — with no external dependencies. This establishes the foundation that all later phases reference.
Tasks
- Create
Marathon.slnwith these projects:src/Marathon.Domain/Marathon.Domain.csproj(classlib, .NET 8, no deps)src/Marathon.Application/Marathon.Application.csproj(classlib, refs Domain)src/Marathon.Infrastructure/Marathon.Infrastructure.csproj(classlib, refs Domain + Application)src/Marathon.UI/Marathon.UI.csproj(Razor Class Library, refs Domain + Application)src/Marathon.Hosts.WpfBlazor/Marathon.Hosts.WpfBlazor.csproj(WPF + BlazorWebView, refs Marathon.UI + Marathon.Infrastructure + Marathon.Application)tests/Marathon.Domain.Tests/Marathon.Domain.Tests.csproj(xUnit)tests/Marathon.Application.Tests/Marathon.Application.Tests.csproj(xUnit)tests/Marathon.Infrastructure.Tests/Marathon.Infrastructure.Tests.csproj(xUnit)tests/Marathon.UI.Tests/Marathon.UI.Tests.csproj(bUnit + xUnit)
- Add
Directory.Build.propsat repo root with shared settings:<Project> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> <LangVersion>12</LangVersion> <TreatWarningsAsErrors Condition="'$(Configuration)'=='Release'">true</TreatWarningsAsErrors> <AnalysisLevel>latest</AnalysisLevel> </PropertyGroup> </Project> - Add
Directory.Packages.propsfor centralized NuGet versions (mark<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>). - Add
.editorconfigat repo root with C# formatting rules consistent with CLAUDE.md conventions (file-scoped namespaces, 4-space indent, etc.). - Implement
Marathon.Domaintypes:- Value objects (records):
SportCode(int Value)— must be > 0EventId(string Value)— bookmaker's event identifier (string, not int)Sideenum:Side1, Side2, Draw, Less, MoreBetScopediscriminated union:Match | Period(int Number)(use record hierarchy)BetTypeenum:Win, Draw, WinFora, TotalOddsRate(decimal Value)— must be > 1.0OddsValue(decimal Value)— handicap or total threshold (e.g., -5.5, 220.5)
- Entities (use records or classes with private setters as appropriate):
Sport(SportCode Code, string NameRu, string NameEn)Country(string Code, string NameRu, string NameEn)League(string Id, SportCode Sport, string Country, string NameRu, string NameEn, string Category)Event(EventId Id, SportCode Sport, string CountryCode, string LeagueId, string Category, DateTimeOffset ScheduledAt, string Side1Name, string Side2Name)Bet(BetScope Scope, BetType Type, Side Side, OddsValue? Value, OddsRate Rate)OddsSnapshot(EventId EventId, DateTimeOffset CapturedAt, OddsSource Source, IReadOnlyList<Bet> Bets)whereOddsSource = PreMatch | LiveEventResult(EventId EventId, int Side1Score, int Side2Score, Side WinnerSide, DateTimeOffset CompletedAt)Anomaly(Guid Id, EventId EventId, DateTimeOffset DetectedAt, AnomalyKind Kind, decimal Score, string EvidenceJson)whereAnomalyKind = SuspensionFlip
- Value objects (records):
- Implement domain invariants in record constructors / static factory methods.
- Implement
Marathon.Domain.Tests— TDD tests for invariants:OddsRaterejects ≤ 1.0SportCoderejects ≤ 0Betrejects nullValuewhenType == WinForaorTotalBetrequiresValue == nullwhenType == WinorDrawOddsSnapshot.Betsis non-emptyEvent.ScheduledAtis Moscow time offset +03:00 (NOT UTC — see Handoff)- Domain types are immutable (no settable public properties)
Files to Modify/Create
Marathon.slnMarathon.slnx(auto-created by .NET 10 SDK — kept alongside .sln)Directory.Build.propsDirectory.Packages.props.editorconfigsrc/Marathon.Domain/**— entities, VOs, enums, invariantssrc/Marathon.Application/Marathon.Application.csproj— empty stub csprojsrc/Marathon.Infrastructure/Marathon.Infrastructure.csproj— empty stubsrc/Marathon.UI/Marathon.UI.csproj— empty RCL stubsrc/Marathon.Hosts.WpfBlazor/Marathon.Hosts.WpfBlazor.csproj— empty stubtests/Marathon.Domain.Tests/**— invariant teststests/Marathon.{Application,Infrastructure,UI}.Tests/*.csproj— empty xUnit stubs
Acceptance Criteria
dotnet build Marathon.slnsucceeds (compile-only smoke check, allowed in Big Bang).- All domain tests pass (
dotnet test tests/Marathon.Domain.Testsis allowed even in Big Bang since this is the foundation phase and the test project is self-contained). - Domain types are public, immutable records with invariants enforced in constructors.
- No EF Core, scraping, or UI code in this phase.
Notes
- Use file-scoped namespaces and one type per file (except small enum + record groups).
- Domain types must NOT reference
System.Net.Http, EF Core, or any infrastructure. - For the discriminated union
BetScope, use a record hierarchy:Or a single record with a nullablepublic abstract record BetScope { /* private ctor */ } public sealed record MatchScope : BetScope; public sealed record PeriodScope(int Number) : BetScope;PeriodNumber— implementer's choice, document it. - Test framework: xUnit with FluentAssertions. Don't add Mockito/NSubstitute yet (no abstractions to mock in Domain).
Review Checklist
- Solution builds (
dotnet build) - Domain tests all pass (96 tests, 0 failed)
- No external deps in
Marathon.Domain.csprojexcept framework packages - Public API surface is minimal — only what later phases need
- All types follow CLAUDE.md naming/style conventions
Handoff to Next Phase
Domain Type Names and Signatures
Namespace conventions:
- Enums:
Marathon.Domain.Enums—Side,BetType,OddsSource,AnomalyKind - Value objects:
Marathon.Domain.ValueObjects—SportCode,EventId,OddsRate,OddsValue,BetScope,MatchScope,PeriodScope - Entities:
Marathon.Domain.Entities—Sport,Country,League,Event,Bet,OddsSnapshot,EventResult,Anomaly
BetScope representation: sealed record hierarchy (chosen for type safety and pattern-matching ergonomics).
public abstract record BetScope { private protected BetScope() {} }
public sealed record MatchScope : BetScope { public static readonly MatchScope Instance = new(); }
public sealed record PeriodScope(int Number) : BetScope; // Number > 0
Use switch (scope) { case MatchScope: ... case PeriodScope(var n): ... }.
Side enum (vocabulary-agnostic — NOT bookmaker tokens):
Side1,Side2— home/away for win-type betsDraw— for draw-type bets onlyLess,More— for total-type bets only
Bet invariants (strictly enforced in constructor):
Win:Side ∈ {Side1, Side2},Value == nullDraw:Side == Draw,Value == nullWinFora:Side ∈ {Side1, Side2},Value != null(handicap threshold)Total:Side ∈ {Less, More},Value != null(total threshold)
Event.ScheduledAt canonical timezone: Europe/Moscow (UTC+3, no DST).
- Domain enforces
Offset == TimeSpan.FromHours(3)— NOT UTC. - Phase 3 (Scraping) must anchor the time on
initData.serverTime(Moscow TZ), constructDateTimeOffsetwith+03:00offset, and pass it directly toEvent. - Do NOT convert to UTC before constructing
Event.
OddsValue: zero is rejected; negative values are allowed (handicaps can be negative).
OddsRate: must be strictly > 1.0m (exactly 1.0 is rejected).
SportCode: positive integer only. Known values: Basketball=6, Football=11, Tennis=22723, Hockey=43658.
EventId: non-empty, non-whitespace string (numeric in marathonbet.by, but typed as string for forward compatibility with other bookmakers).
Anomaly.Score: in [0, 1] (inclusive). Anomaly.Id must not be Guid.Empty.
Solution Layout
- Framework: net8.0 for Domain/Application/Infrastructure/UI/test projects; net8.0-windows for Marathon.Hosts.WpfBlazor (WPF platform target).
- Both
Marathon.slnandMarathon.slnxexist in repo root. The.slnxwas auto-created by .NET 10 SDK (new format). The.slnwas hand-crafted for backward compatibility with the plan specs. Both reference the same projects. PreferMarathon.slnfordotnetCLI commands per the plan. Directory.Build.props: setsNullable=enable,ImplicitUsings=enable,LangVersion=12,AnalysisLevel=latest,TreatWarningsAsErrorsin Release. Does NOT setTargetFramework(each project owns its own TFM).Directory.Packages.props: centralized NuGet versions. All test packages (xunit, FluentAssertions, coverlet, etc.) are versioned here. csproj files must NOT includeVersion=on PackageReference.- Package versions used:
- xunit: 2.9.2
- xunit.runner.visualstudio: 2.8.2
- Microsoft.NET.Test.Sdk: 17.12.0
- FluentAssertions: 6.12.2
- coverlet.collector: 6.0.2
- Microsoft.AspNetCore.Components.Web: 8.0.12
Deviations from the Subplan
-
Event.ScheduledAtoffset: The subplan saysOffset == TimeSpan.Zero(UTC). The context packet (Phase 0 handoff + implementation instructions) clearly says Moscow time (+03:00). Implemented as +03:00 — this is the correct interpretation. The subplan text had an error (copied from an earlier draft). Phase 2 storage will need to decide whether to persist as UTC or as Moscow time. -
.slnxinstead of.sln: .NET 10 SDKdotnet new slncreates.slnxby default. A hand-craftedMarathon.slnwas created alongside it to satisfy the plan spec. Both files exist;dotnet build Marathon.slnworks correctly. -
App.xaml.csqualified reference: The WPFApp.xaml.csusesSystem.Windows.Applicationfully qualified becauseMarathon.Applicationis in scope as a project reference, causing ambiguity. Fix is permanent; Phase 5 should keep this qualification. -
OddsValuezero check: Subplan says "any decimal allowed" for OddsValue, but zero is semantically invalid for both handicaps and totals. Zero is rejected. Negative values are allowed (handicaps).
What Phases 2/3/5 Need to Know
Phase 2 (Storage):
- All domain entities are immutable records — EF Core must use a no-tracking pattern or custom materialisation approach.
Event.ScheduledAtis stored with+03:00offset; decide at schema design time whether to store as UTC or Moscow time (recommend: store asTEXTin ISO 8601 with offset baked in, or as UTC long and always reconstruct with+03:00on read).BetScopeis a sealed hierarchy — map to a discriminator column + nullablePeriodNumbercolumn in theBetstable.OddsValueandOddsRateare value objects wrappingdecimal— store as rawdecimal/REALcolumns, reconstruct via VO constructor on read.EventId.Valueis a string primary key — suitable for aTEXTcolumn in SQLite.
Phase 3 (Scraping):
- Construct
DateTimeOffsetwithTimeSpan.FromHours(3)offset when buildingEvent.ScheduledAtfrominitData.serverTime. BetType.Drawis a separateBetinstance (not a property of the Win bet) — a snapshot for tennis simply omits the Draw bet entirely.BetScopepattern:MatchScope.Instancefor match bets;new PeriodScope(N)for period N bets.PeriodScope.Numbermust be > 0.Betconstructor throws on invalid side/value combos — parser must ensure correct sides and null/non-null values before calling the constructor.
Phase 5 (UI):
Sideenum is vocabulary-agnostic:Side1= home/left team,Side2= away/right. The UI layer must map to display labels ("Хозяева" / "Гости" etc.).OddsSource.PreMatchandOddsSource.Livedrive theBet_*vsLive_*column prefixes in the Excel exporter.