Go Chat is a REST API backend for a chat and browser notification system. It is built with Go, Gin, GORM, and MySQL, and includes authentication, user management, private chat rooms, chat messages, browser Web Push subscriptions, notification delivery, and a small Gemini AI prompt testing endpoint.
- User registration, login, logout, and authenticated profile access
- Bearer token authentication using personal access tokens
- Role-based route protection for admin/root users
- User profile and PIN update endpoints
- Private chat room listing and paginated message retrieval
- Message read tracking and unread message counts
- Browser push subscription, unsubscribe, and notification sending
- VAPID key generator for Web Push setup
- Gemini-powered prompt testing endpoint
- Layered project structure with domain, app/service, port, adapter, and HTTP packages
- Go 1.25.8
- Gin HTTP framework
- GORM ORM
- MySQL
- Web Push with VAPID keys
- Google Gemini API
cmd/
main.go # API application entrypoint
routes.go # Route registration
vapidkeygen/ # Helper command to generate Web Push VAPID keys
internal/
adapter/
db/ # GORM repository implementations
dto/ # Request/response DTOs
http/ # Gin HTTP handlers and middleware
app/ # Business logic services
domain/ # Database/domain models
port/ # Repository interfaces
shared/ # Shared helper utilities
Before cloning and running this project, make sure you have:
- Git
- Go 1.25.8 or newer
- MySQL running locally or remotely
- A Gemini API key
- A database schema compatible with the models in
internal/domain
Note: this repository currently does not include migration files. Create/import the required MySQL tables before running the API.
- Clone the repository:
git clone https://github.com/rosyanxone/go-chat.git- Move into the project directory:
cd go-chat- Download Go dependencies:
go mod download- Create your environment file:
cp .env.example .envOn Windows PowerShell, use:
Copy-Item .env.example .env- Configure
.env:
APP_PORT="8000"
DB_USER="root"
DB_PASS=""
DB_HOST="localhost"
DB_PORT="3306"
DB_NAME="chat"
GEMINI_API_KEY="your-gemini-api-key"
CHAT_DOMAIN="http://localhost:3000"
VAPID_PUBLIC_KEY=""
VAPID_PRIVATE_KEY=""
VAPID_SUBJECT="mailto:user@domain.com"- Generate VAPID keys for browser push notifications:
go run ./cmd/vapidkeygenCopy the generated VAPID_PUBLIC_KEY and VAPID_PRIVATE_KEY values into your .env file.
- Make sure the MySQL database exists:
CREATE DATABASE chat;Then import or create the required tables for users, roles, chats, chat rooms, chat messages, personal access tokens, employees, and push subscriptions.
- Run the API:
go run ./cmd- Test the health endpoint:
curl http://localhost:8000/healthExpected response:
{
"status": "ok"
}Public routes:
GET /healthPOST /api/registerPOST /api/loginPOST /api/validate/phone-numberGET /api/usersGET /api/user/email?email=user@example.comGET /api/web/vapid-public-keyPOST /api/promptPOST /api/test
Authenticated routes:
GET /api/userPOST /api/logoutPOST /api/user/updatePOST /api/user/update/pinGET /api/chat/roomsPOST /api/chat/messagesPOST /api/web/subscribePOST /api/web/unsubscribePOST /api/notify
Authenticated requests should include this header:
Authorization: Bearer <token>- The API runs on the port defined by
APP_PORT. - CORS is configured for local frontend ports and the production domains listed in
cmd/main.go. GEMINI_API_KEYis required at startup because the Gemini client is initialized when the app boots.- Push notifications require valid VAPID keys and frontend service worker support.