Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions docs/interactive-learning-blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# General-purpose learning blocks

Eight portable canvas renderers that any course can use, from cloud architecture to fitness, sales or finance. Each one is a ```` ```canvas ```` fence in the chapter: plain YAML (or JSON) data, no JSX, no code. The chapter is stored in the database as text, so every block is stored as code, never as a picture.

Preview them all at `/zz-learning-blocks` (dev page, no login).

| Renderer | Use it to | Interaction |
| --- | --- | --- |
| `architecture` | Show a system: parts, arrows, networks inside networks | Tap a part for details, drag to move, moving traffic dots |
| `chart` | Show data as a pie, bar or line chart | View only, or guess the hidden values, then reveal |
| `guess-reveal` | Make the learner commit to a number before the answer | Slider, lock, then see the gap |
| `scale-picker` | Teach "how much": tone, effort, detail, risk | Explore each point, then pick the best one for a situation |
| `log-explorer` | Practise finding the cause in a log | Filter by level, search, tap the line, check |
| `command-explainer` | Explain a command part by part | Tap a part, arrow keys, "Explain all" |
| `role-play` | Practise a conversation (customer, manager, patient) | Branching chat, read aloud, answer by voice |
| `self-check-cards` | Recall practice | Flip, "I knew it" or "Not yet", review the misses |

The step-by-step diagram is not a new renderer: a ```` ```flow ```` fence with a `packet:` line already steps through with Back and Next (see `diagram-components-plan.md`).

## Rules that apply to every block

- `title` and `limits` are required. `limits` says what the picture leaves out, in one or two sentences.
- Publishing (`courses:check`) refuses an unknown `renderer` or a missing `title` or `limits`.
- The reader checks the data against the renderer's schema and its cross-checks (for example, "an arrow points to a part that does not exist"). Bad data shows a quiet note instead of a broken block, and the problems are listed in the browser console in development.
- Every block works at 375 px, in light and dark mode, with the keyboard, and with reduced motion.
- A wrong answer is amber, never red.

## architecture

AI or an author writes the system as data. The reader lays it out left to right, or top to bottom when the panel is narrow (a phone).

```canvas
renderer: architecture
title: Web app with a load balancer
limits: One region only. It leaves out DNS, backups and monitoring.
nodes:
- { id: users, type: client, label: Users }
- { id: lb, type: balancer, label: Load balancer, tech: ALB, desc: Spreads requests across the app servers. }
- { id: app1, type: compute, label: App server 1, tech: Node.js }
- { id: app2, type: compute, label: App server 2, tech: Node.js }
- { id: db, type: database, label: Managed database, tech: PostgreSQL }
- { id: mail, type: external, label: Email service }
edges:
- { from: users, to: lb, label: HTTPS }
- { from: lb, to: app1 }
- { from: lb, to: app2 }
- { from: app1, to: db, label: SQL }
- { from: app2, to: db, label: SQL }
- { from: app2, to: mail }
groups:
- { id: private, label: Private subnet, members: [app1, app2] }
- { id: vpc, label: VPC, members: [lb, private, db] }
```

- `type`: `client`, `dns`, `cdn`, `firewall`, `limiter`, `balancer`, `gateway`, `compute`, `function`, `worker`, `cache`, `database`, `nosql`, `search`, `queue`, `stream`, `storage`, or `external`. The icons are the design lab's icons, so diagrams and labs match.
- Limits: 2 to 30 parts, up to 60 arrows, up to 12 groups. Names up to 40 characters, arrow labels up to 24.
- Groups can hold groups. A part can be in only one group.
- `x` and `y` (grid units: column and row) fix a part's place. An author can drag parts in the reader, then press "Copy code" to get the same diagram with `x` and `y` filled in.
- Cards grow to fit their names, so text never leaves a card.

## chart

```canvas
renderer: chart
title: Online sales catch up
limits: Made-up shop data. One year only.
chart: line # pie | bar | line
mode: guess # view (default) | guess
prefix: "$"
unit: k
categories: [Jan, Feb, Mar, Apr, May, Jun, Jul, Aug]
series:
- { id: online, label: Online, values: [42, 45, 51, 48, 56, 61, 64, 70] }
- { id: store, label: In store, values: [58, 55, 57, 60, 59, 62, 60, 58] }
guess: { series: online, from: 6 }
answerNote: Online kept growing and passed in-store sales in July.
source: Example data
```

