A mixed programming language project using Rust for the chat server backend and TypeScript+React for the frontend.
The Docker deployment consist of the following:
- Separate Docker container for backend
- Separate Docker container for frontend
- Deployment runs in its own Docker network
If docker-compose is installed, build and run the service with the following command:
docker compose upBuild the Docker images by calling the Makefile with make. This will also create the chatservice-network Docker network.
makeRun the backend container with
make runBackendThen run the frontend container with
# In another terminal window
make runFrontendBuild and run the server in backend/:
cd backend
cargo run --releaseThen build and run the frontend in frontend/:
# In another terminal window
cd frontend
npm run startWhen using a Kubernetes distribution like MicroK8s, the Docker images have to be prebuilt and added to the local image registry of MicroK8s.
make backend
docker save chatservice-backend > chatservice-backend.tar
microk8s ctr image import chatservice-backend
make frontend
docker save chatservice-frontend > chatservice-frontend.tar
microk8s ctr image import chatservice-frontendAfter that, use microk8s kubectl apply -f kubernetes.yml to create the Kubernetes deployment locally.
There is no command-line interface.
- Open a web browser and navigate to
localhost:8000. Enter your user name. - Open a new browser window or tab for
localhost:8000and join as another user to the chat. Each new browser window and browser tab acts as a separate chat client connection. - Closing the browser window or tab disconnects the client and other clients in the chat will be notified about it.
- When using Docker, press CTRL+C to terminate the container that runs in the foreground, ending both backend and frontend.
You can access the following REST API endpoints (make sure to include /api in the URLs):
- Health endpoint:
GET http://localhost:8000/api/health - Message and activity history of current chat:
GET http://localhost:8000/api/history
The REST endpoints are proxied by the frontend and are used for functionality.
- Backend: Rust
- tokio: asynchronous runtime and TCP network layer
- tokio-tungstenite: WebSocket library
(Found on Are We Web Yet?.
There's also
rust-websocket, but it's unmaintained and the maintainers recommendtokio-tungstenitetoo instead. Note that there's also a WebSocket module inactix-web.) - actix-web: web framework for REST API endpoints
- serde: serialization library used for JSON payloads
- Frontend: TypeScript, React
- Vite: build tool and additional proxy routing of REST API endpoints
- Pico CSS: a lightweight CSS framework for making quick prototypes and demonstrations
- WebSocket API (Socket.IO library was considered, but that uses it's own custom handshake mechanism that is not compatible with the low-level WebSocket handling in Rust.)
- Introduce authentication.
- Make it a distributed service using load balancer, multiple service replicas and a separate in-memory store (Redis or Memcached).
