AccountingNext/CLAUDE.md
Claudio Schaad a58f08e82a Wasser & Heizung: plausibility checks in the bill dialog
The dialog shows a "Kontrolle" section (WaterHeatingBillChecks): the NeoVac
per-mille shares against the optional ones of the property manager,
optional meter readings continuing from the previous bill, the property
totals implied by the own share, and the prices per unit compared with
the previous bill (flagged above ±25 %).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 19:33:21 +01:00

8.4 KiB
Raw Blame History

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Commands

# Build
dotnet build

# Run (dev server at http://localhost:5225)
cd Schaad.Accounting.UI && dotnet run

# Test
dotnet test

# Publish
dotnet publish -c Release

Tests live in Schaad.Accounting.Tests (xUnit + NSubstitute + Shouldly). There is no lint command.

Architecture

AccountingNext is a Swiss personal accounting app built with ASP.NET Core 9 + Blazor (interactive server-side rendering) and Microsoft Fluent UI. Data is stored as human-readable JSON files on disk (System.Text.Json, settings in JsonStorage) — no database.

Projects

Project Role
Schaad.Accounting.UI Blazor web app — pages, dialogs, layout
Schaad.Accounting.Services Business logic — balances, FX conversion, file import, charts
Schaad.Accounting.Db Repository layer — JSON serialization/deserialization
Schaad.Accounting.Common Shared models, DTOs, interfaces

Data flow

