feat(server): web server, interface shell, demo mode and Docker image (refs #11 #12 #13 #14 #15 #16 #17)
ci / test (postgres) (push) Successful in 2m22s
ci / test (sqlite) (push) Failing after 2m27s
ci / image (push) Skipped

Phase 1 completed on top of the library foundations:
- Server: startup state machine (config, first run, database down, schema,
  identity, ready) with an error page that retries by itself; the configured
  database is the only one ever opened, and a vanished SQLite file is never
  recreated. REST API and status WebSocket; session cookie auth, CSRF on
  every form and write call; desktop and demo answer only the computer itself.
- Interface: static Blazor rendering with plain forms (no interactive
  runtime), menu, top bar and phone bottom bar as in the mockups, light and
  dark themes with appendix C tokens and a contrast test, Panoramica, Diario,
  Rischio, Impostazioni; service pages for sign-in, first access, desktop
  first run and the database error page with its choices.
- Demo mode (tasks seed-demo): appendix F in a database of its own under the
  temp folder, frozen clock, never touches the configured installation.
- Docker: entrypoint gives /data to PUID:PGID and drops root with setpriv,
  HEALTHCHECK through bash /dev/tcp; proven with SQLite, PostgreSQL, a wrong
  configuration and a database that goes away and comes back.
- tasks screenshots drives the installed Edge/Chrome through DevTools for
  exact 1440 and 390 pixel shots; anubis db export|import on the command line.

Fixes from the independent review: return paths without control characters,
Host check against DNS rebinding, attempt limit counted before the check and
also on the error-page password, one-use TOTP codes and a code to switch the
second factor off, error-page choices serialized with the startup loop,
identity checked before migrating, restore restarts with "Ferma tutto" on,
damaged archives reported instead of crashing. Running the server tests on
PostgreSQL exposed pages rendered before their data arrived; data-loading
components now load first (LoadedComponent).

Decisions in ADR 0007. Tests: 100 on SQLite and on PostgreSQL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-10 12:40:15 +01:00
1 parent 53ca01b7c3
commit f9d71559e8
71 files changed
+5853 -80

No files matched your search

@@ -0,0 +1,102 @@
@inject ShellData Shell
@* Equity against the "senza bot" comparison (SPEC 13.4): one scale, 2 px lines, faint grid, direct label on the last
point, legend, and the same numbers in a table. Lines are SVG stretched to the box; texts and the end point are
HTML placed in percent, so nothing gets distorted at any width. *@
@if (Points.Count >= 2)
{
var values = Points.Select(p => Shell.Convert(p.Equity, Currency)).ToList();
var bench = Points.Select(p => p.Benchmark is { } b ? Shell.Convert(b, Currency) : (decimal?)null).ToList();
var all = values.Concat(bench.OfType<decimal>()).ToList();
var (lo, hi, step) = Scale(all.Min(), all.Max());
double X(int i) => i * 1000.0 / (Points.Count - 1);
double Y(decimal v) => (double)((hi - v) / (hi - lo)) * 1000.0;
string Line(IEnumerable<(int I, decimal V)> pts) => string.Join(" ", pts.Select(p => Fmt(X(p.I)) + "," + Fmt(Y(p.V))));
var equityLine = Line(values.Select((v, i) => (i, v)));
var benchLine = Line(bench.Select((v, i) => (i, v)).Where(p => p.v is not null).Select(p => (p.i, p.v!.Value)));
var last = values[^1];
<figure class="chart" aria-label="Patrimonio nel tempo, con il bot e senza">
<div class="chart-box">
<div class="chart-axis" aria-hidden="true">
@for (var t = lo; t <= hi; t += step)
{
<span style="top:@Pct(Y(t) / 10)">@Format.Number(t)</span>
}
</div>
<div class="chart-plot">
<svg viewBox="0 0 1000 1000" preserveAspectRatio="none" aria-hidden="true" focusable="false">
@for (var t = lo; t <= hi; t += step)
{
<line class="grid" x1="0" x2="1000" y1="@Fmt(Y(t))" y2="@Fmt(Y(t))" vector-effect="non-scaling-stroke" />
}
<polygon class="area" points="0,1000 @equityLine 1000,1000" />
@if (benchLine.Length > 0)
{
<polyline class="bench" points="@benchLine" vector-effect="non-scaling-stroke" />
}
<polyline class="equity" points="@equityLine" vector-effect="non-scaling-stroke" />
</svg>
@if (bench[^1] is { } lastBench)
{
// Two labels never overlap: the lower one moves down when they are closer than one line.
var gap = Math.Abs(Y(last) - Y(lastBench)) / 10;
var benchTop = gap < 7 ? Y(last) / 10 + (Y(lastBench) >= Y(last) ? 7 : -7) : Y(lastBench) / 10;
<span class="end-dot bench-dot" style="left:100%;top:@Pct(Y(lastBench) / 10)"></span>
<span class="end-label bench-label" style="top:@Pct(benchTop)">@Shell.Money(Points[^1].Benchmark!.Value, Currency, decimals: 0)</span>
}
<span class="end-dot" style="left:100%;top:@Pct(Y(last) / 10)"></span>
<span class="end-label" style="top:@Pct(Y(last) / 10)">@Shell.Money(Points[^1].Equity, Currency, decimals: 0)</span>
</div>
</div>
<figcaption class="legend">
<span class="key key-equity">Con Anubis</span>
@if (benchLine.Length > 0)
{
<span class="key key-bench">Senza bot: Bitcoin e S&amp;P 500 comprati e tenuti</span>
}
</figcaption>
<details class="chart-table">
<summary>Vedi i numeri in una tabella</summary>
<div class="table-wrap">
<table class="table">
<thead><tr><th scope="col">Giorno</th><th scope="col" class="num">Con il bot</th><th scope="col" class="num">Senza bot</th></tr></thead>
<tbody>
@foreach (var p in Points.AsEnumerable().Reverse())
{
<tr><td>@Format.LongDate(p.Day)</td><td class="num">@Shell.Money(p.Equity, Currency)</td><td class="num">@(p.Benchmark is { } b ? Shell.Money(b, Currency) : "—")</td></tr>
}
</tbody>
</table>
</div>
</details>
</figure>
}
@code {
[Parameter, EditorRequired]
public IReadOnlyList<EquityPoint> Points { get; set; } = [];
[Parameter]
public string Currency { get; set; } = "EUR";
private static string Fmt(double v) => v.ToString("0.##", CultureInfo.InvariantCulture);
private static string Pct(double v) => v.ToString("0.###", CultureInfo.InvariantCulture) + "%";
// Round steps (1, 2, 2.5, 3, 5 times a power of ten) giving three to five grid lines.
internal static (decimal Lo, decimal Hi, decimal Step) Scale(decimal min, decimal max)
{
if (max <= min)
{
max = min + 1;
}
var raw = (double)(max - min) / 4;
var power = Math.Pow(10, Math.Floor(Math.Log10(raw)));
var step = new[] { 1, 2, 2.5, 3, 5, 10 }.Select(m => m * power).First(s => s >= raw);
var stepValue = (decimal)step;
var lo = Math.Floor(min / stepValue) * stepValue;
var hi = Math.Ceiling(max / stepValue) * stepValue;
return (lo, hi == lo ? lo + stepValue : hi, stepValue);
}
}