Skip to content

VicVisjA/realtimechat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ’ฌ Real-Time Chat Application

A real-time chat application built using Node.js, Express, Socket.io, and Microsoft SQL Server. This project demonstrates how modern web applications handle live communication, server-side processing, and persistent data storage.

Designed as a portfolio project to demonstrate full-stack engineering skills, including WebSockets, backend architecture, and relational database integration.


๐Ÿš€ Features

  • โšก Real-time messaging using WebSockets
  • ๐Ÿ’พ Persistent chat history stored in SQL Server
  • ๐ŸŒ Multiple user support
  • ๐Ÿง  Event-driven architecture
  • ๐Ÿ”— Client-server communication using Socket.io

๐Ÿงฑ Tech Stack

Frontend

  • HTML
  • JavaScript
  • Socket.io Client

Backend

  • Node.js
  • Express.js
  • Socket.io

Database

  • Microsoft SQL Server

๐Ÿ“ Project Structure

chat-app
โ”‚
โ”œโ”€โ”€ server
โ”‚   โ”œโ”€โ”€ server.js
โ”‚   โ””โ”€โ”€ db.js
โ”‚
โ”œโ”€โ”€ client
โ”‚   โ”œโ”€โ”€ index.html
โ”‚   โ””โ”€โ”€ app.js
โ”‚
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ README.md

๐Ÿง  System Architecture

        Client Browser
        (index.html + app.js)
               โ”‚
               โ”‚ WebSocket Connection
               โ–ผ
        Socket.io Server
           (Node.js)
               โ”‚
               โ”‚ SQL Queries
               โ–ผ
      Microsoft SQL Server
         Messages Table

โš™๏ธ How It Works

1๏ธโƒฃ User Connects

When a user opens the application, the browser establishes a Socket.io connection with the server.

const socket = io();

This creates a persistent WebSocket channel between the client and server.


2๏ธโƒฃ Sending Messages

When a user submits a message:

socket.emit("chat message", { username, message });

The client emits a chat message event to the server.


3๏ธโƒฃ Server Processes the Message

The backend listens for incoming messages:

socket.on("chat message", async (data) => { ... });

The server:

  1. Receives the message
  2. Inserts the message into SQL Server
  3. Broadcasts it to all connected clients

4๏ธโƒฃ Database Storage

Messages are stored in the database using SQL queries:

INSERT INTO Messages (username, message)
VALUES (@username, @message)

This ensures chat history is persisted.


5๏ธโƒฃ Broadcasting Messages

After saving the message, the server sends it to every connected client:

io.emit("chat message", data);

This creates the real-time chat experience.


6๏ธโƒฃ Rendering Messages

The browser dynamically updates the chat interface:

const li = document.createElement("li");
li.textContent = data.username + ": " + data.message;
messages.appendChild(li);

Messages appear instantly without refreshing the page.


๐Ÿ”„ Application Data Flow

User Message
     โ”‚
     โ–ผ
Browser (Socket.io Client)
     โ”‚
     โ–ผ
Node.js Server
     โ”‚
     โ–ผ
SQL Server Database
     โ”‚
     โ–ผ
Broadcast to all clients
     โ”‚
     โ–ผ
Live Chat UI Update

๐Ÿงช Running the Project

Install dependencies

npm install

Start the server

node server/server.js

Open the application

http://localhost:3000

Open multiple browser tabs to test real-time messaging.


๐Ÿ“Š Database Schema

Messages
----------------------------
id          INT (Primary Key)
username    VARCHAR(50)
message     TEXT
created_at  DATETIME

๐Ÿ”ฎ Future Improvements

Possible enhancements for production-ready chat systems:

  • ๐Ÿ” User authentication (JWT)
  • ๐Ÿ’ฌ Chat rooms
  • ๐ŸŸข Online user indicators
  • โŒจ๏ธ Typing indicators
  • ๐Ÿ“œ Message history loading
  • ๐Ÿ“Ž File and image sharing
  • ๐ŸŽจ UI improvements with React or Tailwind

๐Ÿ“Œ Why This Project Matters

This project demonstrates several important software engineering concepts:

  • Real-time communication with WebSockets
  • Event-driven backend architecture
  • Persistent data storage with relational databases
  • Client-server communication patterns
  • Scalable chat application design

It serves as a solid example of building a full-stack real-time system from scratch.


Video

realtimechat.mp4

About

A real-time chat application built using Node.js, Express, Socket.io, and Microsoft SQL Server.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors