Skip to content

Latest commit

Β 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’¬ Messaging App - Full-Stack Chat Application

A modern, real-time messaging application built with React and Node.js featuring user authentication, real-time messaging, and a beautiful responsive UI.

πŸš€ Features

  • βœ… User registration and authentication with JWT
  • βœ… Real-time messaging between users
  • βœ… Modern, responsive chat interface
  • βœ… User search functionality
  • βœ… Online/offline status indicators
  • βœ… Message timestamps
  • βœ… Auto-scrolling chat window
  • βœ… Mobile-responsive design
  • βœ… Docker support for easy deployment

πŸ› οΈ Tech Stack

Frontend:

  • React 18
  • Tailwind CSS
  • Axios
  • Lucide React (icons)

Backend:

  • Node.js
  • Express.js
  • JWT authentication
  • bcrypt for password hashing
  • File-based storage (JSON)

πŸ“ Project Structure

messaging-app/
β”œβ”€β”€ backend/                 # Node.js backend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config/         # Configuration files
β”‚   β”‚   β”œβ”€β”€ middleware/     # Auth middleware
β”‚   β”‚   β”œβ”€β”€ models/         # Data models
β”‚   β”‚   β”œβ”€β”€ routes/         # API routes
β”‚   β”‚   └── server.js       # Entry point
β”‚   β”œβ”€β”€ data/               # JSON storage
β”‚   β”œβ”€β”€ Dockerfile
β”‚   └── package.json
β”‚
β”œβ”€β”€ frontend/               # React frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/    # React components
β”‚   β”‚   β”œβ”€β”€ context/       # Auth context
β”‚   β”‚   β”œβ”€β”€ services/      # API services
β”‚   β”‚   β”œβ”€β”€ utils/         # Helper functions
β”‚   β”‚   └── App.jsx
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ nginx.conf
β”‚   └── package.json
β”‚
└── docker-compose.yml     # Docker orchestration

πŸš€ Quick Start

Option 1: Using npm (Development)

Prerequisites

  • Node.js 16+ and npm installed
  • Two terminal windows

Backend Setup

# Navigate to backend directory
cd backend

# Install dependencies
npm install

# Start the server
npm start

The backend will run on http://localhost:5000

Frontend Setup

# Open a new terminal and navigate to frontend directory
cd frontend

# Install dependencies
npm install

# Start the React app
npm start

The frontend will run on http://localhost:3000

Option 2: Using Docker (Recommended for Production)

Prerequisites

  • Docker and Docker Compose installed

Run with Docker

# From the root directory, build and start all services
docker-compose up --build

# Or run in detached mode
docker-compose up -d --build

Access the application:

  • Frontend: http://localhost:3000
  • Backend API: http://localhost:5000

To stop the containers:

docker-compose down

πŸ“– API Documentation

Authentication Endpoints

Register User

POST /api/register
Content-Type: application/json

{
  "username": "johndoe",
  "password": "password123",
  "fullName": "John Doe"
}

Login

POST /api/login
Content-Type: application/json

{
  "username": "johndoe",
  "password": "password123"
}

User Endpoints (Requires Authentication)

Get All Users

GET /api/users
Authorization: Bearer <token>

Get User by ID

GET /api/users/:id
Authorization: Bearer <token>

Message Endpoints (Requires Authentication)

Send Message

POST /api/messages
Authorization: Bearer <token>
Content-Type: application/json

{
  "receiverId": "user-id",
  "content": "Hello!"
}

Get Conversation

GET /api/messages/:userId
Authorization: Bearer <token>

🎨 Features Walkthrough

1. Authentication

  • Users can register with username, password, and full name
  • Secure password hashing with bcrypt
  • JWT token-based authentication
  • Tokens stored in localStorage

2. User Interface

  • Login/Register Screen: Clean, gradient design with form validation
  • Sidebar: Shows all registered users with search functionality
  • Chat Window: Modern message bubbles with timestamps
  • Responsive: Works perfectly on mobile, tablet, and desktop

3. Messaging

  • Real-time message updates (polling every 3 seconds)
  • Message history persistence
  • Auto-scroll to latest messages
  • Visual distinction between sent and received messages

4. User Status

  • Online/offline indicators
  • Avatar placeholders with colored backgrounds
  • User initials display

πŸ”§ Configuration

Backend Configuration (.env)

PORT=5000
JWT_SECRET=your_super_secret_jwt_key_change_this_in_production
NODE_ENV=development

Frontend Configuration (.env)

REACT_APP_API_URL=http://localhost:5000/api

πŸ“± Screenshots & Usage

  1. Register: Create a new account with username and password
  2. Login: Sign in with your credentials
  3. Select User: Click on any user from the sidebar
  4. Chat: Start sending messages!
  5. Search: Use the search bar to find specific users

πŸ› Troubleshooting

Port Already in Use

If you get a port conflict:

# For backend (port 5000)
lsof -ti:5000 | xargs kill -9

# For frontend (port 3000)
lsof -ti:3000 | xargs kill -9

Docker Issues

# Clean up Docker containers and images
docker-compose down -v
docker system prune -a

# Rebuild from scratch
docker-compose up --build --force-recreate

Backend Not Connecting

  • Ensure backend is running on port 5000
  • Check CORS configuration in server.js
  • Verify JWT_SECRET is set in .env

Frontend API Errors

  • Check proxy configuration in package.json (dev)
  • Verify nginx.conf (Docker)
  • Check browser console for specific errors

πŸ” Security Notes

⚠️ Important for Production:

  1. Change the JWT_SECRET to a strong, random string
  2. Use HTTPS for all communications
  3. Implement rate limiting
  4. Add input validation and sanitization
  5. Use a proper database (PostgreSQL, MongoDB)
  6. Implement proper session management
  7. Add CSRF protection

πŸš€ Deployment

Deploy to Production

  1. Update Environment Variables

    • Set strong JWT_SECRET
    • Configure proper API URLs
    • Set NODE_ENV=production
  2. Build Frontend

cd frontend
npm run build
  1. Use Docker Compose
docker-compose -f docker-compose.yml up -d
  1. Use a Reverse Proxy (Nginx/Apache)
    • Configure SSL certificates
    • Set up domain routing
    • Enable gzip compression

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“ License

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

πŸ‘€ Author

Built with ❀️ using React and Node.js

πŸ™ Acknowledgments

  • React team for the amazing framework
  • Express.js for the backend framework
  • Tailwind CSS for the utility-first CSS
  • Lucide React for beautiful icons

Need Help? Open an issue or check the troubleshooting section above.

Happy Chatting! πŸ’¬

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages