Examples
The examples/ folder is a staircase. Start near the bottom, change something small, and climb when you are curious.
The staircase
Each folder has a short README. Paths below are from the repository root.
| Example | What you will learn |
|---|---|
examples/01_hello_world | The smallest selm program. Great for checking that the CLI works. |
examples/02_counter | A tiny HTTP server with a supervised counter. Plain text plus HTML from the ui package. No Postgres. |
examples/03_todo_app | Full-stack: multi-page SPA, Cowboy API, Postgres, cookies, row security, and migrations. |
examples/04_conduit | A larger RealWorld-style app split into API and web packages. |
examples/05_chat | A websocket lobby. The channel module is shared by the BEAM process and the SPA. No database. |
examples/06_atomvm_hello | Hello on AtomVM: selm on a microcontroller board. |
examples/07_mcp_search | An MCP client with a local fake search server and HTTP search. See AI. |
examples/08_acp_agent | A browser workspace for Cursor and Claude Code over ACP. No database. See AI. |
examples/09_webgl_triangle | A JS WebGL triangle with [glsl| … |] and elm-explorations/webgl. |
examples/10_random | Dice on both sides: browser Random and BEAM Random (generate / step) over HTTP. |
examples/11_hydrate | Same TEA view SSR into #app with Server.page, then JS Browser.element hydrate. |
examples/12_selm_syntax | Language surface samples used by the docs and compiler checks. |
examples/13_csv_books | HTTP CSV round-trip: multipart upload streams through Csv.decode into Postgres. |
examples/14_ws_books_upload | Websocket row / binary streaming with StreamUpload.handleIn: chunked Ups (including Bytes), immediate Error, final Finished. |
examples/15_jobs | Durable Jobs + job module (enqueue over HTTP, SQLite selm_jobs, retries, cron). |
examples/16_svg | JS Svg mark from the first-party selm/svg hard stack. Also a Language tour step. |
examples/17_time_format | Live Time.format clock + Duration. Also a Language tour step. |
examples/18_email | Verification tokens with Email and a welcome message rendered by Email.Mjml. |
examples/19_service_worker | Worker.Service register plus Cache Storage (cachePut / match / delete / clear). |
examples/20_cloudflare_worker | Fetch.Handler ES module for Cloudflare Workers (wrangler dev / node smoke.mjs). |
examples/21_durable_counter | Workers Server.application: gate TEA, reply-Subject call / askMap, nests / startChild / Temporary, alarms, Storage / Env, SQLite, forward / withFetch, derived durable codecs, selmMailbox. |
examples/22_durable_chat | Workers Channels: Server.Socket.supervised + Server.Channel.define with explicit JSON codecs on hibernatable Durable Object WebSockets (contrast BEAM 05_chat). |
examples/23_mcp_server | An MCP server: a Platform.worker echoes tools/call on stdin/stdout. See AI. |
examples/ui | A shared .selm view package used by both BEAM SSR and the JS SPA. |
Commands to try
Todo (needs local Postgres):
cd examples/03_todo_app
selm serveCounter (no database):
cd examples/02_counter
selm runSvg or Time.format (browser):
cd examples/16_svg
selm devDurable Objects (Workers, no Wrangler account needed for smoke):
cd examples/21_durable_counter
selm make && selm wrangler check && node smoke.mjs
cd examples/22_durable_chat
selm make && node smoke.mjs