How codingminions/whatsapp-lite works
Project type and purpose
• A full-stack, monolithic chat application written in Go
• Exposes HTTP endpoints for registration, login and serves HTML templates + CSS under /web
• Provides real-time messaging via WebSockets
• Persists users, sessions, and messages in a Postgres database
File structure
• cmd/server/main.go — the application entry point (starts HTTP & WS server)
• configs/ — global configuration loader (YAML + Go binding)
• internal/… — business logic, organized by domain (auth, user, conversation, websocket)
– handler.go → HTTP handlers
– service.go → domain logic
– repository.go → data access
– middleware.go (auth)
– websocket/hub.go, client.go → real-time hub
• pkg/… — shared utilities
– pkg/database/postgres.go → DB connection
– pkg/logger/logger.go → logging
– pkg/token/jwt.go → JWT generation/validation
– pkg/validator/validator.go → input validation
• migrations/ — SQL migrations for Postgres schema
• web/ — static assets and HTML templates
• test_*.go — integration/unit tests
• Makefile — bootstraps Postgres on macOS and runs the server
README
• Purpose: minimal real-time chat (1k concurrent users)
• Startup: make postgres_setup_complete → go run cmd/server/main.go → visit port 8080
• No external microservices; pure monolith
Main components & interactions
a. CLIENT LAYER
• Web Browser
– Loads static assets (CSS, JS if any) & HTML templates via HTTP GET
– Initiates WebSocket connection for real-time messaging
b. SERVER LAYER
• HTTP Server (Gin/Std-lib mux)
– Routes: /register, /login, /chat, /api/*
– middleware: JWT auth from pkg/token
– handlers in internal/auth, internal/user, internal/conversation
• WebSocket Hub
– Accepts WS handshake at /ws (internal/websocket/router.go)
– Maintains client registry (hub.go)
– Broadcasts direct & group messages to connected clients
c. SERVICE LAYER
• AuthService, UserService, ConversationService
– Encapsulate business rules
– Use pkg/validator for input checks
d. REPOSITORY LAYER
• Repository interfaces for users, sessions, messages, groups
• Implemented via pkg/database/postgres connection
e. DATABASE
• Postgres instance
• Tables: users, sessions, direct_messages, groups, group_members, group_messages
f. SUPPORTING UTILITIES
• Logger (pkg/logger)
• Config loader (configs/config.go reading config.yaml)
• Migrations folder (SQL scripts)
Architectural patterns & principles
• Layered architecture (Handler → Service → Repository)
• Separation of concerns
• Dependency injection via function parameters (e.g., pass repositories to services)
• Single binary monolith
• WebSocket “pub-sub” hub pattern