- Pie: `slices: [{ id, label, value }]` (2 to 6). In guess mode the learner splits 100%.
- Bar: `categories` (2 to 8) and `series` (1 to 3). Line: `categories` (3 to 24) and `series` (1 to 3).
- Guess mode hides values from `guess.from` and asks the learner to set them with sliders or by dragging. `tolerance` sets what counts as close.
- Colours follow a fixed order, there is a legend for 2 or more series, and a hidden table gives the values to screen readers.

## guess-reveal

```canvas
renderer: guess-reveal
title: Guess the number
limits: Rounded numbers. A real line rarely reaches its full speed.
questions:
- question: "You download a 1 GB file on a 100 Mbit/s line. How many seconds, at best?"
min: 0
max: 300
step: 5
unit: " s"
answer: 80
tolerance: 10
explanation: "1 GB is 8,000 megabits. 8,000 divided by 100 is 80 seconds."
source: Example
```

1 to 6 questions. The slider starts at `min`, so the learner has to move it. A single question shows no counter.

## scale-picker

```canvas
renderer: scale-picker
title: Message tone
limits: Two situations only. Real readers vary.
ends: [More blunt, More polite]
frame: Your message
keys: { good: Clear ask, weak: Hedging, bad: Harsh }
points:
- { label: Blunt, text: "[[bad:Release is late. Not my problem.]]", result: They feel blamed., mood: bad }
- { label: Direct, text: "It moves to Thursday. [[good:Can you tell the client?]]", result: Fast and clear., mood: good }
- { label: Over-polite, text: "[[weak:So sorry to bother you,]] maybe a delay?", result: They are not sure what to do., mood: weak }
situations:
- { label: To a teammate, prompt: Your teammate needs to know the release is late. How do you say it?, best: [1], why: A teammate wants the facts and the ask. }
```

3 to 7 points, 1 to 6 situations. `[[good:...]]`, `[[weak:...]]` and `[[bad:...]]` mark words in an example. `code: true` shows the example in a monospace panel (for commit messages or config).

## log-explorer

```canvas
renderer: log-explorer
title: Find the first failure
limits: A real log has thousands of lines.
lines:
- { id: l1, time: "14:09:41", level: info, source: deploy, text: checkout v2.3 rolled out }
- { id: l2, time: "14:09:58", level: error, source: checkout, text: "db pool exhausted: 20 of 20 in use" }
- { id: l3, time: "14:10:02", level: error, source: web, text: POST /checkout 500 5012ms }
question: { prompt: Which line shows the real cause?, answer: [l2], why: The pool ran out first. The 500s come after it. }
```

3 to 80 lines; `level` is `debug`, `info`, `warn` or `error`; 1 to 3 answer lines.

## command-explainer

```canvas
renderer: command-explainer
title: Read a copy command
limits: Only the common flags.
prompt: "$"
parts:
- { text: cp, kind: command, explain: Copy files. }
- { text: "-r", kind: flag, explain: Copy folders and everything inside them. }
- { text: notes/, kind: path, explain: The folder to copy. }
```

`kind`: `command`, `flag`, `argument`, `pipe`, `path` or `other`. `tight: true` joins a part to the one before it with no space. `examples` adds more commands behind a switcher; `output` shows sample output.

## role-play

```canvas
renderer: role-play
title: Calm an upset customer
limits: A real customer does not pick from three lines.
character: { name: Sara Khan, role: Customer }
learnerRole: You, the support agent
goal: Keep Sara as a customer.
start: open
nodes:
open:
says: My order is two weeks late.
choices:
- { text: I am sorry. Let me check it now., next: happy, tone: good, feedback: You own the problem. }
- { text: Delays happen., next: lost, tone: weak, feedback: This brushes her off. }
happy: { says: Thank you., ending: { verdict: Customer kept, tone: good, summary: You said sorry, then acted. } }
lost: { says: I want to cancel., ending: { verdict: Customer lost, tone: warn, summary: She felt ignored. } }
```