Blazor Pages/Dialogs (UI)
  → Services (ViewService, FileService, ChartService)
  → Repositories (AccountRepository, TransactionRepository, …)
  → JSON files: {DataPath}/{mandator}/{year}/*.json

Data is multi-mandator and multi-year. The layout below DataPath (configured in appsettings.Development.json) is defined in DataFolders:

{DataPath}/{mandator}/{year}/*.json          data files
{DataPath}/{mandator}/electricity.json       electricity bills (not per year, see below)
{DataPath}/{mandator}/water.json             water bills (not per year, see below)
{DataPath}/{mandator}/water-heating.json     NeoVac water and heating bills (not per year, see below)
{DataPath}/backup/{mandator}/{year}/         backup zips

When a new year is opened, the previous year's data is copied as the starting point.

electricity.json, water.json and water-heating.json are the data files kept per mandator instead of per year (ISettingsService.GetMandatorPath()), because the NeoVac billing period runs 1 July–30 June and doesn't align with calendar years.

Key services

  • ViewService — aggregates account balances, applies FX rates, builds datasets for the UI
  • FileService — imports bank statements (MT940, CAMT053 via external Schaad.Finance.dll; uploads go to temp files only), manages backups
  • ChartService — produces data for the Plotly booking-text charts on the transactions page
  • SettingsService — manages the active year, mandator, and file paths
  • RawDataRepository — plain-text load/save of the data files for the JSON editor page; validates (strict JSON, unique Ids, account references), refuses if the file changed since loading, and backs up the old version to backup/{mandator}/{year}/json-{timestamp}/; for electricity.json, water.json and water-heating.json it reads/writes the mandator folder instead of the year folder
  • Texte bereinigen page (TextCleanup) — edits only the Text of one account's bookings in the selected year (inline, search/replace via TextReplacement, bulk set); saves through RawDataRepository.SaveTransactionTextsAsync
  • AnalyticsService — loads all years of the current mandator (via MultiYearRepository) into an AccountingAnalysis (expenses, income, net, assets) for the Analyse page; queries run in memory
  • Strom page (Electricity, /electricity, under "Charts" in the menu) — grid and dialog (FluentDataGrid/ElectricityBillDialog) over IElectricityBillRepository's ElectricityBill records (one yearly NeoVac bill each: kWh/CHF for grid and PV, side costs; TotalKwh, PvShare, TotalChf, ChfPerKwh are computed); three Chart.js charts via ChartJsChart (stacked kWh, CHF/kWh lines, total CHF), filtered by the shared BillChartToolbar (BillChartFilter): grouped per bill, calendar year (default) or half-year (BillPeriod<T>.FromBills over IPeriodBill<T>; a bill reaching over several periods is spread evenly over its months and the page shows a note) and limited to a from/to year range (periods overlapping it are kept whole)
  • Wasser page (Water, /water, under "Charts" in the menu) — same layout as Strom over IWaterBillRepository's WaterBill records (warm/cold water m³ and CHF, base costs; TotalM3, WarmWaterShare, TotalChf are computed); two charts (stacked m³, total CHF) with the same BillChartToolbar
  • Wasser & Heizung page (WaterHeating, /water-heating, under "Charts" in the menu) — same layout for NeoVac bills where only per-mille shares are known, over IWaterHeatingBillRepository's WaterHeatingBill records: consumption (warm/cold m³, heat MWh) and ‰ shares from NeoVac, own water/heating costs in CHF from the property manager's statement; WaterHeatingBillDialog calls CalculateCosts, which stores the CHF parts (water split into base/consumption by ‰, consumption split by m³, warm water part of the heating), so AddShare can sum them per period; RoomHeatingChf is the rest of the heating. The dialog shows plausibility checks from WaterHeatingBillChecks (NeoVac ‰ vs. the optional ‰ of the property manager, optional meter readings continuing from the previous bill, implied property totals, prices per unit vs. the previous bill, flagged above ±25 %). Three charts (stacked m³, MWh, stacked CHF) and a guide image (water-heating-bill-guide.svg)

UI structure

Pages live in Schaad.Accounting.UI/Components/Pages/. Each page typically has a companion Dialogs/ subfolder with Fluent UI dialog components for CRUD operations. The app is hardcoded to the de-CH culture.

Key external dependencies

  • Microsoft.FluentUI.AspNetCore.Components — UI components (FluentDataGrid, FluentDialog, etc.)
  • Plotly.Blazor — charts on the older chart pages
  • BlazorMonaco — Monaco editor for the JSON editor page; loaded on demand by wwwroot/js/monaco.js instead of script tags in App.razor. Pages are interactive one by one, so NavigationManager.NavigateTo and menu links run enhanced navigation, which syncs <head> (removing Monaco's styles; monaco.js puts them back) and re-renders the page on the server. The editor therefore switches files in place and only rewrites the URL (wwwroot/js/url.js)
  • Chart.js 4 + chartjs-chart-treemap — charts on the Analyse page; vendored in wwwroot/lib/ (no CDN), wrapped by wwwroot/js/charts.js and ChartJsChart.razor; charts.js hides Monaco's global AMD define while loading them, otherwise the UMD bundles register as AMD modules and window.Chart stays undefined after visiting the JSON editor
  • Bootstrap 5 — only wwwroot/lib/bootstrap/dist/css/bootstrap.min.css (base element styles and a few utilities like text-danger); no Bootstrap JS
  • Schaad.Finance.dll / Schaad.Finance.Api.dll — proprietary DLLs for MT940/CAMT053 parsing and FX rate lookups (FixerIo API key in appsettings.Development.json)

Domain constants

ClassIds in Schaad.Accounting.Common defines the Swiss accounting chart-of-accounts classes: Activa=1, Passiva=2, Income=3, Expenses=4. These are the leading digit of an account number (accounts are 4-digit; Account.Class = Number / 1000).

Testing conventions

Tests live in Schaad.Accounting.Tests and use xUnit + NSubstitute (mocks) + Shouldly (assertions).

  • File and class name: <Subject>TestShould — one file per subject under test. Examples: ViewServiceTestShould.cs, TransactionRepositoryTestShould.cs, FormattingTestShould.cs.
  • Test method name: DoThisWhenThat — describes the behavior first, then the condition. Read together the class + method form a sentence:
    • ViewServiceTestShould.SumActivaAndPassivaTotalsSeparatelyWhenGettingBalanceView
    • TransactionRepositoryTestShould.ReturnNullWhenGettingUnknownTransactionId
  • Assertions: use Shouldly (value.ShouldBe(expected), list.ShouldBeEmpty(), x.ShouldBeNull(), list.ShouldContain(...), first.ShouldBeSameAs(second), etc.). Do not use xUnit Assert.*.

Example:

public class FormattingTestShould
{
    [Fact]
    public void RoundToTwoDecimalsWhenValueHasMorePrecision()
    {
        1.234m.ToFormattedString().ShouldBe("1.23");
    }
}

Repository tests that hit real file I/O use a temp directory via Path.GetTempPath() and clean up in IDisposable.Dispose. Pure service tests use NSubstitute mocks for every dependency and don't touch the filesystem.