Skip to content

Chat app using Nestjs, React, PostgreSQL and Socket-IO, with public messages, private messages, sending files

Notifications You must be signed in to change notification settings

Datodia/chat-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React + Node.js Chat Application

A real-time chat application built with React frontend and Node.js backend, featuring file uploads, private messaging, and Docker deployment.

Features

  • Real-time messaging with Socket.IO
  • User authentication (sign up/sign in)
  • File upload support (images and documents)
  • Private messaging between users
  • Online user list
  • Responsive UI with Tailwind CSS
  • Docker containerization

Tech Stack

Frontend

  • React 19
  • TypeScript
  • Vite
  • Tailwind CSS
  • Socket.IO Client
  • React Router DOM
  • Axios

Backend

  • Node.js
  • Express.js
  • Socket.IO
  • Sequelize (PostgreSQL)
  • JWT Authentication
  • Multer (file uploads)
  • bcrypt

Prerequisites

  • Docker and Docker Compose
  • Node.js 18+ (for local development)
  • PostgreSQL (handled by Docker)

Quick Start with Docker

  1. Set up environment variables

    # Copy environment files
    cp server/.env.example server/.env
    cp client/.env.example client/.env
  2. Build and run with Docker Compose

    docker-compose up --build
  3. Access the application

Manual Setup (Development)

Backend Setup

  1. Navigate to server directory

    cd server
    cp .env.example .env
  2. Install dependencies

    npm install
  3. Start PostgreSQL (or use Docker)

    docker run --name postgres -e POSTGRES_USER=app -e POSTGRES_PASSWORD=app -e POSTGRES_DB=appdb -p 5432:5432 -d postgres:16-alpine
  4. Start the server

    npm run dev

Frontend Setup

  1. Navigate to client directory

    cd client
    cp .env.example .env
  2. Install dependencies

    npm install
  3. Start the development server

    npm run dev

Environment Variables

Server (.env)

# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=app
DB_PASSWORD=app
DB_DATABASE=appdb

# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-here

# Server Configuration
PORT=5005
CLIENT_URL=http://localhost:3000

# CORS Configuration
CORS_ORIGIN=http://localhost:3000

Client (.env)

# API Configuration
VITE_API_URL=http://localhost:5005

Docker Commands

# Build and start all services
docker-compose up --build

# Start services in background
docker-compose up -d

# Stop services
docker-compose down

# View logs
docker-compose logs

# Rebuild specific service
docker-compose up --build backend

API Endpoints

Authentication

  • POST /auth/sign-up - User registration
  • POST /auth/sign-in - User login
  • GET /auth/current-user - Get current user info

Messages

  • GET /messages - Get all public messages
  • GET /messages/private/:userId - Get private messages with specific user
  • POST /messages - Send message (supports file uploads)

Users

  • GET /users - Get users list

File Upload

The application supports uploading images and documents. Files are stored in the server/uploads/ directory and served via the /uploads endpoint.

Architecture

  • Frontend: React SPA with real-time updates via Socket.IO
  • Backend: Express.js API server with Socket.IO for real-time communication
  • Database: PostgreSQL with Sequelize ORM
  • File Storage: Local file system (can be extended to cloud storage)
  • Authentication: JWT tokens stored in cookies

Development Notes

  • The application uses TypeScript for better type safety
  • Real-time messaging is handled through Socket.IO events
  • File uploads are processed via multipart/form-data
  • The UI is responsive and uses Tailwind CSS for styling
  • Docker setup includes PostgreSQL database and both frontend/backend services

About

Chat app using Nestjs, React, PostgreSQL and Socket-IO, with public messages, private messages, sending files

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published