PhoenixDatastar - A LiveView-like experience for Phoenix using Datastar's SSE + Signals architecture

Sharing my project for review and feedback. Be gentle, my self-taught engineering degree is on spreadsheets and a no-code platform (Bubble.io).

AI disclosure
Mix of AI-assisted and hand-written code. Core architecture and design decisions are mine; AI helped with boilerplate, docs, and some implementation details. Also, I incessantly bothered @mcass19 , but he can’t do miracles. The bugs are 100% artisanal, hand-crafted by me.

What
A Phoenix framework integration that gives Elixir developers a LiveView-like experience using Datastar’s SSE + Signals architecture instead of WebSockets. You write familiar Phoenix callbacks (mount, handle_event, handle_info, render) with HEEx templates, but the transport is Datastar’s SSE protocol under the hood.

What it does today

  • Two view types: stateless (:datastar) and live (:live_datastar — GenServer-backed with SSE push)
  • Signal management (put_signal, update_signal) for client-side reactive state
  • Server-side assigns with patch_elements for granular DOM updates via SSE
  • igniter.install script
  • usage_rules skills
  • handle_info support for PubSub/timers — real-time multi-user updates work
  • event/2 macro for handling Datastar actions with signal data: it creates a @post with the csrf token.
  • execute_script, redirect, console_log
    Working examples included (counter, multiplayer counter via PubSub)

Goals / what’s not there yet

  • Alpha stage — the API is still changing. Not production-ready.
    • That said, I don’t listen to my own advice, so I built a little service with it: https://tiptap.rico.wtf. It has a thriving user base of one (me). No incidents reported so far.
  • Needs alignment with the Tao of Datastar
  • Error handling and edge cases need hardening

Would love feedback on whether the API surface feels right to Datastar users, even if you’re not familiar with Elixir.

Hex: phoenix_datastar | Hex
Repo:

GitHub - RicoTrevisan/phoenix_datastar: A LiveView-like experience for Phoenix using Datastar's SSE + Signals architecture. · GitHub

Appreciate any feedback — especially from folks who’ve built SDKs for other backends.

4 Likes

Thanks for sharing! I think it’d be nice if there was a go to Elixir + Datastar combo. This approach feels very similar to LiveView which some may like though imo since it’s so similar my first thought would be maybe I should just use LiveView.

I think there’s an opportunity to radically simplify this combo as a unique alternative framework. I shared some thoughts previously in another thread: Nex - A minimalist web framework for indie hackers and startups - #26 by jam

1 Like

Thank you! That’s the same thing that Delaney said when I posted on the Datastar Discord.

I would love to hear more about your ideas.

In the meantime, let me brain-fart some of the thoughts I had while building it – maybe you guys can spot where I went wrong and I can learn how to improve it.

  • there were some libraries that handled the SSE part of Datastar. I wanted that frontend-backend glue.
  • I’m rather ignorant on other patterns; Elixir Phoenix was ‘my first’. I tried to mimic that.
  • my main desire is to have some realtime pages, I figured I “just replace websockets part of LiveView”.
  • for realtime, the server needs to keep track of open connections – so GenServer on server.ex + registry.ex – does that job and keeps the sse stream open.
  • to get the stream open, I add a @get('_stream') with the default_html.ex
  • I like Phoenix’s way of keeping the page’s HTML and the actions together in one module. So I made a "gambiarra " macro to @post to the server and then have the server figure out which module it should dispatch the call to.
  • the datastar_session came about because when navigating from one live_datastar page to another, it would break in a weird way