Skip to content

m-bwela/chat-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

27 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

i-ONGEA - Real-Time Chat Application

A full-stack real-time chat application built with React, Node.js, Socket.IO, and PostgreSQL.

Chat App React Node.js Socket.IO PostgreSQL

โœจ Features

Core Features

  • 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

Enhanced Features

  • 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

๐Ÿ› ๏ธ Tech Stack

Frontend

  • 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

Backend

  • 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

๐Ÿ“ Project Structure

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

๐Ÿš€ Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • PostgreSQL (v14 or higher)
  • npm or yarn

Installation

  1. Clone the repository

    git clone https://github.com/m-bwela/chat-app.git
    cd chat-app
  2. Set up the database

    • Create a PostgreSQL database named chatapp
    • Note your database port (default: 5432, this project uses: 5433)
  3. Set up the server

    cd server
    npm install
  4. Configure environment variables

    Create a .env file in the server folder:

    DATABASE_URL="postgresql://postgres:your_password@localhost:5433/chatapp"
    JWT_SECRET="your-secret-key-here"
    PORT=5000
  5. Run database migrations

    npx prisma migrate dev
  6. Set up the client

    cd ../client
    npm install

Running the Application

  1. Start the server (Terminal 1)

    cd server
    npm run dev

    Server runs on: http://localhost:5000

  2. Start the client (Terminal 2)

    cd client
    npm run dev

    Client runs on: http://localhost:5173

  3. Open the app

    • Navigate to http://localhost:5173
    • Register two accounts to test messaging
    • Use an incognito window for the second account

๐Ÿ“ก API Endpoints

Authentication

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

Chat

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

๐Ÿ”Œ Socket Events

Client โ†’ Server

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

Server โ†’ Client

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

๐Ÿ—ƒ๏ธ Database Schema

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())
}

๐ŸŽจ Screenshots

Login Page

Login

Chat Interface (Light Mode)

Chat Light Mode

Chat Interface (Dark Mode)

Chat Dark Mode

Group Chat

Group Chat

File & Image Sharing

File Image Sharing

Typing Indicator

Typing Indicator

๐Ÿ”ฎ Future Enhancements

  • 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)

๐Ÿ‘จโ€๐Ÿ’ป Author

m-bwela

๐Ÿ“„ License

This project is open source and available under the MIT License.


Built with โค๏ธ using React, Node.js, and Socket.IO

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages