A real-time chat application built with Phoenix LiveView, inspired by Discord's UI. This application demonstrates the power of Phoenix LiveView for building interactive, real-time web applications without writing any JavaScript.
- Real-time message updates using Phoenix PubSub
- Multiple chat channels with instant switching
- Discord-inspired UI using TailwindCSS
- Message persistence within the LiveView session
- User identification system
- Responsive design
- Elixir 1.14 or later
- Phoenix 1.7 or later
- PostgreSQL (optional, current version stores messages in memory)
- Node.js 14 or later (for asset compilation)
- Clone the repository:
git clone <repository-url>
cd chat
- Install dependencies:
mix deps.get
mix deps.compile
- Install Node.js dependencies:
cd assets
npm install
cd ..
- Start the Phoenix server:
mix phx.server
Now you can visit localhost:4000/chat
from your browser.
lib/
├── chat/
│ └── application.ex
├── chat_web/
│ ├── live/
│ │ └── chat_live.ex # Main LiveView module
│ ├── router.ex
│ └── endpoint.ex
test/
├── chat_web/
│ └── live/
│ │ └── chat_live_test.exs # LiveView tests
└── support/
└── conn_case.ex
The main LiveView module (lib/chat_web/live/chat_live.ex
) handles:
- Real-time message broadcasting
- Channel management
- User session management
- UI rendering
Run the test suite:
mix test
The test suite covers:
- LiveView mounting
- Message sending and receiving
- Channel switching
- Real-time updates
- User management
This application can be deployed to any platform that supports Phoenix applications. For Heroku deployment:
- Add build packs:
heroku buildpacks:add hashnuke/elixir
heroku buildpacks:add https://github.com/gjaldon/heroku-buildpack-phoenix-static.git
- Configure environment variables:
heroku config:set SECRET_KEY_BASE=$(mix phx.gen.secret)
heroku config:set PHX_HOST=your-app-name.herokuapp.com
-
Persistence
- Add database storage for messages
- Implement message history
-
User Features
- User authentication
- User profiles and avatars
- Online status tracking
-
Channel Features
- Private channels
- Direct messaging
- Channel permissions
-
UI Enhancements
- Message formatting
- File uploads
- Emoji support
- Typing indicators
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE.md file for details.
- Phoenix Framework team for LiveView
- Discord for UI inspiration
- TailwindCSS for styling utilities