2 to 30 nodes. A node has 2 to 4 `choices` or an `ending`. The check refuses unknown `next` ids, unreachable nodes and dead ends. "Read aloud" uses the browser's speech; "Answer by voice" uses speech recognition and picks the closest reply by word overlap. Both appear only in browsers that support them. No AI call is made.

## self-check-cards

```canvas
renderer: self-check-cards
title: HTTP status codes
limits: Recall on a card is not the same as using it at work.
deckLabel: Status codes
cards:
- { id: "200", front: What does 200 mean?, back: OK. The request worked. }
- { id: "404", front: What does 404 mean?, back: Not found., hint: The page is missing. }
```

2 to 20 cards. At the end the learner can review only the "Not yet" cards.

## Where the code is

- Model (schema, checks, pure functions): `packages/learning-ui/src/canvas/models/<renderer>.ts`
- Component: `packages/learning-ui/src/canvas/primitives/<renderer>.tsx`, with a spec next to it (`<renderer>.spec.md`)
- Tests: `frontend/tests/unit/canvas/<renderer>.test.ts`
- Registration: `PORTABLE_CANVAS_RENDERERS` in `models/portable.ts`, the switch in `canvas/InteractiveCanvas.tsx`, and `PORTABLE_CANVAS_RENDERER_NAMES` in `server/src/shared/mdx/canvas-tags.ts` (run `pnpm sync-shared` in `server/`).
171 changes: 171 additions & 0 deletions frontend/src/app/zz-learning-blocks/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import { ChapterMdx } from "@/mdx/compile";

// Dev-only specimen sheet of the general-purpose canvas renderers, like
// /zz-diagram-gallery. Public, no auth, no data. Each example is a ```canvas
// fence that goes through the real chapter pipeline (transformVisualFences,
// then <InteractiveCanvas renderer=...>). See docs/interactive-learning-blocks.md.

const T = "```";

