A real-time web forum application built with Go and WebSockets, enabling live user communication through posts, comments, and private messaging.
- Hamza Maach
- Yassine Elmach
- Registration with comprehensive user details:
- Nickname
- Age
- Gender
- First Name
- Last Name
- Password
- Login using nickname/email and password
- Secure session management
- Real-time online/offline status tracking
- Single Page Application (SPA) architecture
- Create and read posts
- Comment on posts
- Multiple category associations for posts
- Real-time private messaging between users
- Online/offline user status display
- Message history
- Message sorting by recent activity
- Message format includes:
- Timestamp
- Sender information
- Message content
real-time-forum/
├── cmd/
│ └── main.go # Application entry point and server initialization
├── server/
│ ├── api/ # RESTful API routes and WebSocket endpoint definitions
│ ├── config/ # Environment configurations and application settings
│ ├── controllers/ # HTTP handlers and WebSocket message handlers
│ ├── database/ # Database files (database.db, schema.sql, etc)
│ ├── middlewares/ # Request middleware (auth, rate limiting, etc)
│ ├── models/ # Data models and database query methods
│ ├── utils/ # Helper functions
│ └── validators/ # Request payload validation and sanitization
├── web/
│ ├── assets/
│ │ ├── css/ # Application styles and layout definitions
│ │ ├── js/ # Frontend logic and WebSocket client implementation
│ │ └── images/ # Static image resources
│ └── index.html # Single page application entry point
├── dockerfile # Container configuration for deployment
├── go.mod # Go dependencies and module configuration
└── README.md # Project documentation
- Go 1.22+
- SQLite3 database
- Gorilla WebSocket for real-time communication
- bcrypt for password hashing
- UUID for session management
- HTML5 & CSS3
- Font Awesome icons
- Vanilla JavaScript (No frameworks)
- WebSocket API
- Single Page Application architecture
- Docker containerization
- Real-time message delivery
- Online status updates
- Connection state management
- Error handling and reconnection logic
- Throttled/debounced scroll events for message loading
- Dynamic content rendering without page reloads
- Real-time UI updates
- Responsive design
- Users table with extended profile information
- Messages table for private communications
- Online status tracking
- Session management
- Posts and comments with real-time capabilities
View the detailed database schema here.
- Go 1.22 or higher
- SQLite3
- Docker (optional)
-
Clone the Repository
git clone https://github.com/hmaach/real-time-forum cd real-time-forum
-
Install Dependencies
go mod download
-
Run the Application
go run cmd/main.go
Access the forum at
http://localhost:8080
- Build and run using Docker:
docker build -t real-time-forum . docker run -p 8080:8080 real-time-forum
/ws/chat
- Private messaging connection
- POST
/api/register
- User registration - POST
/api/login
- User authentication - GET
/api/messages/:userId
- Fetch message history - POST
/api/posts
- Create new post - POST
/api/comments
- Create new comment