SwiftChat is a modern, real-time chat application built using C++ and the Crow microframework. It supports user authentication, multi-user chat over WebSockets, and even integrates with DeepL for language translation.
- User Signup & Login: Secure authentication using JWT tokens.
- Real-Time Chat: WebSocket-based chat with session management.
- Language Translation: Translate messages using DeepL API.
- PostgreSQL Integration: User data and sessions are stored in a PostgreSQL database.
- REST API: Endpoints for user management and translation.
- HTML Templates: Renders HTML pages for login, signup, chat, and communities.
- C++17 compatible compiler (e.g.,
g++) - Crow
- nlohmann/json
- jwt-cpp
- libpqxx
- libcurl
- PostgreSQL
-
Clone the Repository:
git clone https://github.com/alihassancods/swiftchat.git cd swiftchat -
Install Dependencies:
Make sure you have installed all the required libraries mentioned above. For Ubuntu, you can use:
sudo apt-get install libpqxx-dev libcurl4-openssl-dev
You may also need to install Crow, jwt-cpp, and nlohmann/json manually or via your package manager.
-
Set Up Your Environment Variables:
Create a
data.envfile in the project root with the following content:IP_ADDR=your_postgres_host_ip API_KEY=your_deepl_api_key -
Prepare the Database:
Ensure PostgreSQL is running and create the required database and table:
CREATE DATABASE swiftchat; \c swiftchat CREATE TABLE users ( id SERIAL PRIMARY KEY, email TEXT UNIQUE NOT NULL, password TEXT NOT NULL, username TEXT NOT NULL, master_token TEXT );
Default database connection assumes:
- user:
postgres - password:
1234 - port:
5432 - db:
swiftchat
Adjust these in
main.ccor viadata.envas needed. - user:
-
Build the Project:
g++ -std=c++17 -o websocket_app main.cc -lcurl -lcrypto -pthread -lpqxx
-
Run the Server:
./websocket_app
The app will run on port
18080.
- Visit
http://localhost:18080/signupto create a new account. - Visit
http://localhost:18080/loginto log in. - Visit
http://localhost:18080/chatfor the main chat interface. - The
/translateendpoint can be used for text translation.
- POST
/signup– Register a new user (email,password) - POST
/login– Authenticate and receive a session token (email,password) - GET
/profile– User profile page (HTML) - GET
/communities– Communities list (HTML) - GET
/chat– Main chat (HTML) - GET
/translate?text=your_text– Translate text to English (uses DeepL)
Connect to: ws://localhost:18080/ws
Handles real-time messaging between authenticated sessions.
MIT