PackyTrace Syntax Exercises¶
A hands-on workbook for the languages and patterns used in this repository. Examples marked “illustrative” teach a concept but are not copied from repository code and may omit setup required by a standalone playground.
How to use this¶
Each file is a sequence of small exercises. Every exercise has the same shape:
- Concept: one or two lines on what you are about to practice.
- Example: annotated code to compile or run where the exercise supplies enough context.
- Your exercise: a task. Write the answer yourself first.
- Solution: a collapsible '' block. Open it after you try.
Don't skip the "write it yourself" step. Reading a solution feels like learning; producing the syntax from a blank page is learning.
Suggested order¶
| # | File | Language / topic | Mirrors |
|---|---|---|---|
| 01 | typescript-types.md | TS: interfaces, unions, literals, generics, narrowing | client .../domain/types.ts |
| 02 | typescript-functions.md | TS: pure functions, immutability, array methods | domain/expiry.ts, verdict/rules.ts |
| 03 | typescript-ports-and-di.md | TS: ports as interfaces, dependency injection, error classes | identity-service |
| 04 | go-types-and-structs.md | Go: structs, methods, receivers, zero values | passport-service/domain |
| 05 | go-interfaces-and-errors.md | Go: interfaces, sentinel errors, wrapping, errors.Is | passport-service |
| 06 | go-usecases-hexagonal.md | Go: use-case structs, injected ports, degradation | internal/passport/resolve_scan.go |
| 07 | svelte5-runes.md | Svelte 5: $props / $state / $derived, blocks | 'lib/components/**' |
| 08 | architecture-placement.md | Where does this code go? domain vs application vs ports vs adapters | whole repo |
01–03 are TypeScript, 04–06 are Go, 07 is the Svelte client, 08 is language-agnostic architecture judgement (the layering this whole repo enforces).
Setup if you want to actually run things¶
- TypeScript snippets: paste into the TS playground: fastest feedback, no install. Or npx tsx scratch.ts in a service folder.
- Go snippets: paste into the Go playground, or make a scratch/main.go and go run ./scratch.
- Svelte snippets: the Svelte 5 playground runs runes directly.
Keep your scratch files out of the services' src/ trees so the linters and make check never see them.