Skip to content

About

Real-time terminal chat in C++20 over gRPC (bidirectional streaming) — multi-room, presence, SQLite history, Docker-ready

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Gadu++

A real-time terminal chat application written in C++20, communicating over gRPC (bidirectional streaming). No GUI — plain terminal, like the old-school messengers or IRC. A weekend project, built to a solid standard: multithreaded server, unit tests, Docker.

C++ gRPC CMake Docker Tests


What this project is

A text-based chat application that runs entirely in the terminal. Multiple users connect to a server, join rooms (identified by an id, e.g. 123) and talk in real time — like classic instant messengers, just without any window, using nothing but stdin/stdout.

The project exists to demonstrate concrete C++ engineering skills, not just a "hello world":

  • Network programming — gRPC with bidirectional streaming (a single RPC call carries an entire chat session, in both directions, for its whole lifetime).
  • Concurrency — a multithreaded server (a dedicated writer thread per client, fed through a thread-safe queue), and a client with two threads (reading stdin concurrently with receiving the stream).
  • API design — the contract is defined in Protocol Buffers, and business logic (RoomManager) is separated from the transport layer (ChatServiceImpl), which makes message routing testable without spinning up a real server.
  • Data persistence — chat history stored in SQLite.
  • Unit testing — GoogleTest covering the routing logic (rooms, direct messages, presence).
  • DevOps — a multi-stage Docker build plus docker compose, so the whole thing runs with a single command, no local installation required.

Demo

$ ./gadu_client --user=mateusz --server=localhost:50051 123
Connected as mateusz, room: 123. Type /help for the list of commands.
*** Welcome, mateusz! You are in room '123'.
hey everyone
[12:03:11] kasia: hey, I'm here too
--- kasia changed status to: away ---
/dm kasia I have a question about the project

Room 123 in the example above did not need to exist beforehand — the server creates it automatically on first join.

Quick start (Docker — the fastest path)

Requires only Docker, nothing else needs to be installed:

git clone <this-repo-url>
cd gadu-plus-plus

# start the server in the background
docker compose up -d --build server

# in a separate terminal: connect as a client to room "123"
docker compose run --rm client --user=mateusz --server=server:50051 123

Open a second terminal and run the same command with a different --user to see a live conversation between two people.

Quick start (native build on Linux)

sudo apt-get update
sudo apt-get install -y \
    build-essential cmake pkg-config \
    protobuf-compiler-grpc libgrpc++-dev libprotobuf-dev \
    libsqlite3-dev libgtest-dev

mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . -j$(nproc)

# terminal 1
./gadu_server --address=0.0.0.0:50051 --db=gadu.db

# terminal 2
./gadu_client --user=mateusz --server=localhost:50051 123

Architecture

[CLI client] <--gRPC (bidi streaming)--> [Server] <---> [SQLite]
  2 threads: stdin + stream reader      1 thread/client    chat history

All communication flows over a single bidirectional stream (rpc Chat(stream ClientMessage) returns (stream ServerMessage)) — no polling, no separate request per message.

Features

Feature How to use it
Rooms by id, created automatically 3rd CLI argument, e.g. ... 123, or --room=123
Switching rooms mid-session /join <room>
Direct messages /dm <user> <text>
Presence status /status available|away|invisible
Recent message history sent automatically right after joining a room

Project layout

gadu-plus-plus/
├── proto/gadu.proto            # gRPC contract
├── server/
│   ├── chat_service.hpp/.cpp   # Chat() RPC implementation
│   ├── room_manager.hpp/.cpp   # message routing, rooms, presence
│   ├── storage.hpp/.cpp        # chat history in SQLite
│   └── blocking_queue.hpp      # thread-safe outbound queue
├── client/main.cpp             # terminal client (2 threads)
├── tests/room_manager_test.cpp # unit tests (GoogleTest)
├── docker/                     # Dockerfile.server, Dockerfile.client
└── docker-compose.yml

Tests

cd build
ctest --output-on-failure
# or directly:
./gadu_tests

The message-routing logic (RoomManager) is decoupled from the gRPC layer, which makes it testable without a real network client or server.

Tech stack

C++20 · gRPC · Protocol Buffers · CMake · SQLite · GoogleTest · Docker

Possible extensions

  • TLS between client and server
  • Client-side reconnect with backoff
  • List of online users in a room (/who)
  • Authentication instead of a bare username

About

Real-time terminal chat in C++20 over gRPC (bidirectional streaming) — multi-room, presence, SQLite history, Docker-ready

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages