๐ฌ Step-by-step tutorial creates a Chat App using Phoenix LiveView including Presence, Authentication and Style with Tailwind CSS
We really wanted a Free & Open Source
real-world example
with full code,
tests and auth.
We wrote this
so we could point
people in our team/community
learning Phoenix LiveView to it.
This LiveView example/tutorial takes you from zero
to fully functioning app
in 20 minutes.
Here is the table of contents of what you can expect to cover in this example/tutorial:
LiveView Chat TutorialPhoenix Applive Directory, LiveView Controller and Templaterouter.exmount/3 functionAnyone learning Phoenix LiveView
wanting a self-contained tutorial
including:
Setup, Testing, Authentication, Presence,
It's recommended,
though not required,
that you follow the
LiveView Counter Tutorial
as this one is more advanced.
At least, checkout the list of
prerequisites
so you know what you need to have
installed on your computer before
you start this adventure!
Provided you have
Elixir, Phoenix
and Postgres installed,
you're good to go!
Phoenix AppStart by creating the new liveview_chat Phoenix application:
mix phx.new liveview_chat --no-mailer --no-dashboard
We don't need email or dashboard features
so we're excluding them from our app.
You can learn more about creating
new Phoenix apps by running:
mix help phx.new
Run mix deps.get to retrieve the dependencies.
then create the
liveview_chat_dev Postgres database
by running the command:
mix ecto.setup
You should see output similar to the following:
The database for LiveviewChat.Repo has been created
14:20:19.71 [info] Migrations already up
Once that command succeeds You should now be able to start the application by running the command:
mix phx.server
You will see terminal output similar to the following:
[info] Running LiveviewChatWeb.Endpoint with cowboy 2.9.0 at 127.0.0.1:4000 (http)
[debug] Downloading esbuild from https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.14.29.tgz
[info] Access LiveviewChatWeb.Endpoint at http://localhost:4000
[watch] build finished, watching for changes...
When you open the URL:
http://localhost:4000
in your web browser you should see something similar to:

live Directory, LiveView Controller and TemplateCreate the lib/liveview_chat_web/live folder
and the controller at
lib/liveview_chat_web/live/message_live.ex:
defmodule LiveviewChatWeb.MessageLive do
use LiveviewChatWeb, :live_view
def mount(_params, _session, socket) do
{:ok, socket}
end
def render(assigns) do
LiveviewChatWeb.MessageView.render("messages.html", assigns)
end
end
Note: neither the file name nor the code has the word "controller" anywhere. Hopefully it's not confusing. It's a "controller" in the sense that it controls what happens in the app.
A LiveView controller requires
the functions mount/3 and render/1 to be defined.
To keep the controller simple the mount/3
is just returning the {:ok, socket} tuple
without any chan
Warning: phx-update="append" is deprecated, please use streams instead ๐
https://github.com/dwyl/phoenix-liveview-chat-example/issues/281
Labels: help wanted, priority-2, chore, tech-debt, technical
Update Tailwind installation section
https://github.com/dwyl/phoenix-liveview-chat-example/issues/151
Labels: enhancement, T25m, chore
Update UI
https://github.com/dwyl/phoenix-liveview-chat-example/issues/150
Labels: enhancement
Postgres error on long message
https://github.com/dwyl/phoenix-liveview-chat-example/issues/149
Labels: bug
Still some errors in instructions?
https://github.com/dwyl/phoenix-liveview-chat-example/issues/123
Labels: help wanted, T25m, elixir, tech-debt, technical
Are Instructions up to date?
https://github.com/dwyl/phoenix-liveview-chat-example/issues/114
Labels: good first issue, help wanted, T2h, starter, priority-2, chore
example no js to reset input
https://github.com/dwyl/phoenix-liveview-chat-example/issues/88
Labels: enhancement, T5m, chore
No CONTRIBUTING document was found. Please check the README and open issues.