Skip to content

feat(web): v0.1 UI — calendar heatmap, day detail, trade detail#5

Merged
SwathiMystery merged 3 commits intomainfrom
feat/web-ui
Apr 21, 2026
Merged

feat(web): v0.1 UI — calendar heatmap, day detail, trade detail#5
SwathiMystery merged 3 commits intomainfrom
feat/web-ui

Conversation

@SwathiMystery
Copy link
Copy Markdown
Contributor

What

First web UI for khata. FastAPI + Jinja2 + HTMX. No client JS framework. Single stylesheet with dark mode via prefers-color-scheme. Logo-matched amber/indigo palette.

Pages

route purpose
GET / redirect to the current month's calendar
GET /calendar/{year}/{month} month grid, P&L-coloured days, Tue/Thu expiry markers, month-level totals, prev/next nav
GET /day/{YYYY-MM-DD} trade table, summary strip (trades/wins/losses/fees), inline daily reflection editor
GET /trade/{id} trade meta, executions/fills table, tag chips with add/remove, note editor

HTMX partials

route purpose
POST /notes/trade/{id} save trade note on blur, returns updated note block
POST /notes/day/{YYYY-MM-DD} save daily note on blur
POST /tags/trade/{id} add tag (kind: psych/setup/mistake/custom), returns tag list
DELETE /tags/trade/{id}/{tag} remove tag, returns tag list

CLI

khata web                                # 127.0.0.1:8000, reload on
khata web --host 0.0.0.0 --port 9000     # LAN-reachable
khata web --no-reload                    # production/container

Tests

12 new smoke tests via fastapi.testclient.TestClient. Covers every route, every HTMX round-trip, and edge cases (invalid date, missing trade, empty day). Full suite: 34/34 green.

Notes

  • Schema untouched. Reads-only against existing tables (trades, executions, trade_legs, notes, tags, trade_tags).
  • HTMX via unpkg CDN — comment in base.html documents vendoring option for air-gapped installs.
  • FastAPI's Depends() idiom trips ruff's B008 on import-time function calls. Added a per-file ignore only for khata/web/main.py — doesn't affect the rest of the codebase.
  • datetime.utcnow() replaced with timezone-aware equivalent for Python 3.12+ deprecation.

Verification

Ran against a live Dhan account (103 executions, 18 trades from my real sync):

  • Calendar shows the month with wins/losses correctly coloured, Tue/Thu expiry dots visible
  • Day view lists each trade with IST time, entry/exit, direction badge, links to trade detail
  • Trade detail shows avg entry/exit, fees, duration; daily note + tag add persists across refresh
  • HTMX round-trips completed in ~5ms per op

Checklist

  • 12 new tests, all green (34 total)
  • uv run ruff check khata tests clean (with scoped B008 allowance)
  • uv run ruff format khata tests applied
  • Docs: CLI help is self-documenting; ROADMAP.md v0.1 scope matches
  • No schema change

Adds the first web UI for khata: FastAPI + Jinja2 + HTMX, zero JS
framework, single stylesheet, dark-mode via prefers-color-scheme.

Pages
- GET /                          → redirect to current month calendar
- GET /calendar/{year}/{month}   → month grid, P&L-coloured days,
                                   Tue/Thu expiry markers, prev/next nav
- GET /day/{YYYY-MM-DD}          → day header, summary strip, trade
                                   table, inline daily reflection
- GET /trade/{id}                → trade meta, executions/fills, tag
                                   chips with add/remove, note editor

HTMX partials (no client JS)
- POST /notes/trade/{id}         → save trade note on blur
- POST /notes/day/{YYYY-MM-DD}   → save daily note on blur
- POST /tags/trade/{id}          → add tag (kind: psych/setup/mistake/custom)
- DELETE /tags/trade/{id}/{tag}  → remove tag

CLI
- khata web [--host 127.0.0.1] [--port 8000] [--reload/--no-reload]
  Defaults to localhost-only and reload-on for dev.

Tests
- 12 new smoke tests via FastAPI TestClient covering every route, HTMX
  round-trip, and edge cases (invalid date, missing trade, empty day).
  34/34 green overall.

Notes
- Schema untouched; only new reads on existing tables.
- HTMX loaded via unpkg CDN; comment in base.html notes vendoring option
  for offline installs.
- FastAPI's Depends() in parameter defaults is idiomatic — added per-file
  ruff ignore for B008 in khata/web/main.py only.
- `datetime.utcnow()` replaced with timezone-aware equivalent for 3.12+.

Verified against live Dhan data: 103 executions, 18 trades, calendar
heatmap coloured correctly, day view links to trade detail, daily note
save+reload roundtrip, tag add+remove persists.
@SwathiMystery SwathiMystery merged commit bd531e1 into main Apr 21, 2026
7 checks passed
@SwathiMystery SwathiMystery deleted the feat/web-ui branch April 21, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant