An open API service indexing awesome lists of open source software.

https://github.com/elyse502/real-time-chat-app

A full-stack real-time chat application built with Node.js, Socket.IO, React, TypeScript, and Tailwind CSS featuring room-based messaging, typing indicators, live user tracking, responsive UI, and scalable modular architecture.
https://github.com/elyse502/real-time-chat-app

backend chat-application event-driven expressjs frontend fullstack nodejs react react-context-api realtime-chat realtime-communication responsive-ui socketio socketio-client tailwindcss typescript typescript-project vite websocket websocket-server

Last synced: 1 day ago
JSON representation

A full-stack real-time chat application built with Node.js, Socket.IO, React, TypeScript, and Tailwind CSS featuring room-based messaging, typing indicators, live user tracking, responsive UI, and scalable modular architecture.

Awesome Lists containing this project

README

          

# ๐Ÿ’ฌ Real-Time Chat Application ๐ŸŒ

## A Production-Grade WebSocket-Powered Messaging Platform

![React](https://img.shields.io/badge/React-19.x-61DAFB?style=for-the-badge&logo=react&logoColor=black)
![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6?style=for-the-badge&logo=typescript&logoColor=white)
![Node.js](https://img.shields.io/badge/Node.js-18%2B-339933?style=for-the-badge&logo=node.js&logoColor=white)
![Socket.IO](https://img.shields.io/badge/Socket.IO-4.x-010101?style=for-the-badge&logo=socket.io&logoColor=white)
![Vite](https://img.shields.io/badge/Vite-5.x-646CFF?style=for-the-badge&logo=vite&logoColor=white)
![Tailwind CSS](https://img.shields.io/badge/Tailwind-3.x-38B2AC?style=for-the-badge&logo=tailwind-css&logoColor=white)
![License](https://img.shields.io/badge/License-MIT-green?style=for-the-badge)

### **Built with Modern Web Technologies:**

![WebSockets](https://img.shields.io/badge/WebSockets-Real_Time-FF6B6B?style=flat-square&logo=websocket&logoColor=white)
![Event-Driven](https://img.shields.io/badge/Event-Driven-Architecture-4CAF50?style=flat-square&logo=events&logoColor=white)
![Bidirectional](https://img.shields.io/badge/Bidirectional-Communication-1E90FF?style=flat-square&logo=exchange&logoColor=white)
![Type Safety](https://img.shields.io/badge/Type-Safe-Full-3178C6?style=flat-square&logo=typescript&logoColor=white)

---

## ๐Ÿ“‹ Table of Contents

- [๐Ÿ’ฌ Real-Time Chat Application ๐ŸŒ](#-real-time-chat-application-)
- [A Production-Grade WebSocket-Powered Messaging Platform](#a-production-grade-websocket-powered-messaging-platform)
- [**Built with Modern Web Technologies:**](#built-with-modern-web-technologies)
- [๐Ÿ“‹ Table of Contents](#-table-of-contents)
- [๐ŸŽฏ Project Overview](#-project-overview)
- [Key Differentiators](#key-differentiators)
- [โœจ Features](#-features)
- [๐Ÿ› ๏ธ Tech Stack](#๏ธ-tech-stack)
- [Frontend](#frontend)
- [Backend](#backend)
- [๐Ÿ—๏ธ System Architecture](#๏ธ-system-architecture)
- [๐Ÿ“ Project Structure](#-project-structure)
- [๐ŸŽจ Core Features Deep Dive](#-core-features-deep-dive)
- [1. Real-Time Messaging ๐Ÿ’ฌ](#1-real-time-messaging-)
- [2. Room-Based Communication ๐Ÿ ](#2-room-based-communication-)
- [3. Typing Indicators โŒจ๏ธ](#3-typing-indicators-๏ธ)
- [4. Live User Tracking ๐Ÿ‘ฅ](#4-live-user-tracking-)
- [5. Message History ๐Ÿ“œ](#5-message-history-)
- [๐Ÿ”Œ Socket Events](#-socket-events)
- [Client โ†’ Server Events](#client--server-events)
- [Server โ†’ Client Events](#server--client-events)
- [๐Ÿ›๏ธ Backend Architecture](#๏ธ-backend-architecture)
- [Layered Design](#layered-design)
- [Service Layer Example](#service-layer-example)
- [๐ŸŽญ Frontend Architecture](#-frontend-architecture)
- [Component Hierarchy](#component-hierarchy)
- [Context Structure](#context-structure)
- [Custom Hooks](#custom-hooks)
- [โš™๏ธ Installation \& Setup](#๏ธ-installation--setup)
- [Prerequisites](#prerequisites)
- [Quick Start](#quick-start)
- [๐Ÿ”ง Configuration](#-configuration)
- [Backend Environment (.env)](#backend-environment-env)
- [Frontend Environment (.env)](#frontend-environment-env)
- [๐Ÿ“Š Validation Rules](#-validation-rules)
- [Validation Implementation](#validation-implementation)
- [๐ŸŽจ User Experience Highlights](#-user-experience-highlights)
- [๐Ÿ“ˆ Performance Optimizations](#-performance-optimizations)
- [๐Ÿ”ฎ Future Roadmap](#-future-roadmap)
- [๐Ÿ“š Learning Outcomes](#-learning-outcomes)
- [๐Ÿ‘จโ€๐Ÿ’ป Author](#-author)
- [**Elysรฉe NIYIBIZI**](#elysรฉe-niyibizi)
- [๐Ÿ“„ License](#-license)
- [๐Ÿ™ Acknowledgments](#-acknowledgments)
- [โญ Star this repository if it helped you learn real-time application development!](#-star-this-repository-if-it-helped-you-learn-real-time-application-development)

---

## ๐ŸŽฏ Project Overview

A **production-ready real-time chat platform** demonstrating modern WebSocket architecture, full-stack TypeScript development, and responsive UI design. This application enables users to join chat rooms, exchange messages instantly, view active participants, and experience seamless live communication.

### Key Differentiators

| Aspect | Implementation |
| -------------------- | ------------------------------------- |
| **Communication** | Real-time WebSocket with Socket.IO |
| **Architecture** | Clean separation of concerns |
| **Type Safety** | Full TypeScript across stack |
| **State Management** | React Context API |
| **Styling** | Responsive Tailwind CSS |
| **Persistence** | In-memory with planned DB integration |

---

## โœจ Features

| Category | Feature | Status |
| ------------------------- | -------------------------------- | ------ |
| **Messaging** | Real-time message exchange | โœ… |
| **Rooms** | Multiple chat rooms support | โœ… |
| **User Tracking** | Live participant list per room | โœ… |
| **Typing Indicators** | Real-time typing status | โœ… |
| **Message History** | Previous conversations per room | โœ… |
| **Auto-Scroll** | Automatic scroll to new messages | โœ… |
| **System Notifications** | Join/leave event broadcasting | โœ… |
| **Username Persistence** | Local storage username storage | โœ… |
| **Connection Monitoring** | Real-time connection status | โœ… |
| **Responsive Design** | Mobile, tablet, desktop support | โœ… |
| **Type Safety** | Full TypeScript implementation | โœ… |
| **Toast Notifications** | User-friendly feedback system | โœ… |

---

## ๐Ÿ› ๏ธ Tech Stack

### Frontend

| Technology | Version | Purpose | Badge |
| -------------------- | ------- | ------------- | ------------------------------------------------------------------------------------------------- |
| **React** | 19.x | UI Library | ![React](https://img.shields.io/badge/React-19.x-61DAFB?logo=react&logoColor=black) |
| **TypeScript** | 5.x | Type Safety | ![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6?logo=typescript&logoColor=white) |
| **Vite** | 5.x | Build Tool | ![Vite](https://img.shields.io/badge/Vite-5.x-646CFF?logo=vite&logoColor=white) |
| **Tailwind CSS** | 3.x | Styling | ![Tailwind](https://img.shields.io/badge/Tailwind-3.x-38B2AC?logo=tailwind-css&logoColor=white) |
| **Socket.IO Client** | 4.x | Real-time | ![Socket.IO](https://img.shields.io/badge/Socket.IO-4.x-010101?logo=socket.io&logoColor=white) |
| **React Hot Toast** | 2.x | Notifications | ![Toast](https://img.shields.io/badge/Toast-2.x-FF5F6D?logo=react&logoColor=white) |

### Backend

| Technology | Version | Purpose | Badge |
| -------------- | ------- | ------------------ | ------------------------------------------------------------------------------------------------- |
| **Node.js** | 18+ | Runtime | ![Node.js](https://img.shields.io/badge/Node.js-18%2B-339933?logo=node.js&logoColor=white) |
| **Express.js** | 4.x | Web Framework | ![Express](https://img.shields.io/badge/Express-4.x-000000?logo=express&logoColor=white) |
| **Socket.IO** | 4.x | WebSocket Server | ![Socket.IO](https://img.shields.io/badge/Socket.IO-4.x-010101?logo=socket.io&logoColor=white) |
| **TypeScript** | 5.x | Type Safety | ![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6?logo=typescript&logoColor=white) |
| **dotenv** | 16.x | Environment Config | ![dotenv](https://img.shields.io/badge/dotenv-16.x-ECD53F?logo=dotenv&logoColor=black) |

---

## ๐Ÿ—๏ธ System Architecture

```console
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ FRONTEND (React) โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ UI Components โ”‚ โ”‚
โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚
โ”‚ โ”‚ โ”‚RoomList โ”‚ โ”‚MessageListโ”‚ โ”‚MessageInputโ”‚ โ”‚ChatHeaderโ”‚ โ”‚UsernameFormโ”‚ โ”‚ โ”‚
โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚ โ”‚ โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ Context API โ”‚ โ”‚
โ”‚ โ”‚ โ€ข ChatContext (messages, users, typing status) โ”‚ โ”‚
โ”‚ โ”‚ โ€ข SocketContext (connection management) โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚ โ”‚ โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ Socket.IO Client โ”‚ โ”‚
โ”‚ โ”‚ โ€ข Emits events to server โ”‚ โ”‚
โ”‚ โ”‚ โ€ข Listens for server events โ”‚ โ”‚
โ”‚ โ”‚ โ€ข Manages reconnection โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚
WebSocket (ws:// or wss://)
โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ BACKEND (Node.js) โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ Socket.IO Server โ”‚ โ”‚
โ”‚ โ”‚ โ€ข Manages client connections โ”‚ โ”‚
โ”‚ โ”‚ โ€ข Routes events to handlers โ”‚ โ”‚
โ”‚ โ”‚ โ€ข Broadcasts to rooms โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚ โ”‚ โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ Services Layer โ”‚ โ”‚
โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚
โ”‚ โ”‚ โ”‚RoomService โ”‚ โ”‚MessageServiceโ”‚ โ”‚UserService โ”‚ โ”‚ โ”‚
โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚ โ”‚ โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ Data Models โ”‚ โ”‚
โ”‚ โ”‚ โ€ข Room (id, name, users, messages) โ”‚ โ”‚
โ”‚ โ”‚ โ€ข Message (id, userId, text, timestamp) โ”‚ โ”‚
โ”‚ โ”‚ โ€ข User (id, username, roomId) โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

---

## ๐Ÿ“ Project Structure

```console
real-time-chat-app/
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ backend/ # Node.js + Express + Socket.IO
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ config/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ constants.ts # Application constants
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ models/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ room.model.ts # Room data structure
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ message.model.ts # Message data structure
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ user.model.ts # User data structure
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ services/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ room.service.ts # Room business logic
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ message.service.ts # Message business logic
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ user.service.ts # User business logic
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ sockets/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ chat.socket.ts # Socket event handlers
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ types/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ index.ts # TypeScript interfaces
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ utils/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ validators.ts # Input validation
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ app.ts # Express app configuration
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ server.ts # Server entry point
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ package.json # Backend dependencies
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ tsconfig.json # TypeScript config
โ”‚ โ””โ”€โ”€ ๐Ÿ“„ .env # Environment variables
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ frontend/ # React + Vite + Tailwind
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ components/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ Chat/
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ ChatContainer.tsx
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ MessageList.tsx
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ MessageInput.tsx
โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ TypingIndicator.tsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ Room/
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ RoomList.tsx
โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ RoomItem.tsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ Layout/
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ ChatHeader.tsx
โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ Sidebar.tsx
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“ UI/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ ConnectionStatus.tsx
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ UsernameForm.tsx
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ context/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ ChatContext.tsx # Chat state management
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ SocketContext.tsx # Socket connection management
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ hooks/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ useSocket.ts # Socket lifecycle hook
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ useLocalStorage.ts # Persistent storage hook
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ layouts/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ MainLayout.tsx # App layout wrapper
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ services/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ socket.ts # Socket client initialization
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ types/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ index.ts # TypeScript interfaces
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ App.tsx # Root component
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ main.tsx # Entry point
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ public/ # Static assets
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ package.json # Frontend dependencies
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ vite.config.ts # Vite configuration
โ”‚ โ””โ”€โ”€ ๐Ÿ“„ .env # Environment variables
โ”‚
โ”œโ”€โ”€ ๐Ÿ“„ .gitignore # Git ignore rules
โ””โ”€โ”€ ๐Ÿ“„ README.md # Documentation
```

---

## ๐ŸŽจ Core Features Deep Dive

### 1. Real-Time Messaging ๐Ÿ’ฌ

Users send and receive messages instantly using WebSockets powered by Socket.IO.

```typescript
// Client sends message
socket.emit("send_message", { roomId, message, username });

// Server broadcasts to room
io.to(roomId).emit("receive_message", {
id: uuid(),
username,
text: message,
timestamp: new Date(),
});
```

### 2. Room-Based Communication ๐Ÿ 

Users join independent chat rooms for organized conversations.

```typescript
// Join room
socket.emit("join_room", { roomId, username });

// Server manages room membership
socket.join(roomId);
io.to(roomId).emit("user_joined", { username });
```

### 3. Typing Indicators โŒจ๏ธ

Real-time typing status shows who is actively typing.

```typescript
// Client on keypress
socket.emit("start_typing", { roomId, username });

// Server broadcasts
socket.broadcast.to(roomId).emit("user_typing", { username });
```

### 4. Live User Tracking ๐Ÿ‘ฅ

Each room displays all currently connected users.

```typescript
// Track users per room
const roomUsers = new Map>();

// Broadcast updates
io.to(roomId).emit("room_users", Array.from(roomUsers.get(roomId)));
```

### 5. Message History ๐Ÿ“œ

Users receive previous conversation history when joining.

```typescript
// Store messages per room
const messageHistory = new Map();

// Send history on join
socket.emit("message_history", messageHistory.get(roomId));
```

---

## ๐Ÿ”Œ Socket Events

### Client โ†’ Server Events

| Event | Payload | Description |
| -------------- | ------------------------------------------------------- | ------------------------- |
| `get_rooms` | `{}` | Fetch all available rooms |
| `join_room` | `{ roomId: string, username: string }` | Join a specific room |
| `send_message` | `{ roomId: string, message: string, username: string }` | Send a message to room |
| `start_typing` | `{ roomId: string, username: string }` | Notify typing started |
| `stop_typing` | `{ roomId: string, username: string }` | Notify typing stopped |

### Server โ†’ Client Events

| Event | Payload | Description |
| ----------------- | ---------------------- | --------------------------- |
| `rooms_list` | `Room[]` | List of available rooms |
| `receive_message` | `Message` | Incoming message |
| `message_history` | `Message[]` | Previous room messages |
| `room_users` | `User[]` | Active room participants |
| `user_joined` | `{ username: string }` | User joined notification |
| `user_left` | `{ username: string }` | User left notification |
| `user_typing` | `{ username: string }` | Typing activity indicator |
| `error` | `{ message: string }` | Validation or server errors |

---

## ๐Ÿ›๏ธ Backend Architecture

### Layered Design

| Layer | Responsibility | Files |
| ------------ | ----------------------------------- | ---------------- |
| **Config** | Application constants & environment | `constants.ts` |
| **Models** | Data structures & interfaces | `*.model.ts` |
| **Services** | Business logic & data management | `*.service.ts` |
| **Sockets** | Event handlers & communication | `chat.socket.ts` |
| **Utils** | Helper functions & validators | `validators.ts` |
| **Types** | Shared TypeScript interfaces | `index.ts` |

### Service Layer Example

```typescript
// room.service.ts
export class RoomService {
private rooms: Map = new Map();

getAllRooms(): Room[] {
return Array.from(this.rooms.values());
}

getRoom(roomId: string): Room | undefined {
return this.rooms.get(roomId);
}

addUserToRoom(roomId: string, user: User): void {
const room = this.rooms.get(roomId);
if (room) {
room.users.push(user);
}
}
}
```

---

## ๐ŸŽญ Frontend Architecture

### Component Hierarchy

```console
App
โ”œโ”€โ”€ SocketProvider
โ”‚ โ””โ”€โ”€ ChatProvider
โ”‚ โ””โ”€โ”€ MainLayout
โ”‚ โ”œโ”€โ”€ Sidebar
โ”‚ โ”‚ โ”œโ”€โ”€ UsernameForm
โ”‚ โ”‚ โ””โ”€โ”€ RoomList
โ”‚ โ”‚ โ””โ”€โ”€ RoomItem[]
โ”‚ โ””โ”€โ”€ ChatContainer
โ”‚ โ”œโ”€โ”€ ChatHeader
โ”‚ โ”‚ โ”œโ”€โ”€ RoomName
โ”‚ โ”‚ โ””โ”€โ”€ ConnectionStatus
โ”‚ โ”œโ”€โ”€ MessageList
โ”‚ โ”‚ โ””โ”€โ”€ Message[]
โ”‚ โ”œโ”€โ”€ TypingIndicator
โ”‚ โ””โ”€โ”€ MessageInput
```

### Context Structure

```typescript
// ChatContext.tsx
interface ChatContextType {
currentRoom: Room | null;
messages: Message[];
users: User[];
typingUsers: string[];
sendMessage: (text: string) => void;
joinRoom: (roomId: string) => void;
startTyping: () => void;
stopTyping: () => void;
}
```

### Custom Hooks

```typescript
// useSocket.ts
export const useSocket = () => {
const [isConnected, setIsConnected] = useState(false);

useEffect(() => {
socket.on("connect", () => setIsConnected(true));
socket.on("disconnect", () => setIsConnected(false));

return () => {
socket.off("connect");
socket.off("disconnect");
};
}, []);

return { socket, isConnected };
};
```

---

## โš™๏ธ Installation & Setup

### Prerequisites

- โœ… **Node.js** (v18 or higher)
- โœ… **npm** or **yarn** package manager
- โœ… **Git** (for cloning)
- โœ… **Modern web browser**

### Quick Start

```console
# 1. Clone the repository
git clone https://github.com/elyse502/real-time-chat-app.git

# 2. Navigate to project directory
cd real-time-chat-app

# 3. Setup Backend
cd backend
npm install
cp .env.example .env # Configure environment variables

# 4. Setup Frontend
cd ../frontend
npm install
cp .env.example .env # Configure environment variables

# 5. Run Development Servers
# Terminal 1 - Backend (from backend directory)
npm run dev

# Terminal 2 - Frontend (from frontend directory)
npm run dev

# 6. Open Application
# Frontend: http://localhost:5173
# Backend: http://localhost:3000
```

---

## ๐Ÿ”ง Configuration

### Backend Environment (.env)

```env
# Server Configuration
PORT=3000
NODE_ENV=development

# Client Configuration
CLIENT_URL=http://localhost:5173

# Socket Configuration
SOCKET_PING_TIMEOUT=60000
SOCKET_PING_INTERVAL=25000
```

### Frontend Environment (.env)

```env
# API Configuration
VITE_API_URL=http://localhost:3000

# Socket Configuration
VITE_SOCKET_PATH=/socket.io
```

---

## ๐Ÿ“Š Validation Rules

| Field | Type | Rules | Error Message |
| ------------ | ------ | --------------------------- | --------------------------------------------- |
| **Username** | string | Min: 3 chars, Max: 20 chars | "Username must be 3-20 characters" |
| **Message** | string | Min: 1 char, Max: 500 chars | "Message cannot be empty or exceed 500 chars" |
| **Room ID** | string | Must exist in system | "Room does not exist" |

### Validation Implementation

```typescript
// Backend validator
export const validateUsername = (username: string): boolean => {
return username.length >= 3 && username.length <= 20;
};

export const validateMessage = (message: string): boolean => {
return message.length >= 1 && message.length <= 500;
};
```

---

## ๐ŸŽจ User Experience Highlights

| Feature | Implementation | Benefit |
| ------------------------- | ---------------------------------- | -------------------------- |
| **Auto-Scroll** | `scrollIntoView()` on new messages | Always see latest messages |
| **Toast Notifications** | React Hot Toast | Non-intrusive feedback |
| **Connection Monitoring** | Socket event listeners | Real-time status awareness |
| **Typing Indicators** | Debounced emit events | Reduced network traffic |
| **Room Updates** | Real-time participant lists | Always accurate user count |
| **Responsive Layout** | Tailwind breakpoints | Works on all devices |
| **Username Persistence** | LocalStorage | No re-entry on refresh |

---

## ๐Ÿ“ˆ Performance Optimizations

| Optimization | Implementation | Impact |
| ---------------------- | ------------------------------ | ---------------------------- |
| **Message Throttling** | Rate limiting per user | Prevents spam |
| **Debounced Typing** | 300ms debounce | Reduces 90% of typing events |
| **Virtual Scrolling** | For large message history | Smooth rendering |
| **Lazy Loading** | Code splitting with React.lazy | Faster initial load |
| **Socket Compression** | perMessageDeflate enabled | Reduced bandwidth |
| **Connection Pooling** | Reuse socket connections | Lower memory usage |

---

## ๐Ÿ”ฎ Future Roadmap

| Feature | Priority | Description |
| -------------------------- | -------- | --------------------------- |
| ๐Ÿ” **JWT Authentication** | High | Secure user authentication |
| ๐Ÿ—„๏ธ **MongoDB Persistence** | High | Persistent message storage |
| ๐Ÿ’ฌ **Private Messaging** | High | Direct user-to-user chats |
| ๐Ÿ“Ž **File Sharing** | Medium | Image and file attachments |
| ๐Ÿณ **Docker Support** | Medium | Containerized deployment |
| ๐Ÿ“Š **Redis Scaling** | Medium | Horizontal scaling support |
| ๐Ÿงช **Testing Suite** | Medium | Unit & integration tests |
| ๐Ÿ”„ **CI/CD Pipeline** | Low | Automated deployment |
| ๐Ÿ˜Š **Message Reactions** | Low | Emoji reactions to messages |
| ๐Ÿ‘ค **User Avatars** | Low | Profile pictures |

---

## ๐Ÿ“š Learning Outcomes

This project demonstrates practical experience with:

| Category | Skills Demonstrated |
| --------------------- | -------------------------------------- |
| **WebSockets** | Real-time, bidirectional communication |
| **Full-Stack** | End-to-end TypeScript development |
| **Socket.IO** | Event handling, rooms, broadcasting |
| **React** | Hooks, Context API, components |
| **Architecture** | Separation of concerns, modular design |
| **State Management** | Context, local storage |
| **Type Safety** | Full TypeScript implementation |
| **Real-Time Systems** | Event-driven architecture |
| **Responsive Design** | Mobile-first approach |

---

## ๐Ÿ‘จโ€๐Ÿ’ป Author

### **Elysรฉe NIYIBIZI**

_Junior Fullstack Software Engineer_

[![Portfolio](https://img.shields.io/badge/Portfolio-elyseedev.netlify.app-000000?style=for-the-badge&logo=vercel&logoColor=white)](https://elyseedev.netlify.app)
[![GitHub](https://img.shields.io/badge/GitHub-elyse502-181717?style=for-the-badge&logo=github&logoColor=white)](https://github.com/elyse502)
[![LinkedIn](https://img.shields.io/badge/LinkedIn-Niyibizi_Elysรฉe-0A66C2?style=for-the-badge&logo=linkedin&logoColor=white)](https://linkedin.com/in/niyibizi-elysรฉe)
[![Email](https://img.shields.io/badge/Email-elyseniyibizi502@gmail.com-D14836?style=for-the-badge&logo=gmail&logoColor=white)](mailto:elyseniyibizi502@gmail.com)

**Specialties:**

- Backend Development
- Real-Time Systems
- TypeScript Applications
- MERN Stack Development

---

## ๐Ÿ“„ License

This project is licensed under the **MIT License** - see the [LICENSE](https://github.com/elyse502/real-time-chat-app/blob/main/LICENSE) file for details.

```
MIT License

Copyright (c) 2026 Elysรฉe NIYIBIZI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction...
```

---

## ๐Ÿ™ Acknowledgments

- **Socket.IO Team** - For the incredible real-time library
- **React Team** - For the amazing UI framework
- **TypeScript Team** - For type safety across the stack
- **Open Source Community** - For continuous inspiration

---

### โญ Star this repository if it helped you learn real-time application development!

**Built with ๐Ÿ’ป, WebSockets, and Real-Time Passion**

---

_From concept to production - a complete real-time chat platform demonstrating modern web architecture_

[โฌ† Back to Top](#-table-of-contents)