This is a modern, real-time chat application built with Go, leveraging the power of Fiber, HTMX, Tailwind CSS, and Templ. It uses SQLite for persistent storage and Redis for real-time functionality.
- Real-time room-based with admin role messaging
- Persistent chat history with cursor pagination
- Persistant unread message count for each room
- Admin can add, kick, promote, demote a member
- Online status for users
- Responsive design with Tailwind CSS
- Server-side rendered templates with Templ
- Client-Server interactions using HTMX
- Go - Backend language
- Fiber - Web framework
- HTMX - Frontend interactivity
- Templ - Type-safe Go HTML templating
- Tailwind CSS - Styling
- SQLite - Database
- sql-migrate - Handling database migrations
- Redis - In-memory data store used for its Pub/Sub capabilities
- Air - Live reload for Go apps
- Docker - Containerization
- Fly.io - Deployment platform
- Go 1.20 or higher
- Docker (for deployment)
- Redis server
The application uses two environment variables:
DATABASE_PATH
: Path to the SQLite database file, Default :./test.db
REDIS_CONN_STRING
: Connection string for Redis, Default : uses local instance:6379
- Clone the repository:
git clone https://github.com/ricin9/chat-redis-pubsub
cd chat-redis-pubsub
- Install dependencies:
go mod tidy
go install github.com/rubenv/sql-migrate/...@latest # sql-migrate cli
go install github.com/air-verse/air@latest # live reload
go install github.com/a-h/templ/cmd/templ@latest # template engine
- Setup redis
You can either install redis locally using your package manager or docker, or use remote connection string like below
export REDIS_CONN_STRING=redis://<user>:<password>@<host>:<port>
- Run the development server:
I have not yet made development scripts/makefiles yet so you are going to have to do this one by one.
# runs main.go with live reload
air
# html template generation
templ generate --watch ./views
# generates tailwindcss classes
npx tailwindcss -c ./views/tailwind.config.js -i ./views/input.css -o ./static/css/output.css --watch
- Open your browser and navigate to
http://127.0.0.1:3000
- Generate production templates and styles
templ generate ./views
npx tailwindcss -c ./views/tailwind.config.js -i ./views/input.css -o ./static/css/output.css --minify
- Build the Docker image
docker build -t chat-app .
This project uses Docker and Fly.io for deployment.
-
Install fly.io CLI if you don't already have it. Guide
-
Since fly.io filesystem is ephemeral and we are using sqlite3 db, we need to create a volume.
fly volume create sqlite_db -r <region> -n 1
Region must be the same one you're deploying the app to.
-
Repeat Step 1 from Build Steps
-
Deploy to Fly.io:
flyctl deploy
Contributions are welcome! Please feel free to submit a Pull Request.
Open an issue if you found a bug, want to sugges changes, refactors, ...etc