Skip to content

A simple real-time chat application built with Go, HTMX, and WebSockets.

Notifications You must be signed in to change notification settings

cdt-eth/htmx-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-time Chat with Go, WebSocket, and HTMX

A real-time chat application built with Go, WebSocket for real-time messaging, and HTMX for dynamic UI interactions.

go-htmx

Features

  • Real-time messaging using WebSocket
  • Dynamic UI interactions with HTMX
  • User authentication with JWT
  • In-memory message storage
  • Message deletion
  • User identification

Tech Stack

  • Go for backend
  • WebSocket for real-time communication
  • HTMX for dynamic UI updates
  • JWT for authentication
  • Native CSS for styling
  • Air for live reload during development

Project Structure

htmx-chat/
├── .github/
│   └── workflows/
│       └── deploy.yml      # GitHub Actions deployment
├── cmd/
│   └── server/
│       └── main.go         # Application entry point
├── internal/
│   ├── auth/
│   │   └── jwt.go         # JWT utilities
│   ├── handlers/
│   │   ├── auth.go        # Authentication handlers
│   │   └── chat.go        # WebSocket and chat handlers
│   ├── middleware/
│   │   └── auth.go        # Auth middleware
│   └── models/
│       ├── message.go     # Message model
│       └── user.go        # User model
├── scripts/
│   └── deploy.sh          # Deployment helper script
├── templates/
│   ├── index.html         # Chat interface
│   └── login.html         # Auth interface
├── .air.toml              # Air configuration
├── .env.example          # Example environment variables
├── .gitignore
├── Dockerfile            # Container configuration
├── go.mod                # Go module definition
├── railway.toml          # Railway configuration
└── README.md

Running Locally

  1. Clone the repository:
git clone https://github.com/cdt-eth/htmx-chat.git
  1. Install dependencies:
go mod tidy
  1. Install Air for live reload:
go install github.com/cosmtrek/air@latest
  1. Set up environment variables:
cp .env.example .env
# Generate a JWT secret:
openssl rand -base64 32
# Add it to .env as JWT_SECRET
  1. Run with Air (live reload):
air

Or run directly with Go:

go run cmd/server/main.go
  1. Visit http://localhost:8080 in your browser

Deployment

This project is deployed on Railway.app.

Prerequisites

  • Docker installed locally
  • Railway CLI: brew install railway

Deploy Steps

  1. Login to Railway:
railway login
  1. Link to project:
railway link
  1. Deploy:
railway up

Environment Variables

Required variables in Railway:

  • JWT_SECRET: Your JWT signing key
  • PORT: Usually set to 8080

Continuous Deployment

Railway automatically deploys when changes are pushed to the main branch.

To deploy manually:

# Build and test locally
docker build -t htmx-chat .
docker run -p 8080:8080 htmx-chat

# Deploy to Railway
railway up

License

MIT

About

A simple real-time chat application built with Go, HTMX, and WebSockets.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published