A full-stack real-time chat application built with React, Node.js, Socket.IO, and PostgreSQL.
- User Authentication - Register, login, logout with JWT tokens
- Real-Time Messaging - Instant message delivery using Socket.IO
- One-on-One Chats - Private conversations between two users
- Group Chats - Create groups with multiple participants, leave groups
- Typing Indicators - See when someone is typing (in chat window and sidebar)
- Read Receipts - Single check (โ) for sent, double check (โโ) for read
- Online/Offline Status - Real-time user presence updates
- Unread Message Count - Badge showing number of unread messages per conversation
- Profile Avatars - Upload and display custom profile pictures
- Image/File Sharing - Send images and documents (PDF, DOC, TXT, etc.)
- Dark Mode - Toggle between light and dark themes
- Browser Notifications - Get notified of new messages even when tab is inactive
- Message Sorting - Conversations sorted by most recent message
- React 19 - UI library
- Vite - Build tool and dev server
- Tailwind CSS v4 - Styling
- Socket.IO Client - Real-time communication
- Axios - HTTP requests
- React Router DOM - Client-side routing
- Node.js - Runtime environment
- Express 5 - Web framework
- Socket.IO - WebSocket server
- Prisma 5 - ORM for database
- PostgreSQL - Database
- JWT - Authentication tokens
- bcryptjs - Password hashing
- Multer - File uploads
chat-app/
โโโ client/ # Frontend (React)
โ โโโ src/
โ โ โโโ components/ # Reusable UI components
โ โ โ โโโ Avatar.jsx
โ โ โ โโโ AvatarUpload.jsx
โ โ โ โโโ ChatWindow.jsx
โ โ โ โโโ CreateGroupModal.jsx
โ โ โ โโโ Sidebar.jsx
โ โ โโโ context/ # React Context providers
โ โ โ โโโ AuthContext.jsx
โ โ โ โโโ SocketContext.jsx
โ โ โ โโโ ThemeContext.jsx
โ โ โโโ hooks/ # Custom hooks
โ โ โ โโโ useNotification.js
โ โ โโโ pages/ # Page components
โ โ โ โโโ Chat.jsx
โ โ โ โโโ Login.jsx
โ โ โ โโโ Register.jsx
โ โ โโโ utils/ # Utilities
โ โ โ โโโ api.js
โ โ โโโ App.jsx
โ โ โโโ main.jsx
โ โ โโโ main.css
โ โโโ package.json
โ โโโ vite.config.js
โ
โโโ server/ # Backend (Node.js)
โ โโโ prisma/
โ โ โโโ schema.prisma # Database schema
โ โ โโโ migrations/ # Database migrations
โ โโโ src/
โ โ โโโ controllers/ # Route handlers
โ โ โ โโโ authControllers.js
โ โ โ โโโ chatController.js
โ โ โโโ middleware/ # Express middleware
โ โ โ โโโ auth.js
โ โ โ โโโ upload.js
โ โ โโโ routes/ # API routes
โ โ โ โโโ authRoutes.js
โ โ โ โโโ chatRoutes.js
โ โ โโโ socket/ # Socket.IO handlers
โ โ โ โโโ socketHandler.js
โ โ โโโ lib/
โ โ โโโ prisma.js
โ โโโ uploads/ # Uploaded files
โ โ โโโ avatars/
โ โ โโโ messages/
โ โโโ app.js
โ โโโ server.js
โ โโโ package.json
โ โโโ .env
โ
โโโ README.md
- Node.js (v18 or higher)
- PostgreSQL (v14 or higher)
- npm or yarn
-
Clone the repository
git clone https://github.com/m-bwela/chat-app.git cd chat-app -
Set up the database
- Create a PostgreSQL database named
chatapp - Note your database port (default: 5432, this project uses: 5433)
- Create a PostgreSQL database named
-
Set up the server
cd server npm install -
Configure environment variables
Create a
.envfile in theserverfolder:DATABASE_URL="postgresql://postgres:your_password@localhost:5433/chatapp" JWT_SECRET="your-secret-key-here" PORT=5000
-
Run database migrations
npx prisma migrate dev
-
Set up the client
cd ../client npm install
-
Start the server (Terminal 1)
cd server npm run devServer runs on: http://localhost:5000
-
Start the client (Terminal 2)
cd client npm run devClient runs on: http://localhost:5173
-
Open the app
- Navigate to http://localhost:5173
- Register two accounts to test messaging
- Use an incognito window for the second account
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register new user |
| POST | /api/auth/login |
Login user |
| POST | /api/auth/logout |
Logout user |
| GET | /api/auth/me |
Get current user |
| POST | /api/auth/avatar |
Upload avatar |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/chat/users |
Get all users |
| GET | /api/chat/conversations |
Get user's conversations |
| POST | /api/chat/conversations |
Create one-on-one chat |
| POST | /api/chat/conversations/group |
Create group chat |
| DELETE | /api/chat/conversations/:id/leave |
Leave group |
| GET | /api/chat/conversations/:id/messages |
Get messages |
| POST | /api/chat/messages |
Send text message |
| POST | /api/chat/messages/file |
Send file message |
| Event | Description |
|---|---|
authenticate |
Authenticate socket connection |
join-conversation |
Join a chat room |
leave-conversation |
Leave a chat room |
send-message |
Send a message |
typing-start |
User started typing |
typing-stop |
User stopped typing |
mark-read |
Mark messages as read |
| Event | Description |
|---|---|
new-message |
New message received |
user-online |
User came online |
user-offline |
User went offline |
user-typing |
User is typing |
user-stop-typing |
User stopped typing |
messages-read |
Messages were read |
user-avatar-updated |
User updated avatar |
model User {
id String @id @default(uuid())
username String @unique
email String @unique
passwordHash String
avatarUrl String?
isOnline Boolean @default(false)
lastSeen DateTime?
createdAt DateTime @default(now())
}
model Conversation {
id String @id @default(uuid())
name String?
isGroup Boolean @default(false)
createdAt DateTime @default(now())
}
model Message {
id String @id @default(uuid())
conversationId String
senderId String
content String?
fileUrl String?
fileName String?
fileType String?
fileMimeType String?
fileSize Int?
isRead Boolean @default(false)
createdAt DateTime @default(now())
}- Message search functionality
- Emoji picker
- Voice messages
- Video calls
- Message reactions
- Message editing/deletion
- Group admin features (add/remove members)
- Custom group avatars
- Message forwarding
- Deploy to cloud (Vercel + Railway)
m-bwela
- GitHub: @m-bwela
This project is open source and available under the MIT License.
Built with โค๏ธ using React, Node.js, and Socket.IO





