gleam-lustre-development
Guides Claude through idiomatic Lustre frontend development. Use when building SPAs, UI components, or interactive applications. Based on lustre_ui patterns from the official Lustre team.
What this skill does
# Gleam Lustre Development Skill
This skill guides Claude Code through **idiomatic Lustre development** following patterns from the official `lustre_ui` library.
## Primary Sources
1. **[Lustre Documentation](https://hexdocs.pm/lustre/)** - Official docs
2. **[Lustre UI](https://github.com/lustre-labs/ui)** - Official component library (reference implementation)
3. **[Lustre Examples](https://github.com/lustre-labs/lustre/tree/main/examples)** - Official examples
## Core Architecture: Model-Update-View
Every Lustre application follows the Elm Architecture:
```gleam
import lustre
import lustre/effect.{type Effect}
import lustre/element.{type Element}
// TYPES -----------------------------------------------------------------------
type Model {
Model(
count: Int,
// ... state fields
)
}
type Msg {
UserClickedIncrement
UserClickedDecrement
ApiReturnedData(Result(Data, Error))
}
// MAIN ------------------------------------------------------------------------
pub fn main() {
let app = lustre.application(init, update, view)
let assert Ok(_) = lustre.start(app, "#app", Nil)
Nil
}
// INIT ------------------------------------------------------------------------
fn init(_flags) -> #(Model, Effect(Msg)) {
let model = Model(count: 0)
#(model, effect.none())
}
// UPDATE ----------------------------------------------------------------------
fn update(model: Model, msg: Msg) -> #(Model, Effect(Msg)) {
case msg {
UserClickedIncrement -> #(Model(..model, count: model.count + 1), effect.none())
UserClickedDecrement -> #(Model(..model, count: model.count - 1), effect.none())
ApiReturnedData(Ok(data)) -> #(Model(..model, data: data), effect.none())
ApiReturnedData(Error(_)) -> #(model, effect.none())
}
}
// VIEW ------------------------------------------------------------------------
fn view(model: Model) -> Element(Msg) {
html.div([], [
html.button([event.on_click(UserClickedDecrement)], [html.text("-")]),
html.p([], [html.text(int.to_string(model.count))]),
html.button([event.on_click(UserClickedIncrement)], [html.text("+")]),
])
}
```
### Application Levels
```gleam
// Static HTML only (no interactivity)
lustre.element(html.div([], [html.text("Hello")]))
// Interactive without effects (init/update return Model only)
lustre.simple(init, update, view)
// Full application with effects (init/update return #(Model, Effect))
lustre.application(init, update, view)
// Registrable Web Component
lustre.component(init:, update:, view:, options: [...])
```
## MANDATORY: Message Naming Convention
**Messages MUST use Subject-Verb-Object naming that describes WHAT HAPPENED, not what to do:**
```gleam
// ✅ CORRECT: Describes what happened
type Msg {
UserClickedSubmit
UserTypedInField(value: String)
UserPressedEnter
UserSelectedOption(id: String)
UserToggledCheckbox(checked: Bool)
ApiReturnedUsers(Result(List(User), Error))
ApiReturnedError(Error)
ParentSetValue(value: String)
ParentToggledOpen
TimerFired
WindowResized(width: Int, height: Int)
}
// ❌ WRONG: Imperative/command style
type Msg {
Submit // What does this mean?
SetValue(String) // Command, not event
Toggle // Too vague
LoadUsers // Command, not event
UpdateField // Command, not event
}
```
**Prefixes by source:**
- `User...` - User interactions (clicks, typing, etc.)
- `Api...` - HTTP/API responses
- `Parent...` - Props from parent component
- `Timer...` / `Window...` / `Dom...` - Browser events
- `Child...` - Events from child components
## Controlled vs Uncontrolled Props
For components that can have state managed by parent OR internally:
```gleam
/// A prop that can be controlled by the parent or managed internally.
pub type Prop(a) {
Prop(
value: a, // Current value
controlled: Bool, // Is parent controlling this?
touched: Bool, // Has user interacted?
)
}
pub fn new(value: a) -> Prop(a) {
Prop(value: value, controlled: False, touched: False)
}
/// Set default value (only if not controlled and not touched)
pub fn default(prop: Prop(a), value: a) -> Prop(a) {
case prop.controlled || prop.touched {
True -> prop
False -> Prop(..prop, value: value)
}
}
/// Control from parent (always updates)
pub fn control(prop: Prop(a), value: a) -> Prop(a) {
Prop(..prop, value: value, controlled: True)
}
/// User touched (only updates if not controlled)
pub fn touch(prop: Prop(a), value: a) -> Prop(a) {
case prop.controlled {
True -> prop
False -> Prop(..prop, value: value, touched: True)
}
}
```
**Usage in update:**
```gleam
fn update(model: Model, msg: Msg) -> #(Model, Effect(Msg)) {
case msg {
ParentSetDefaultValue(value) ->
// Only apply if not controlled and not touched by user
case model.open.controlled || model.open.touched {
True -> #(model, effect.none())
False -> {
let open = Prop(..model.open, value: value)
#(Model(..model, open: open), effect.none())
}
}
ParentSetValue(value) -> {
// Controlled: always update
let open = Prop(..model.open, value: value, controlled: True)
#(Model(..model, open: open), effect.none())
}
UserToggledOpen ->
case model.open.controlled {
// Controlled: emit event, don't update locally
True -> #(model, emit_change(!model.open.value))
// Uncontrolled: update locally AND emit event
False -> {
let open = Prop(..model.open, value: !model.open.value, touched: True)
#(Model(..model, open: open), emit_change(!model.open.value))
}
}
}
}
```
## Web Components (Registrable Components)
For reusable components that need their own state:
```gleam
import lustre
import lustre/component
pub const tag: String = "my-component"
pub fn register() -> Result(Nil, lustre.Error) {
let comp = lustre.component(init:, update:, view:, options: [
// Don't inherit parent styles
component.adopt_styles(False),
// React to attribute changes
component.on_attribute_change("value", fn(value) {
Ok(ParentSetValue(value))
}),
// React to property changes (for complex values)
component.on_property_change("items", {
decode.list(decode.string)
|> decode.map(ParentSetItems)
}),
// React to context from ancestors
component.on_context_change("theme", {
use theme <- decode.field("theme", decode.string)
decode.success(ThemeChanged(theme))
}),
])
lustre.register(comp, tag)
}
// Public element function
pub fn element(
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
element.element(tag, attributes, children)
}
```
## Opaque Types for Public APIs
Encapsulate internal structure:
```gleam
/// An accordion item with heading and collapsible panel.
pub opaque type Item(msg) {
Item(
name: String,
attributes: List(Attribute(msg)),
heading: Element(msg),
panel: Panel(msg),
)
}
/// Create an accordion item.
pub fn item(
name name: String,
attributes attributes: List(Attribute(msg)),
heading heading: Element(msg),
panel panel: Panel(msg),
) -> Item(msg) {
Item(name:, attributes:, heading:, panel:)
}
```
## Effects
```gleam
import lustre/effect
// No effect
effect.none()
// Batch multiple effects
effect.batch([effect1, effect2, effect3])
// Custom effect
effect.from(fn(dispatch) {
// Do something async
dispatch(SomethingHappened(result))
})
// Emit custom event (for components)
event.emit("my-event", json.object([
#("value", json.string(value)),
]))
// Provide context to descendants
effect.provide("context-name", json.object([
#("theme", json.string("dark")),
]))
```
## Event Handling with Decoders
```gleam
import gleam/dynamic/decode
import lustre/event
// Simple event
pub fn on_click(msg: msg) -> Attribute(msg) {
event.on_click(msg)
}
// Custom event with detail
puRelated in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.