A modern, real-time messaging application built with React and Node.js featuring user authentication, real-time messaging, and a beautiful responsive UI.
- β 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
Frontend:
- React 18
- Tailwind CSS
- Axios
- Lucide React (icons)
Backend:
- Node.js
- Express.js
- JWT authentication
- bcrypt for password hashing
- File-based storage (JSON)
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
- Node.js 16+ and npm installed
- Two terminal windows
# Navigate to backend directory
cd backend
# Install dependencies
npm install
# Start the server
npm startThe backend will run on http://localhost:5000
# Open a new terminal and navigate to frontend directory
cd frontend
# Install dependencies
npm install
# Start the React app
npm startThe frontend will run on http://localhost:3000
- Docker and Docker Compose installed
# From the root directory, build and start all services
docker-compose up --build
# Or run in detached mode
docker-compose up -d --buildAccess the application:
- Frontend:
http://localhost:3000 - Backend API:
http://localhost:5000
To stop the containers:
docker-compose downPOST /api/register
Content-Type: application/json
{
"username": "johndoe",
"password": "password123",
"fullName": "John Doe"
}POST /api/login
Content-Type: application/json
{
"username": "johndoe",
"password": "password123"
}GET /api/users
Authorization: Bearer <token>GET /api/users/:id
Authorization: Bearer <token>POST /api/messages
Authorization: Bearer <token>
Content-Type: application/json
{
"receiverId": "user-id",
"content": "Hello!"
}GET /api/messages/:userId
Authorization: Bearer <token>- Users can register with username, password, and full name
- Secure password hashing with bcrypt
- JWT token-based authentication
- Tokens stored in localStorage
- 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
- Real-time message updates (polling every 3 seconds)
- Message history persistence
- Auto-scroll to latest messages
- Visual distinction between sent and received messages
- Online/offline indicators
- Avatar placeholders with colored backgrounds
- User initials display
PORT=5000
JWT_SECRET=your_super_secret_jwt_key_change_this_in_production
NODE_ENV=developmentREACT_APP_API_URL=http://localhost:5000/api- Register: Create a new account with username and password
- Login: Sign in with your credentials
- Select User: Click on any user from the sidebar
- Chat: Start sending messages!
- Search: Use the search bar to find specific users
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# Clean up Docker containers and images
docker-compose down -v
docker system prune -a
# Rebuild from scratch
docker-compose up --build --force-recreate- Ensure backend is running on port 5000
- Check CORS configuration in server.js
- Verify JWT_SECRET is set in .env
- Check proxy configuration in package.json (dev)
- Verify nginx.conf (Docker)
- Check browser console for specific errors
- Change the JWT_SECRET to a strong, random string
- Use HTTPS for all communications
- Implement rate limiting
- Add input validation and sanitization
- Use a proper database (PostgreSQL, MongoDB)
- Implement proper session management
- Add CSRF protection
-
Update Environment Variables
- Set strong JWT_SECRET
- Configure proper API URLs
- Set NODE_ENV=production
-
Build Frontend
cd frontend
npm run build- Use Docker Compose
docker-compose -f docker-compose.yml up -d- Use a Reverse Proxy (Nginx/Apache)
- Configure SSL certificates
- Set up domain routing
- Enable gzip compression
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
Built with β€οΈ using React and Node.js
- 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! π¬