Projects

Real time chat app

2023·1 min read

React
JavaScript
Styled Components
CRA
MongoDB
Express
Socket.io
LinkGitHub

A full-stack chat playground built to learn WebSocket-based messaging end-to-end. The client (client/) is a Create React App single-page app; the server (server/ + index.js) is an Express API that handles auth and message persistence and runs a Socket.io gateway for instant delivery between online users.

Real-Time Chat App

WhatsApp-style real-time chat — React + Styled Components on the client, Node/Express/MongoDB + Socket.io on the server, all in one monorepo.

Try it live

A full-stack chat playground built to learn WebSocket-based messaging end-to-end. The client (client/) is a Create React App single-page app; the server (server/ + index.js) is an Express API that handles auth and message persistence and runs a Socket.io gateway for instant delivery between online users.

Features

  • Email/username register & login with bcrypt-hashed passwords
  • Avatar picker (random SVG avatars via multiavatar.com)
  • 1-on-1 real-time messaging over Socket.io with an online-users map
  • Message history persisted in MongoDB and replayed on conversation open
  • Emoji picker in the composer (emoji-picker-react)
  • Toast notifications for auth and validation errors (react-toastify)
  • React Router v6 routing across Login / Register / Set Avatar / Chat
  • Production mode serves the built client straight from the Express app

Tech Stack

Client — React 17 (CRA) · Styled Components · React Router v6 · Axios · socket.io-client · emoji-picker-react · react-toastify

Server — Node.js · Express · Mongoose / MongoDB · socket.io · bcrypt · cors · dotenv

Tooling — nodemon · concurrently

Project Structure

.
├── index.js              # Express + Socket.io entry
├── server/
│   ├── controllers/      # userController, messageController
│   ├── models/           # User, Message (Mongoose)
│   └── routes/           # /api/auth, /api/messages
└── client/               # Create React App frontend
    └── src/
        ├── pages/        # Login, Register, Chat
        ├── components/   # ChatContainer, ChatInput, Contacts, SetAvatar, ...
        └── utils/        # APIRoutes

API

Method Route Purpose
POST /api/auth/register Create a new user
POST /api/auth/login Log in
GET /api/auth/logout/:id Log out
GET /api/auth/allusers/:id List other users
POST /api/auth/setavatar/:id Save selected avatar
POST /api/messages/addmsg Persist a message
POST /api/messages/getmsg Load a conversation

Socket events: add-user, send-msg, msg-recieve.

Credits

Built by Mohamed Gado.

More projects

  • Ecommerce App2022 · React
  • Simple Time Logger2023 · React
  • Full-Stack Movie App2022 · Spring Boot
All projects