A modern, real-time chat application built with React and Node.js, featuring WebSocket communication for instant messaging.
- π User authentication (register/login)
- π¬ Real-time messaging with WebSocket
- π₯ Online/offline user status
- π¨ Modern UI with Tailwind CSS
- π Secure password hashing with bcrypt
- πͺ JWT-based session management
- π± Responsive design
- ποΈ Account and message deletion
- React 19.2.0 - UI framework
- Vite 7.2.4 - Build tool
- Tailwind CSS 4.1.17 - Styling
- Axios - HTTP client
- WebSocket - Real-time communication
- Node.js with Express 5.2.1
- MongoDB with Mongoose 9.0.1
- WebSocket (ws) 8.18.3 - Real-time messaging
- JWT - Authentication
- bcrypt - Password hashing
treq/
βββ api/ # Backend server
β βββ config/
β β βββ database.js # MongoDB connection
β β βββ cors.js # CORS configuration
β βββ controllers/
β β βββ authController.js # Authentication logic
β β βββ userController.js # User management
β β βββ messageController.js # Message handling
β βββ middleware/
β β βββ auth.js # JWT verification
β β βββ errorHandler.js # Error handling
β βββ models/
β β βββ User.js # User schema
β β βββ Message.js # Message schema
β βββ routes/
β β βββ authRoutes.js # Auth endpoints
β β βββ userRoutes.js # User endpoints
β β βββ messageRoutes.js # Message endpoints
β βββ websocket/
β β βββ wsHandler.js # WebSocket logic
β βββ utils/
β β βββ constants.js # App constants
β βββ index.js # Server entry point
β βββ .env.example
β βββ package.json
β
βββ client/ # Frontend application
β βββ src/
β β βββ components/ # Reusable components
β β β βββ Avatar.jsx
β β β βββ Contact.jsx
β β β βββ Logo.jsx
β β β βββ Menu.jsx
β β β βββ Toast.jsx
β β βββ context/
β β β βββ UserContext.jsx
β β βββ pages/
β β β βββ Chat.jsx
β β β βββ RegisterAndLoginForm.jsx
β β βββ App.jsx
β β βββ Routes.jsx
β β βββ main.jsx
β β βββ index.css
β βββ public/
β βββ index.html
β βββ vite.config.js
β βββ .env.example
β βββ package.json
β
βββ README.md
- Node.js (v16 or higher)
- MongoDB Atlas account or local MongoDB installation
- npm or yarn
-
Clone the repository
git clone https://github.com/quacky20/Treq cd treq -
Backend Setup
cd api npm installCreate a
.envfile in theapidirectory:MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_secret_key_here CLIENT_URL=http://localhost:5173 PORT=4000
-
Frontend Setup
cd ../client npm installCreate a
.envfile in theclientdirectory:VITE_API_URL=http://localhost:4000 VITE_WS_URL=ws://localhost:4000
-
Start the backend server
cd api npm run devServer will run on
http://localhost:4000 -
Start the frontend (in a new terminal)
cd client npm run devApplication will run on
http://localhost:5173 -
Open your browser Navigate to
http://localhost:5173
POST /register- Register a new userPOST /login- Login userPOST /logout- Logout userGET /profile- Get current user profile
GET /messages/:userID- Get messages with a specific userDELETE /messages- Delete all user messages
GET /people- Get all registered usersDELETE /account- Delete user account
GET /test- Test endpointGET /health- Health check
- WebSocket connection for instant message delivery
- Automatic reconnection on connection loss
- Online/offline status indicators
- Secure password hashing
- JWT-based authentication
- Session persistence with cookies
- Clean, modern interface
- Toast notifications for user actions
- Responsive design for all devices
- Keyboard shortcuts (ESC to exit chat)
| Variable | Description |
|---|---|
MONGO_URI |
MongoDB connection string |
JWT_SECRET |
Secret key for JWT tokens |
CLIENT_URL |
Frontend URL for CORS |
PORT |
Server port (default: 4000) |
| Variable | Description |
|---|---|
VITE_API_URL |
Backend API URL |
VITE_WS_URL |
WebSocket server URL |
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Yours truly
- Material Symbols for icons
- Tailwind CSS for styling utilities
- MongoDB for database
- Vercel and Render for hosting
Made with β€οΈ