087fbdd176
Budget.Core: entities, DTOs, enums, FrequencyCalculator (no EF/ASP.NET deps) Budget.Infrastructure: AppDbContext, migrations, BudgetAuthorizationService Budget.Api: controllers, middleware, Program.cs — references both projects EF and Npgsql packages moved to Infrastructure; Api retains only JwtBearer, HealthChecks, and EF.Design (needed for dotnet ef CLI). Dockerfile updated to copy all three project directories before publishing. Migration namespaces updated from Budget.Api.Data.* to Budget.Infrastructure.Data.* and model type strings updated to Budget.Core.Models.* in the snapshot. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
4.1 KiB
4.1 KiB
Plan: Core / Infrastructure / API Project Split
Goal
Split the single Budget.Api project into three projects matching the stwaddle stack pattern:
Budget.Core— entities, DTOs, enums. No ASP.NET or EF dependencies.Budget.Infrastructure— DbContext, EF configs, migrations, domain services.Budget.Api— controllers, middleware, Program.cs, DI wiring.
Current state
Everything lives in src/Budget.Api/:
Models/ Budget, Income, Outgo, BudgetShare, KnownUser, enums
DTOs/ BudgetDtos, IncomeDtos, OutgoDtos, ShareDtos, SummaryDtos
Data/ AppDbContext, Migrations/
Services/ BudgetAuthorizationService, FrequencyCalculator,
KnownUserMiddleware, ErrorHandlingMiddleware, ClaimsPrincipalExtensions
Controllers/ BudgetsController, IncomesController, OutgosController,
SharesController, SummaryController
Program.cs
Target state
src/
Budget.Core/
Models/ Budget, Income, Outgo, BudgetShare, KnownUser, enums
DTOs/ all DTO records and request types
Services/ FrequencyCalculator (pure logic, no EF/ASP.NET)
Budget.Infrastructure/
Data/ AppDbContext, Migrations/
Services/ BudgetAuthorizationService
Budget.Api/
Controllers/
Services/ KnownUserMiddleware, ErrorHandlingMiddleware,
ClaimsPrincipalExtensions
Program.cs
References: Budget.Api → Budget.Infrastructure → Budget.Core
Steps
Phase 1 — Create projects and move files
dotnet new classlib -n Budget.Core -o src/Budget.Core --framework net10.0dotnet new classlib -n Budget.Infrastructure -o src/Budget.Infrastructure --framework net10.0- Add both to the solution:
dotnet sln add src/Budget.Core/Budget.Core.csproj src/Budget.Infrastructure/Budget.Infrastructure.csproj - Move
Models/andDTOs/toBudget.Core; update namespaces fromBudget.Api.*toBudget.Core.*. - Move
FrequencyCalculator.cstoBudget.Core/Services/. - Move
Data/(AppDbContext + Migrations) toBudget.Infrastructure/Data/. - Move
BudgetAuthorizationService.cstoBudget.Infrastructure/Services/.
Phase 2 — Wire up project references and NuGet packages
- Add project reference:
Budget.Infrastructure→Budget.Core. - Move EF Core + Npgsql NuGet packages from
Budget.Api.csprojtoBudget.Infrastructure.csproj. Keep onlyMicrosoft.AspNetCore.Authentication.JwtBearerand health-check packages inBudget.Api.csproj. - Add project references to
Budget.Api.csproj: bothBudget.CoreandBudget.Infrastructure. - Add
Microsoft.EntityFrameworkCore.DesigntoBudget.Api.csproj(needed fordotnet efCLI to find the startup project).
Phase 3 — Update namespaces and using statements
- Global search-replace across all moved files:
namespace Budget.Api→namespace Budget.Coreornamespace Budget.Infrastructureas appropriate. - Update
usingdirectives in all controllers, middleware, and Program.cs to reference the new namespaces.
Phase 4 — Update Dockerfile and EF migrations command
- Update Dockerfile Stage 2 to copy and restore all three projects before publishing
Budget.Api. - Verify
dotnet ef migrations addcommand still works with--project Budget.Infrastructure --startup-project Budget.Api. - Build and confirm zero errors.
Key decisions
ClaimsPrincipalExtensionsand the two middleware classes stay inBudget.Api— they have direct ASP.NET dependencies and are not reusable across projects.BudgetAuthorizationServicegoes inBudget.Infrastructurebecause it queries the DbContext.FrequencyCalculatorgoes inBudget.Corebecause it is pure arithmetic with no external dependencies.- DTOs stay in
Budget.Core(notBudget.Api) soBudget.Infrastructurecan reference them if needed without creating a circular dependency.
Files affected
Budget.sln- New:
src/Budget.Core/Budget.Core.csproj - New:
src/Budget.Infrastructure/Budget.Infrastructure.csproj src/Budget.Api/Budget.Api.csproj(trim NuGet packages, add project refs)- All
.csfiles undersrc/Budget.Api/(namespace updates) Dockerfile(Stage 2 COPY pattern)