A full-stack real-time chat application built with React, TypeScript, Socket.IO, and Express.
- Real-time messaging using WebSockets via Socket.IO
- Room-based chat system with unique room codes
- User presence indicators showing who is in the room
- System messages for user join/leave events
- Visual user identification with color-coded avatars
- Responsive design for desktop and mobile devices
- React 19
- TypeScript
- React Router v7
- Socket.IO Client
- TailwindCSS v4
- Vite
- Node.js
- Express
- Socket.IO
- TypeScript
chat-room-websockets/
├── frontend/ # React frontend application
│ ├── src/
│ │ ├── components/ # Reusable UI components
│ │ ├── hooks/ # Custom React hooks
│ │ ├── pages/ # Page components
│ │ └── App.tsx # Main application component
│ └── ...
└── backend/ # Node.js backend application
├── src/
│ ├── socket/ # WebSocket handling
│ └── index.ts # Main server entry point
└── ...
- Node.js (v16+)
- npm or yarn
-
Clone the repository
git clone https://github.com/yourusername/chat-room-websockets.git cd chat-room-websockets -
Install dependencies
# Install root dependencies npm install # Install frontend dependencies cd frontend npm install # Install backend dependencies cd ../backend npm install
-
Start the backend server
cd backend npm run dev -
In a new terminal, start the frontend development server
cd frontend npm run dev -
Open your browser and navigate to
http://localhost:5173
-
Build the entire application
npm run build
-
Start the production server
npm start
- Enter your name on the homepage
- Choose to create a new room or join an existing one
- For joining, enter the room code provided by the room creator
- Start chatting in real-time with other users in the room
The application uses Socket.IO to establish WebSocket connections between the client and server. Events are emitted and listened to on both ends to facilitate real-time communication.
Main socket events:
join-room: When a user enters a roomleave-room: When a user leaves a roomsend-message: When a user sends a messagereceive-message: When a message is receivedroom-users: Updates the list of users in a roomuser-joined/user-left: System notifications