const SOURCE = `## Architecture

${T}canvas
renderer: architecture
title: Web app with a load balancer
limits: One region only. It leaves out DNS, backups and monitoring.
nodes:
- { id: users, type: client, label: Users }
- { id: cdn, type: cdn, label: CDN, tech: CloudFront, desc: Serves images and scripts from a server near the user. }
- { id: lb, type: balancer, label: Load balancer, tech: ALB, desc: Spreads requests across the app servers and skips one that is down. }
- { id: app1, type: compute, label: App server 1, tech: Node.js }
- { id: app2, type: compute, label: App server 2, tech: Node.js }
- { id: cache, type: cache, label: Cache, tech: Redis }
- { id: db, type: database, label: Managed database, tech: PostgreSQL, desc: Keeps users and orders. One writer, daily backups. }
- { id: mail, type: external, label: Email service }
edges:
- { from: users, to: cdn, label: HTTPS }
- { from: cdn, to: lb, label: cache miss }
- { from: lb, to: app1 }
- { from: lb, to: app2 }
- { from: app1, to: cache }
- { from: app2, to: cache }
- { from: app1, to: db, label: SQL }
- { from: app2, to: db, label: SQL }
- { from: app2, to: mail }
groups:
- { id: private, label: Private subnet, members: [app1, app2] }
- { id: data, label: Data subnet, members: [cache, db] }
- { id: vpc, label: VPC 10.0.0.0/16, members: [lb, private, data] }
${T}

## Chart

${T}canvas
renderer: chart
title: Online sales catch up
limits: Made-up shop data. One year only.
chart: line
mode: guess
prefix: "$"
unit: k
categories: [Jan, Feb, Mar, Apr, May, Jun, Jul, Aug]
series:
- { id: online, label: Online, values: [42, 45, 51, 48, 56, 61, 64, 70] }
- { id: store, label: In store, values: [58, 55, 57, 60, 59, 62, 60, 58] }
guess: { series: online, from: 6 }
answerNote: Online kept growing and passed in-store sales in July.
source: Example data
${T}

${T}canvas
renderer: chart
title: Where the monthly budget goes
limits: One example budget. Your split depends on where you live.
chart: pie
unit: "%"
slices:
- { id: needs, label: Needs, value: 50 }
- { id: wants, label: Wants, value: 30 }
- { id: save, label: Savings, value: 20 }
${T}

## Guess, then reveal

${T}canvas
renderer: guess-reveal
title: Guess the number
limits: Rounded numbers. A real line rarely reaches its full speed.
questions:
- { question: "You download a 1 GB file on a 100 Mbit/s line. How many seconds, at best?", min: 0, max: 300, step: 5, unit: " s", answer: 80, tolerance: 10, explanation: "1 GB is 8,000 megabits. 8,000 divided by 100 is 80 seconds." }
${T}

## Scale picker

${T}canvas
renderer: scale-picker
title: Message tone
limits: Two situations only. Real readers vary.
ends: [More blunt, More polite]
frame: Your message
keys: { good: Clear ask, weak: Hedging, bad: Harsh }
points:
- { label: Blunt, text: "[[bad:Release is late. Not my problem.]]", result: They feel blamed., mood: bad }
- { label: Direct, text: "It moves to Thursday. [[good:Can you tell the client?]]", result: Fast and clear., mood: good }
- { label: Over-polite, text: "[[weak:So sorry to bother you,]] maybe a delay?", result: They are not sure what to do., mood: weak }
situations:
- { label: To a teammate, prompt: Your teammate needs to know the release is late. How do you say it?, best: [1], why: A teammate wants the facts and the ask. }
${T}

## Log explorer

${T}canvas
renderer: log-explorer
title: Find the first failure
limits: A real log has thousands of lines.
lines:
- {id: l1, time: "14:09:41", level: info, source: deploy, text: checkout v2.3 rolled out}
- {id: l2, time: "14:09:50", level: debug, source: checkout, text: pool size 20}
- {id: l3, time: "14:09:58", level: error, source: checkout, text: "db pool exhausted: 20 of 20 in use"}
- {id: l4, time: "14:10:02", level: error, source: web, text: POST /checkout 500 5012ms}
- {id: l5, time: "14:10:03", level: warn, source: web, text: retrying request}
question: {prompt: Which line shows the real cause?, answer: [l3], why: The pool ran out first. The 500 errors come after it.}
${T}

## Command explainer

${T}canvas
renderer: command-explainer
title: Read a copy command
limits: Only the common flags.
prompt: "$"
parts:
- {text: cp, kind: command, explain: Copy files.}
- {text: "-r", kind: flag, explain: Copy folders and everything inside them.}
- {text: notes/, kind: path, explain: The folder to copy.}
- {text: backup/, kind: path, explain: Where the copy goes.}
${T}

## Role-play

${T}canvas
renderer: role-play
title: Calm an upset customer
limits: A real customer does not pick from three lines.
character: { name: Sara Khan, role: Customer }
learnerRole: You, the support agent
goal: Keep Sara as a customer.
start: open
nodes:
open:
says: My order is two weeks late.
choices:
- { text: I am sorry. Let me check it now., next: happy, tone: good, feedback: You own the problem. }
- { text: Delays happen., next: lost, tone: weak, feedback: This brushes her off. }
happy: { says: Thank you., ending: { verdict: Customer kept, tone: good, summary: You said sorry, then acted. } }
lost: { says: I want to cancel., ending: { verdict: Customer lost, tone: warn, summary: She felt ignored. } }
${T}

## Self-check cards

${T}canvas
renderer: self-check-cards
title: HTTP status codes
limits: Recall on a card is not the same as using it at work.
deckLabel: Status codes
cards:
- { id: "200", front: What does 200 mean?, back: OK. The request worked. }
- { id: "404", front: What does 404 mean?, back: Not found., hint: The page is missing. }
- { id: "500", front: What does 500 mean?, back: Server error. The server failed. }
${T}
`;

export default function LearningBlocksGalleryPage() {
return (
<main className="mx-auto max-w-3xl px-4 py-10">
<h1 className="text-2xl font-semibold">General learning blocks</h1>
<div className="mt-6">
<ChapterMdx source={SOURCE} />
</div>
</main>
);
}
8 changes: 8 additions & 0 deletions frontend/src/shared/mdx/canvas-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export const PORTABLE_CANVAS_RENDERER_NAMES = [
"phrase-fixer",
"budget-stack",
"slot-card",
"chart",
"scale-picker",
"guess-reveal",
"log-explorer",
"command-explainer",
"role-play",
"self-check-cards",
"architecture",
] as const;

export function isPortableCanvasRendererName(value: unknown): boolean {
Expand Down
Loading
Loading