This example demonstrates how to integrate Crucible UI into a Phoenix application.
- Backend Implementation - Custom backend using in-memory storage (no database required)
- Router Integration - How to mount Crucible UI routes
- Component Usage - Using Crucible UI components in custom views
- Real-time Updates - PubSub integration for live updates
Since this is a documentation example (not a runnable Phoenix app), follow these steps to integrate Crucible UI into your own Phoenix application:
Add to your mix.exs:
def deps do
[
{:crucible_ui, "~> 0.2.0"}
]
endCreate lib/my_app/crucible_backend.ex:
defmodule MyApp.CrucibleBackend do
@behaviour Crucible.UI.Backend
# See backend_example.ex in this directory for full implementation
endIn lib/my_app_web/router.ex:
defmodule MyAppWeb.Router do
use MyAppWeb, :router
import Crucible.UI.Router
scope "/experiments" do
pipe_through [:browser, :require_authenticated]
experiment_routes "/",
backend: MyApp.CrucibleBackend,
on_mount: [MyAppWeb.RequireAuth],
root_layout: {MyAppWeb.Layouts, :app},
telemetry_prefix: [:my_app, :experiments]
end
endIn your LiveViews:
defmodule MyAppWeb.DashboardLive do
use Phoenix.LiveView
import Crucible.UI.Components
def render(assigns) do
~H"""
<.header>
My Dashboard
<:subtitle>Real-time experiment tracking</:subtitle>
</.header>
<.stat_card
icon="hero-beaker"
label="Total Experiments"
value={@experiment_count}
/>
"""
end
endbackend_example.ex- Complete Backend implementation with in-memory storagerouter_example.ex- Router configuration examplescustom_live_example.ex- Using Crucible UI components in custom views
- All 15 required callbacks
- In-memory storage (ETS)
- PubSub broadcasting
- Error handling
- Basic mounting
- Authentication hooks
- Custom layouts
- Telemetry prefixes
- Dashboard layouts
- Stat cards
- Status badges
- Data tables
- Modals
Crucible UI components work with any Phoenix app - no dependencies on specific app modules.
Backend is passed via session, allowing different implementations for different apps.
Comprehensive @behaviour and @spec ensure compile-time checks.
PubSub integration keeps all views in sync automatically.
- Review the example files in this directory
- Implement your own backend based on
backend_example.ex - Mount routes in your router
- Start using components in your views
For full documentation, see the main README.