Skip to content

quacky20/Treq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TREQ - Real-time Chat Application

A modern, real-time chat application built with React and Node.js, featuring WebSocket communication for instant messaging.

Features

  • πŸ” 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

Tech Stack

Frontend

  • 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

Backend

  • 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

Project Structure

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

Getting Started

Prerequisites

  • Node.js (v16 or higher)
  • MongoDB Atlas account or local MongoDB installation
  • npm or yarn

Installation

  1. Clone the repository

    git clone https://github.com/quacky20/Treq
    cd treq
  2. Backend Setup

    cd api
    npm install

    Create a .env file in the api directory:

    MONGO_URI=your_mongodb_connection_string
    JWT_SECRET=your_secret_key_here
    CLIENT_URL=http://localhost:5173
    PORT=4000
  3. Frontend Setup

    cd ../client
    npm install

    Create a .env file in the client directory:

    VITE_API_URL=http://localhost:4000
    VITE_WS_URL=ws://localhost:4000

Running the Application

  1. Start the backend server

    cd api
    npm run dev

    Server will run on http://localhost:4000

  2. Start the frontend (in a new terminal)

    cd client
    npm run dev

    Application will run on http://localhost:5173

  3. Open your browser Navigate to http://localhost:5173

API Endpoints

Authentication

  • POST /register - Register a new user
  • POST /login - Login user
  • POST /logout - Logout user
  • GET /profile - Get current user profile

Messages

  • GET /messages/:userID - Get messages with a specific user
  • DELETE /messages - Delete all user messages

Users

  • GET /people - Get all registered users
  • DELETE /account - Delete user account

Health

  • GET /test - Test endpoint
  • GET /health - Health check

Features in Detail

Real-time Messaging

  • WebSocket connection for instant message delivery
  • Automatic reconnection on connection loss
  • Online/offline status indicators

User Management

  • Secure password hashing
  • JWT-based authentication
  • Session persistence with cookies

UI/UX

  • Clean, modern interface
  • Toast notifications for user actions
  • Responsive design for all devices
  • Keyboard shortcuts (ESC to exit chat)

Environment Variables

Backend (api/.env)

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)

Frontend (client/.env)

Variable Description
VITE_API_URL Backend API URL
VITE_WS_URL WebSocket server URL

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Yours truly

Acknowledgments

  • Material Symbols for icons
  • Tailwind CSS for styling utilities
  • MongoDB for database
  • Vercel and Render for hosting

Made with ❀️

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published