A real-time forum application built with Go and JavaScript that enables users to communicate through posts, comments, and private messages.
- Overview
- Features
- Technologies Used
- Installation
- Usage
- API Endpoints
- WebSocket Implementation
- Database Schema
- Collaborators
- Contributing
- License
Real-Time Forum is a web application that allows users to interact through posts, comments, and private messaging. The application utilizes WebSockets for real-time functionality and SQLite for data persistence. The backend is written in Go, while the frontend is built with vanilla JavaScript.
-
User Authentication
- Registration and login system
- Session management using cookies
-
Posts Management
- Create and read posts
- Categorize posts for better organization
- Like/dislike functionality
- Image upload support
-
Comments System
- Add comments to posts
- Nested comment replies
- Like/dislike comments
-
Real-Time Private Messaging
- Send and receive messages instantly
- Chat history persistence
- Online status indicators
- Typing Animation
-
Updates
- Real-time update for posts, likes, comments, and messages for all users
- Go: Server-side programming language
- SQLite: Database management
- Gorilla WebSocket: WebSocket implementation for Go
- HTTP Router: Custom routing implementation
- JavaScript: Client-side scripting
- HTML/CSS: Structure and styling
- WebSocket API: Client-side WebSocket implementation
- Fetch API: AJAX requests to the server
- HTTP/HTTPS: For RESTful API communication
- WebSocket Protocol: For real-time bidirectional communication
- Implements the WebSocket handshake (HTTP Upgrade)
- Uses ws:// protocol
- Go (version 1.23+)
- SQLite
- Git
-
Clone the repository:
git clone https://learn.zone01kisumu.ke/git/aosindo/real-time-forum
-
Navigate to the project directory:
cd real-time-forum -
Run the make command to build and start the application:
make
-
The server will start running on
http://localhost:8000(or the configured port)
- Open your browser and navigate to
http://localhost:8000 - Register a new account or login with existing credentials
- Explore the forum by browsing posts or creating your own
- Interact with other users through comments, likes, and private messages
The application exposes several RESTful API endpoints for client-server communication:
POST /api/signup- Register a new userPOST /api/login- Authenticate a userPOST /api/logout- Log out and invalidate session
GET /api/posts- Get all postsGET /api/post/details- Get a specific postPOST /posts/create- Create a new postPOST /api/interactions- Like/Dislike
POST /api/comments- Add a comment to a postPOST /api/interactions- Like/Dislike
GET /api/messages- Send a message via REST API (fallback)
The application uses WebSockets to provide real-time functionality:
- Client connects to
ws://localhost:8000/wswith session token authentication - Server upgrades the HTTP connection to WebSocket protocol
chat_message: Private messages between usersupdates: System Updates (likes, comments, etc.)user_status: Online/offline status updatestyping_indicator: Shows when a user is typing
- Connection is established with HTTP upgrade request
- Authentication is performed using session cookies
- JSON messages are exchanged between client and server
The application uses SQLite with the following main tables:
users: User information and authenticationsessions: User session dataposts: Forum posts with category relationshipscomments: Comments on posts and repliesinteractions: Tracks likes/dislikes on posts and commentsmessages: Private messages between userscategories: Post categorization
We welcome contributions to the Real-Time Forum project. Please follow these steps to contribute:
- Fork the repository
- Create a new branch (
git checkout -b feature/amazing-feature) - Make your changes
- Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please ensure your code follows the project's coding standards and includes appropriate tests.
This project is licensed under the MIT License - see the LICENSE file for details.