Skip to content

Kittipong91/mini-chat-web

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Mini Chat Application

A simple, professional-grade chat application supporting one-on-one conversations between two users. Built for clarity, maintainability, and ease of testing.


🚀 Live Demo

View the live demo here



1. Project Overview

This project is a Mini Chat Application that enables chat between two users. It is designed for demonstration and learning purposes, focusing on clean architecture and modern web technologies.


2. Tech Stack

Layer Technology
Frontend Next.js, Tailwind CSS
Backend Node.js, Express
Language TypeScript
Database MongoDB
Testing Jest

3. Getting Started

Prerequisites

  • Node.js (v18+ recommended)
  • npm
  • MongoDB Atlas

1. Clone the repository

git clone <repo-url>
cd Conversations

2. Setup Environment Variables

Backend (backend/.env):

MONGODB_URI=your_mongodb_uri
PORT=4000

Frontend (frontend/.env):

NEXT_PUBLIC_API_BASE=http://localhost:4000

3. Install dependencies & Run (Both Frontend & Backend)

Open two terminals:

Backend

cd backend
npm install
npm run dev

Frontend

cd frontend
npm install
npm run dev

4. Authentication Simulation

  • No real authentication.
  • Simulate login by sending an x-user-id header with every API request.
  • Seed Users:
    • User 1: { id: 1, name: "Alice" }
    • User 2: { id: 2, name: "Bob" } User 2: { id: 3, name: "Carol" }
  • To test chat between users, open two browser windows and set different x-user-id values (e.g., via browser devtools or by modifying the frontend logic).

5. Implemented Features

  • User-to-user chat (1:1)
  • Pagination for conversations and messages
  • Unit tests for validation
  • Clean RESTful API design
  • Simple authentication simulation via header

6. API Endpoints

Method Endpoint Description Auth (x-user-id)
GET /users/me Get current user info Required
GET /conversations List conversations (paginated) Required
POST /conversations Start new conversation Required
GET /conversations/:id/messages List messages in conversation Required
POST /messages Send message to conversation Required

7. How to Run Tests

Backend (Jest)

cd backend
npm run test

8. Environment Setup Example

backend/.env

MONGODB_URI= your-url
PORT=4000

frontend/.env

NEXT_PUBLIC_API_BASE=http://localhost:4000

Releases

Packages

Contributors

Languages