Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:
name: Build and test
name: ✨ Build and Test
runs-on: ubuntu-latest
services:
postgres:
Expand All @@ -22,41 +22,48 @@ jobs:
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-beam@v1
- uses: actions/checkout@v7 # github.com/actions/checkout
- name: 💧 Set up Elixir
uses: erlef/setup-beam@v1 # github.com/erlef/setup-beam
with:
elixir-version: '1.18.4' # Define the elixir version [required]
otp-version: '28.0.1' # Define the OTP version [required]
- name: Restore dependencies cache
uses: actions/cache@v4
elixir-version: '1.19.x' # Define the elixir version [required]
otp-version: '28.1.x' # Define the OTP version [required]
- name: 📂 Restore Dependencies Cache
uses: actions/cache@v6 # github.com/actions/cache
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Install dependencies
- name: ⬇️ Install dependencies
run: mix deps.get
- name: Run Tests
run: mix coveralls.json
- name: ✅ Run Tests
run: mix ci --warnings-as-errors
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MIX_ENV: test
AUTH_API_KEY: ${{ secrets.AUTH_API_KEY }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1

- name: 🎨 Check code formating
run: mix format --check-formatted

- name: 🔍 Lint the code
run: mix credo --all --strict

- name: 💯 Upload coverage to Codecov
uses: codecov/codecov-action@v7 # github.com/codecov/codecov-action

# Continuous Deployment to Fly.io
# https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/
deploy:
name: Deploy app
name: 🚀 Deploy app
runs-on: ubuntu-latest
needs: build
# https://stackoverflow.com/questions/58139406/only-run-job-on-specific-branch-with-github-actions
if: github.ref == 'refs/heads/main'
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: superfly/flyctl-actions@1.1
- uses: actions/checkout@v7 # github.com/actions/checkout
- uses: superfly/flyctl-actions@1.5 # github.com/superfly/flyctl-actions
with:
args: "deploy"
9 changes: 3 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Temporary files, for example, from tests.
/tmp/

# Ignore package tarball (built via "mix hex.build").
chat-*.tar

# Ignore assets that are produced by build tools.
/priv/static/assets/
/priv/static

# Ignore digested assets cache.
/priv/static/cache_manifest.json
Expand All @@ -33,8 +35,3 @@ chat-*.tar
npm-debug.log
/assets/node_modules/

.vscode/
.env
.DS_Store

.elixir_ls
449 changes: 449 additions & 0 deletions AGENTS.md

Large diffs are not rendered by default.

88 changes: 43 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<div align="center">

# Phoenix Chat Example

![phoenix-chat-logo](https://user-images.githubusercontent.com/194400/39481553-c448aa1c-4d63-11e8-9389-47789833a96e.png)

![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/dwyl/phoenix-chat-example/ci.yml?label=build&style=flat-square&branch=main)
Expand All @@ -21,15 +19,17 @@ and _deploying_ a Chat app in Phoenix!

</div>

- [Phoenix Chat Example](#phoenix-chat-example)
- [Why?](#why)
- [What?](#what)
- [Who?](#who)
- [_How_?](#how)
<details>
<summary>Contents [click to expand]</summary>

- [Why? 🤷‍♀️](#why-️)
- [What? 💭](#what-)
- [Who? 👥](#who-)
- [_How_? 💻](#how-)
- [0. Pre-requisites (_Before you Start_)](#0-pre-requisites-before-you-start)
- [_Check_ You Have Everything _Before_ Starting](#check-you-have-everything-before-starting)
- [First _Run_ the _Finished_ App](#first-run-the-finished-app)
- [Clone the Project:](#clone-the-project)
- [Clone the Project: ⬇️](#clone-the-project-️)
- [Install the Dependencies](#install-the-dependencies)
- [Run the App](#run-the-app)
- [1. _Create_ The _App_](#1-create-the-app)
Expand Down Expand Up @@ -65,7 +65,10 @@ and _deploying_ a Chat app in Phoenix!
- [Inspiration](#inspiration)
- [Recommended Reading / Learning](#recommended-reading--learning)

## Why?
<br />
</details>

# Why? 🤷‍♀️

Chat apps are the
[`"Hello World"`](https://en.wikipedia.org/wiki/%22Hello,_World!%22_program)
Expand All @@ -83,15 +86,18 @@ which are all part of the "***Real World***"
of building and running apps;
so those are topics we **_will_ cover** to "_fill in the gaps_".

We wrote _this_ tutorial to be **_easiest_ way to learn `Phoenix`**,
`Ecto` and `Channels` with a **_practical_ example _anyone_ can follow**.
We wrote _this_ tutorial
to be **_easiest_ way to learn `Phoenix`**,
`Ecto` and `Channels` with a **_practical_ example
_anyone_ can follow**. 🔰

This is the example/tutorial we _wished_ we had
when we were learning `Elixir`, `Phoenix` ...
If you find it useful, please ⭐ 🙏 Thanks!
If you find it useful,
**_please_ star** on **`GitHub`** ⭐ 🙏 Thanks!


## What?
# What? 💭

A simple step-by-step tutorial showing you how to:

Expand All @@ -118,7 +124,7 @@ as it's _immediately_ obvious and _practical_ ***why***
we are learning something.


## Who?
# Who? 👥

This example is for ***complete beginners***
as a "***My First Phoenix***" App. <br />
Expand All @@ -138,7 +144,7 @@ that is or might be stuck with the _same_ thing!
[dwyl/learn-**phoenix-framework**/issues](https://github.com/dwyl/learn-phoenix-framework/issues)


# _How_?
# _How_? 💻

These instructions show you how to _create_ the Chat app
_from scratch_.
Expand Down Expand Up @@ -188,7 +194,7 @@ see:
[dwyl/Javascript-the-Good-Parts-notes](https://github.com/dwyl/Javascript-the-Good-Parts-notes)


### _Check_ You Have Everything _Before_ Starting
### _Check_ You Have Everything _Before_ Starting

Check you have the _latest version_ of **Elixir**
(_run the following command in your terminal_):
Expand All @@ -214,32 +220,14 @@ mix phx.new -v
You should see:

```sh
Phoenix installer v1.7.0-rc.2
Phoenix installer v1.8.5
```

> **Note**: if your `Phoenix` version is _newer_,
> Please feel free to update this doc! 📝
> We try our best to keep it updated ...
> but _your_ contributions are always welcome!

> In this tutorial,
> we are using
> [Phoenix 1.7-rc2](https://github.com/phoenixframework/phoenix/blob/master/CHANGELOG.md#170-rc2-2023-01-13),
> the second release candidate
> for `Phoenix 1.7`.
> At the time of writing,
> if you install Phoenix,
> the *latest stable version* is not `v1.7`.
> To use this version,
> follow the official guide (don't worry, it's just running one command!)
> -> https://www.phoenixframework.org/blog/phoenix-1.7-released
>
> However, if you are reading this after its release,
> `v1.7` will be installed for you,
> and you should see
> `Phoenix installer v1.7.0`
> in your terminal.


_Confirm_ **PostgreSQL** is running (_so the App can store chat messages_)
run the following command:
Expand All @@ -252,11 +240,12 @@ You should see output _similar_ to the following:

```sh
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 529 Nelson 5u IPv6 0xbc5d729e529f062b 0t0 TCP localhost:postgresql (LISTEN)
postgres 529 Nelson 6u IPv4 0xbc5d729e55a89a13 0t0 TCP localhost:postgresql (LISTEN)
postgres 529 Alex 5u IPv6 0xbc5d729e529f062b 0t0 TCP localhost:postgresql (LISTEN)
postgres 529 Alex 6u IPv4 0xbc5d729e55a89a13 0t0 TCP localhost:postgresql (LISTEN)
```

This tells us that PostgreSQL is "_listening_" on TCP Port `5432`
This tells us that PostgreSQL
is "_listening_" on TCP Port `5432`
(_the default port_)

If the `lsof` command does not yield any result
Expand All @@ -279,21 +268,21 @@ performed, let's _fly_! 🚀

<br />

## First _Run_ the _Finished_ App
## First _Run_ the _Finished_ App

_Before_ you attempt to build the Chat App from scratch,
clone and run the _finished_ working version
to get an idea of what to expect.

### Clone the Project:
### Clone the Project: ⬇️

In your terminal run the following command to clone the repo:

```sh
git clone git@github.com:dwyl/phoenix-chat-example.git
```

### Install the Dependencies
### Install the Dependencies

Change into the `phoenix-chat-example` directory
and install both the `Elixir` and `Node.js` dependencies
Expand All @@ -306,16 +295,15 @@ mix setup

<!-- ### TODO: Add auth step? -->


### Run the App

Run the Phoenix app with the command:

```sh
mix phx.server
```
```

If you open the app
Open the app
[localhost:4000](http://localhost:4000)
in two more web browsers,
you can see the chat messages
Expand All @@ -324,6 +312,12 @@ as soon as you hit the <kbd>Enter</kbd> key:

![phoenix-chat-example-tailwind-ui-with-auth](https://user-images.githubusercontent.com/194400/204945771-fa4f4c2a-b055-4ef2-93f0-fe0c6b8f4466.gif)

> **Note**: if you want to use
the **_optional_ authentication** (login),
you wil need to follow the instructions in:



<br />

Now that you have confirmed that the _finished_
Expand Down Expand Up @@ -389,7 +383,11 @@ in your browser <br />
and you will see the `default`
"Welcome to Phoenix" homepage:_ <br />

![welcome-to-phoenix](https://user-images.githubusercontent.com/17494745/216576178-a227a6ef-ad12-4b74-9b29-4913b5e298bc.png)
<div align="center">

![welcome-to-phoenix](https://github.com/user-attachments/assets/39da24da-62df-4c24-a1ae-5165d7bba754)

</div>

Shut down the Phoenix server in your terminal
with the
Expand Down
Loading
Loading