Skip to content
Laviyx Learn

Try

Final-year project

Real-Time Chat Application with Node.js and WebSockets

A full-stack chat app with sign-up, private and group chats, messages delivered instantly over WebSockets, online status, typing indicators, read receipts and stored message history.

Intermediate 8–10 weeks 2–4 studentsUpdated

Node.jsExpressSocket.IO or wsPostgreSQL or SQLiteHTML, CSS, JavaScript or React

The problem

Messaging apps feel instant because the server pushes new messages to you instead of you asking for them again and again. Building a chat app teaches the parts of a modern backend: authentication, a database, real-time connections, and what changes when many people are online at once.

Features to build

  • Sign up and log in, with passwords hashed using bcrypt
  • One-to-one chats and group rooms that users can create and join
  • Messages delivered instantly over WebSockets to everyone in the room
  • Messages saved in the database, with older history loaded as you scroll up
  • Online and offline status, and a 'typing…' indicator
  • Delivered and read receipts for one-to-one chats
  • Unread counts for each chat
  • Message text shown as plain text, never as HTML, to block script injection

Suggested data model

TableKey columns
usersid, name, email (unique), password_hash, last_seen_at
roomsid, name, is_group, created_by, created_at
room_membersroom_id, user_id, joined_at, last_read_message_id
messagesid, room_id, sender_id, body, created_at

Add an index on messages (room_id, created_at) so loading a chat's recent history stays fast as the table grows.

Build plan

  1. 1

    Build the REST API

    Create Express routes for sign-up, log-in, listing rooms and loading message history, with input validation and error handling.

  2. 2

    Add authentication

    Issue a session or JWT on log-in, and check it both on HTTP requests and when a WebSocket connects.

  3. 3

    Real-time messaging

    When a client sends a message, validate it, save it to the database, then broadcast it to the room's members. Send back the saved message ID as an acknowledgement.

  4. 4

    Presence and typing

    Track connected users in memory, broadcast online and offline changes, and send short-lived typing events that are never stored.

  5. 5

    History and receipts

    Load history in pages using the oldest loaded message as a cursor, and update last_read_message_id when a user views a chat.

  6. 6

    Test and deploy

    Test with several browser windows, write API tests, and deploy with environment variables for secrets.

Learn these first

Each part of the project is taught in one of these free lessons.

Make it stand out

  • Image and file sharing, with size and type checks
  • Search messages in a chat
  • Browser notifications for new messages
  • Run two server instances and connect them with Redis pub/sub so users on different servers can chat

Viva and interview questions

Try to answer each one aloud before you open it.

  • Why use WebSockets instead of the client asking the server every few seconds?

    Polling sends many requests that usually return nothing and still adds delay. A WebSocket keeps one connection open in both directions, so the server can push a message the moment it arrives, with far less overhead.

  • Why save a message before broadcasting it?

    If the server broadcast first and then crashed, people would see a message that was never stored and would disappear later. Saving first means everything shown has a permanent record and a real ID.

  • How do you stop someone from sending JavaScript inside a message?

    Treat message text as plain text: insert it with textContent in the browser, or let React escape it. Never insert it as HTML. Also validate length and type on the server.

  • How would this work with thousands of users on several servers?

    Each server only knows its own connections. A shared pub/sub channel such as Redis lets a server publish a new message, and every server forwards it to its own connected members of that room.

  • Why load history with a cursor instead of page numbers?

    New messages keep arriving, so 'page 2' changes as people chat and messages get skipped or repeated. Asking for messages older than a given message ID always returns the right next set.

What to put in your project report

  1. Abstract: the problem, your solution and the result in one paragraph.
  2. Introduction and problem statement: who has the problem and why it matters.
  3. Requirements: the features (functional) and qualities such as speed and security (non-functional).
  4. Design: architecture diagram, database tables or data flow, and screen layouts.
  5. Implementation: the main modules and the most interesting code, explained.
  6. Testing: the test cases you ran, with inputs, expected and actual results.
  7. Results: screenshots or numbers that show the project working.
  8. Conclusion and future scope: what you achieved and what you would add next.

Your college may give its own format. Follow that first, and use this list to check nothing is missing.

All project ideas →