rechenkistev0.1.2

Request flow

How Astro, htmx and Alpine.js share the work in one practice run.

Rechenkiste is a server-rendered Astro app (output: "server") on Cloudflare Workers. htmx and Alpine.js are bundled from npm and started in BaseLayout.astro; nothing loads from a CDN.

Layer Job in Rechenkiste
Astro Renders the pages, the API routes and – through the fragment renderer – every task, feedback and result fragment
htmx Posts answers and swaps the returned HTML into the page
Alpine.js Local UI state only: the grade and count tiles on the start page, the number pad, the character filter of the answer field
Tailwind CSS 4 Styling, via the Vite plugin

One practice run

Focus
One practice run, request by request
One practice run, request by requestThe start form creates the session with all tasks and redirects to /test, which renders the first task on the server. Each answer is an htmx POST to /api/test/answer: the route checks the submission against the session, validates it, advances the session and returns the rendered feedback fragment. The next task is fetched as a fragment from /api/test/task, automatically 600 ms after a correct answer or with the Next task button after a wrong one.loop[every task]1. Browser → Astro routes: POST /api/test/startPOST /api/test/start12. Astro routes → Session: store all tasksstore all tasks23. Astro routes → Browser: redirect /testredirect /test34. Browser → Astro routes: GET /testGET /test45. Astro routes → fragment-renderer: first taskfirst task56. Astro routes → Browser: pagepage67. Browser → Astro routes: hx-post /api/test/answerhx-post /api/test/answer78. Astro routes → Session: load, check taskload, check task89. Astro routes → Astro routes: validate, advancevalidate, advance910. Astro routes → Session: savesave1011. Astro routes → fragment-renderer: feedbackfeedback1112. Astro routes → Browser: fragment, HX-Triggerfragment, HX-Trigger1213. Browser → Astro routes: GET /api/test/taskGET /api/test/task1314. Astro routes → fragment-renderer: next tasknext task1415. Astro routes → Browser: fragmentfragment15Browser – htmxBrowserhtmxAstro routes – WorkerAstro routesWorkerSession – KVSessionKVfragment-renderer – Astro componentsfragment-rendererAstro components

Source: src/pages/api/test/start.ts, src/pages/test.astro, src/pages/api/test/answer.ts, src/pages/api/test/task.ts, src/services/task-renderer.ts

Show chart data
Data for One practice run, request by request
No.FromToMessageKindFragment
1BrowserAstro routesPOST /api/test/startcall
2Astro routesSessionstore all taskscall
3Astro routesBrowserredirect /testreply
4BrowserAstro routesGET /testcall
5Astro routesfragment-rendererfirst taskcall
6Astro routesBrowserpagereply
7BrowserAstro routeshx-post /api/test/answercallloop [every task]
8Astro routesSessionload, check taskcallloop [every task]
9Astro routesAstro routesvalidate, advancecallloop [every task]
10Astro routesSessionsavecallloop [every task]
11Astro routesfragment-rendererfeedbackcallloop [every task]
12Astro routesBrowserfragment, HX-Triggerreplyloop [every task]
13BrowserAstro routesGET /api/test/taskcallloop [every task]
14Astro routesfragment-renderernext taskcallloop [every task]
15Astro routesBrowserfragmentreplyloop [every task]
Focus
One practice run, request by request
One practice run, request by requestThe start form creates the session with all tasks and redirects to /test, which renders the first task on the server. Each answer is an htmx POST to /api/test/answer: the route checks the submission against the session, validates it, advances the session and returns the rendered feedback fragment. The next task is fetched as a fragment from /api/test/task, automatically 600 ms after a correct answer or with the Next task button after a wrong one.loop[every task]1. Browser → Astro routes: POST /api/test/startPOST /api/test/start12. Astro routes → Session: store all tasksstore all tasks23. Astro routes → Browser: redirect /testredirect /test34. Browser → Astro routes: GET /testGET /test45. Astro routes → fragment-renderer: first taskfirst task56. Astro routes → Browser: pagepage67. Browser → Astro routes: hx-post /api/test/answerhx-post /api/test/answer78. Astro routes → Session: load, check taskload, check task89. Astro routes → Astro routes: validate, advancevalidate, advance910. Astro routes → Session: savesave1011. Astro routes → fragment-renderer: feedbackfeedback1112. Astro routes → Browser: fragment, HX-Triggerfragment, HX-Trigger1213. Browser → Astro routes: GET /api/test/taskGET /api/test/task1314. Astro routes → fragment-renderer: next tasknext task1415. Astro routes → Browser: fragmentfragment15Browser – htmxBrowserhtmxAstro routes – WorkerAstro routesWorkerSession – KVSessionKVfragment-renderer – Astro componentsfragment-rendererAstro components

Source: src/pages/api/test/start.ts, src/pages/test.astro, src/pages/api/test/answer.ts, src/pages/api/test/task.ts, src/services/task-renderer.ts

Show chart data
Data for One practice run, request by request
No.FromToMessageKindFragment
1BrowserAstro routesPOST /api/test/startcall
2Astro routesSessionstore all taskscall
3Astro routesBrowserredirect /testreply
4BrowserAstro routesGET /testcall
5Astro routesfragment-rendererfirst taskcall
6Astro routesBrowserpagereply
7BrowserAstro routeshx-post /api/test/answercallloop [every task]
8Astro routesSessionload, check taskcallloop [every task]
9Astro routesAstro routesvalidate, advancecallloop [every task]
10Astro routesSessionsavecallloop [every task]
11Astro routesfragment-rendererfeedbackcallloop [every task]
12Astro routesBrowserfragment, HX-Triggerreplyloop [every task]
13BrowserAstro routesGET /api/test/taskcallloop [every task]
14Astro routesfragment-renderernext taskcallloop [every task]
15Astro routesBrowserfragmentreplyloop [every task]
  1. Start. The start page submits grade, task count and the two options to /api/test/start. The route creates a session with all tasks, stores it in the Astro session (KV) and redirects to /test.

  2. First task. test.astro loads the session and renders the current task on the server with renderTaskFragment() – the same function the API routes use.

  3. Answer. The answer form carries htmx attributes:

    <form
      id="answer-form"
      hx-post="/api/test/answer"
      hx-target="#feedback-container"
      hx-swap="innerHTML"
      hx-disabled-elt="find button[type='submit']"
    >

    /api/test/answer checks that the submission belongs to the current session and task (otherwise 409), validates the answer with the task’s own rules, advances the session and returns the rendered feedback fragment with the header HX-Trigger: feedbackShown.

  4. Next task. After a correct answer the feedback waits 600 ms and fetches /api/test/task into #task-container via htmx.ajax. After a wrong answer the child reads the hint and presses Next task, an hx-get to the same route.

  5. Result. When the run is complete, the feedback leads to /ergebnis, which renders the result fragment: score, a row of stamps and every task with both answers.

Fragment and page counter

The footer shows F:n P:n – fragment loads against page loads in the current session. It is refreshed by htmx from /api/test/counter whenever a task or feedback arrives, and shows how many requests of a run were answered with a fragment instead of a full page.

Edit this page on GitHub · Docs for v0.1.2