The ecosystem
Packages: Roc modules and components for any Roc Solid app
A package is a directory of Roc modules, often with components, added to an app with one line in its header. Use one for what the platforms leave out: charts, form checks, translations, a job queue, email, an admin for your tables. Some packages are also plugins, which add tables, background work or scripts to the server. Twenty-six so far, each with a page here.
The packages#
Grouped by where they work: in the page, on the server, and beside the app (tools and monitoring).
Pages
- ChartsEight kinds of chart that glide to their data, styled by CSS
- FormsA form's rules written once, checked as it is typed and at the endpoint
- MarkdownCommonMark in Roc, a <Markdown> component, and typed frontmatter
- IntlNumbers, dates and translated messages, as each locale writes them
- Virtual listsLists of any length that render only the rows that show
- VideoVideos made of your components, played in the page or rendered to MP4 and WebM
- QR codesQR codes made in plain Roc, drawn as SVG by a component that follows its text
- PresenceWho is here, who is typing, and live cursors
- AudioSound files from a handler, played by the plugin's script
- VibrateThe phone's vibration motor from a handler, in a browser and on Android
- LocalSignals that keep themselves on the device, in a browser and on Android and iOS
Server
- AuthSign-in by a mailed link or at a provider, sessions, two-factor codes, roles and your users: a plugin
- StripeSubscriptions through Stripe's Checkout, kept in step by its webhooks, and a billing page of your own: a plugin
- AIClaude from the server: answers streamed to a page, typed answers, tools, and teams of agents: a plugin
- ChatChat platforms behind one interface: a bot's handler written once
- SlackA Slack bot over Socket Mode or the Events API, answered by your handler: a plugin
- Jobs and cronWork that runs later, and again, on a schedule too: a plugin
- EmailEmail over SMTP, or a dev mailbox while you develop: a plugin
- PushWeb Push notifications: a button that subscribes, and jobs that send: a plugin
- StorageFiles in S3, beside the server, or in memory
- WebSocketA client for servers that keep a connection open: Slack's Socket Mode, Discord's Gateway, a feed
- GuardRate limits, feature flags and request guards, as middleware
- CryptoSHA-256, SHA-1, HMAC, HKDF, Base64, Base32, hex and UUIDs, in Roc
Tools
- AdminA Django-style admin for your database's tables
- TestingFind things in a page by role, name and label, from Roc and Node
- MCPAn app's tools, resources and prompts, for AI agents
- ToolsWhat a tool is, made once for the AI package's models and an MCP server
- HeadlessChromium's headless shell driven from Roc: pages opened, clicked, typed into and photographed
Monitoring
- OpenTelemetryRequest timings and the app's metrics over OTLP; logs for a collector
- PostHog5xx answers, handled errors, failed jobs and browser errors, as PostHog issues
What is in a package#
Each package has its own directory under the repository's packages/ (beside dbcheck, which rocx check --sql uses and no app imports). It holds Roc modules, components, or both.
Roc modules
main.roc is an ordinary Roc package header listing the modules. A package that only computes (charts, forms, intl, Markdown, QR codes) names no platform. It can't render or fetch, so the server, the browser and an expect all call the same functions. A package that needs the server (to send email, run jobs, read the database) names the server platform; more than half do. One, headless, names the CLI platform: rocx uses it, apps don't.
Components
components/*.rocx are components, such as <BarChart>. They import the platform's Html and Solid, and an app is two programs on two platforms (server and browser). So rocx generate (which rocx dev and rocx build run first) copies them into the app, and each half compiles them on its own platform.
A server-platform package can still offer modules to the browser (audio's Audio.play! runs in a click handler). It lists them in a second header, browser.roc, which names the browser platform only if they need it. The browser's half of the app sees that header instead of main.roc. If a page imports any other module, rocx stops and names the import.
Adding one to an app#
Name the package in the app's header (main.roc), beside the platform. You import it by the name before the colon; use the package's directory name, as every app here does.
app [program] { charts: "../packages/charts/main.roc", pf: platform "../server/platform/main.roc" }That line covers both halves: rocx generate writes the browser copy's header from it, on the browser platform, through each package's browser.roc if it has one. A server-platform package with no browser.roc (Stripe, storage, PostHog) is left out of that copy.
Then import modules and components as in any Roc program: import charts.Format, import charts.BarChart. A component is copied to the app's Generated/charts/BarChart.roc and the import points there. Its <style> joins the app's stylesheet, and compiler errors point at the package's file. The charts page's bar chart, from site/Demos/BarDemo.rocx:
import charts.BarChart
import charts.Format
{<BarChart data!={walk!().birds} label="Birds counted on a morning walk, by kind" format={|count| Format.num(count, 0)} padding={Shuffle.pick(look!(), 0.3, 0.55, 0.12)} />}Each package's page shows its header line, a first example and its limits. The README.md in the package's directory is the full reference.
Plugins#
Some features need more than functions: a job queue needs a table and background workers, a dev mailbox its own pages, a sound player a script on every page. A package provides these as a plugin: one value, made from options, listed in your program's plugins.
import jobs.Job
import email.Email
program = App.program({
init!,
plugins: [Job.plugin({ jobs: App.jobs }), Email.plugin({})],
})A plugin can add database tables (applied before the app's migrations), background loops, work at start, development pages (only under --dev or --debug), and files it serves, such as a page script or a service worker. It adds no routes: every URL your app answers is a file under routes/ (D-116). A package that answers requests gives you handlers to call from your own route files, behind their folder's middleware.
A plugin can declare what it needs: an environment variable, a database, another plugin. At start the server checks every plugin and stops on any problem (a missing variable, a required plugin not listed, two files at one place), listing them all. The server platform's page covers what a plugin can add and how to write one.
The packages that are plugins, and what each adds:
- Auth:
Auth.plugin({ providers })adds its tables: sessions, users, roles and two-factor sign-in. Its handlers answer your sign-in routes (a mailed link, a provider and back, the second factor, signing out, the dev sign-in) with youradmit!, and its middleware passes on the signed-in user. - Stripe:
Stripe.plugin({})adds tables of customers, checkouts, subscriptions and events, kept in step byStripe.webhook_route!on your webhook route, with youron_event!. Its functions send people to Checkout and the Customer Portal, say who has paid, and give your own billing page the card, the invoices and cancelling. - AI:
Ai.plugin({})reads the API key and model at start (outside--dev, no key, no start) and logs the model. Its functions ask Claude for an answer (whole, streamed to a page, or read into a Roc type), with the app's functions as tools. Its agents are models with a role and their own tools, and can be each other's tools. - Jobs and cron:
Job.plugin({ jobs: App.jobs, crons })adds the queue's table, its workers, the schedules' loop, and a sweep of old finished jobs. - Email:
Email.plugin({})adds the dev mailbox under--dev, and logs at start whether the SMTP server answers. Outside--dev, noSMTP_URL, no start. - Push:
Push.plugin({})adds the subscriptions' table, the sending job (it needs the jobs plugin), the service worker and the page's script; under--devwith no VAPID keys, a key pair for the run. Three handlers answer your routes for the key and a page's subscriptions. - Guard:
FlagStore.plugin({})keeps feature-flag overrides in a table, so they survive a restart. Rate limits and guards need no plugin. - Audio:
AudioPlayer.plugin({})adds the player forAudio.play!, a script every page loads. - Vibrate:
Vibrator.plugin({})adds the script that passesVibrate.pattern!to the browser's vibration motor. A phone app needs none. - PostHog:
PostHog.plugin({})sends errors to PostHog's error tracking; its handlers answer your routes for the page's script and its report endpoint. - OpenTelemetry:
Otel.plugin({})reads theOTEL_*settings at start and adds the loop that sums the app's measurements and sends them to the collector. Its middleware times every request.