Skip to content

abhishekgupta1025/chat-application-1

Repository files navigation

Real-Time Chat Application

A comprehensive, full-stack chat application built with Next.js, Socket.IO, and MongoDB. This application provides real-time messaging capabilities, user authentication, and responsive design optimized for both desktop and mobile platforms.

Chat Application Next.js React Socket.io TypeScript

Features

  • Real-time messaging - Instantaneous message delivery using Socket.IO
  • Contact management - User contact system with chat room functionality
  • User authentication - Secure authentication system with JWT tokens
  • Responsive design - Cross-platform compatibility for desktop and mobile devices
  • Offline functionality - Graceful degradation when backend services are unavailable
  • Message persistence - Persistent chat history storage
  • Modern user interface - Clean, intuitive design using Tailwind CSS
  • Performance optimization - Optimized for speed and reliability

Installation and Setup

System Requirements

The following software components are required for this application:

  • Node.js (version 18.0 or higher) - Download
  • Git - Download
  • MongoDB (optional, required for full backend functionality) - Download

Application Deployment

Option 1: Frontend-Only Deployment (Recommended for Testing)

# Clone the repository
git clone <repository-url>
cd "chat application 1"

# Install project dependencies
npm install
# Alternative: pnpm install

# Configure environment variables
echo "NEXT_PUBLIC_API_URL=http://localhost:5000" > .env.local

# Start the development server
npm run dev
# Alternative: pnpm dev

# Access the application
# Navigate to: http://localhost:3000

This configuration utilizes local mock data for demonstration purposes.

Option 2: Full-Stack Deployment (Frontend + Backend)

Backend Server Configuration:

# Navigate to backend directory
cd backend

# Install backend dependencies
npm install

# Configure backend environment variables
echo "MONGODB_URI=mongodb://localhost:27017/chatapp
JWT_SECRET=your-secret-key-here
PORT=5000" > .env

# Start backend server
npm start

Frontend Application Configuration:

# Return to main project directory
cd "chat application 1"

# Start frontend development server
npm run dev

Service Access Points:

Application Usage

  1. Register/Login - Create an account or log in to the system
  2. Start Chatting - Select "General Chat" or any contact from the list
  3. Send Messages - Type messages and press Enter or click Send
  4. Real-time Updates - Messages appear instantly for all connected users

Project Structure

Chat Application
├── frontend/                 # Next.js React Application
│   ├── pages/                # Application pages
│   │   ├── chat.tsx         # Main chat interface
│   │   ├── login.tsx        # User authentication
│   │   └── api/             # API endpoints
│   ├── components/          # Reusable React components
│   ├── types/              # TypeScript type definitions
│   └── styles/             # CSS and styling
│
├── backend/                 # Node.js Express Server
│   ├── server.js           # Main server file
│   ├── routes/             # API route handlers
│   ├── models/             # Database models
│   └── .env                # Environment variables
│
└── Documentation
    ├── README.md           # This file
    ├── yaipadhle.md       # Beginner's guide
    └── technical.md        # Technical documentation

Technology Stack

Frontend

  • Next.js 15 - React framework with SSR
  • React 18 - UI library with hooks
  • TypeScript - Type-safe JavaScript
  • Tailwind CSS - Utility-first CSS framework
  • Socket.IO Client - Real-time communication
  • shadcn/ui - Modern UI components

Backend

  • Node.js - JavaScript runtime
  • Express.js - Web application framework
  • Socket.IO - Real-time bidirectional communication
  • MongoDB - NoSQL database
  • Mongoose - MongoDB object modeling
  • JWT - JSON Web Tokens for authentication
  • bcryptjs - Password hashing

Configuration Options

Environment Variables

Frontend (.env.local):

NEXT_PUBLIC_API_URL=http://localhost:5000  # Backend server URL

Backend (.env):

MONGODB_URI=mongodb://localhost:27017/chatapp  # Database connection
JWT_SECRET=your-super-secret-key-here          # Authentication secret
PORT=5000                                      # Server port

Available Scripts

Frontend

npm run dev        # Start development server
npm run build      # Build for production
npm run start      # Start production server
npm run lint       # Run ESLint

Backend

npm start          # Start the server
npm run dev        # Start with nodemon (auto-restart)

Deployment

Frontend (Vercel - Recommended)

  1. Push your code to GitHub
  2. Connect your repo to Vercel
  3. Add environment variable: NEXT_PUBLIC_API_URL=https://your-backend-url.com
  4. Deploy automatically

Backend (Railway/Heroku)

  1. Push backend code to a repository
  2. Connect to Railway or Heroku
  3. Add environment variables (MongoDB URI, JWT Secret)
  4. Deploy

Troubleshooting

Common Issues

"Cannot connect to backend"

  • Solution: The application automatically uses local mock data. Backend is optional for testing.

"Messages not appearing"

  • Check if Socket.IO is connected (open browser developer tools → Network tab)
  • Fallback: Application uses polling every 2 seconds as backup

"Build errors"

  • Run npm install to ensure all dependencies are installed
  • Check Node.js version (should be 18+)

"TypeScript errors"

  • Run npm run build to see detailed error messages
  • All current errors have been resolved in this version

Getting Help

  1. Check the console - Press F12 in browser and look for error messages
  2. Verify setup - Ensure all environment variables are set correctly
  3. Restart servers - Stop and restart both frontend and backend
  4. Clear cache - Delete .next folder and node_modules, then reinstall

Learn More

Contributing

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

License

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

Key Features

  • Production Ready - Thoroughly tested and debugged
  • Beginner Friendly - Extensive documentation and comments
  • Modern Stack - Uses the latest versions of popular technologies
  • Full Feature Set - Real-time chat with all essential features
  • Mobile First - Responsive design that works everywhere
  • Fallback Support - Works even when the backend is down

Ready to get started? Follow the Installation and Setup guide above to begin using the application.


Built using Next.js, Socket.IO, and modern web technologies

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published