A real-time chat application built with Go, WebSocket for real-time messaging, and HTMX for dynamic UI interactions.
- Real-time messaging using WebSocket
- Dynamic UI interactions with HTMX
- User authentication with JWT
- In-memory message storage
- Message deletion
- User identification
- 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
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
- Clone the repository:
git clone https://github.com/cdt-eth/htmx-chat.git
- Install dependencies:
go mod tidy
- Install Air for live reload:
go install github.com/cosmtrek/air@latest
- Set up environment variables:
cp .env.example .env
# Generate a JWT secret:
openssl rand -base64 32
# Add it to .env as JWT_SECRET
- Run with Air (live reload):
air
Or run directly with Go:
go run cmd/server/main.go
- Visit
http://localhost:8080
in your browser
This project is deployed on Railway.app.
- Docker installed locally
- Railway CLI:
brew install railway
- Login to Railway:
railway login
- Link to project:
railway link
- Deploy:
railway up
Required variables in Railway:
JWT_SECRET
: Your JWT signing keyPORT
: Usually set to 8080
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
MIT