Skip to content

Latest commit

 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Chat App

Home Screenshot

🚀 Requirements

  • Node.js v18.0.0 or higher (tested on 20.18.3)
  • npm v9.x or higher

🛠️ Backend

Built with Node.js, Express, and TypeScript. Provides RESTful API endpoints for chat with comprehensive test coverage:

  • POST /api/messages — Accepts a user message (optionally with a session ID), saves it to MongoDB, generates a bot reply, saves it, and returns it.
  • GET /api/messages — Retrieves all chat messages (user and bot) from MongoDB, sorted by timestamp. Supports session ID filtering.
  • DELETE /api/messages?sessionId=... — Deletes all chat messages for a specific session.

Each message can be associated with a sessionId to support multiple chat sessions or users.

Uses Mongoose to interact with MongoDB Atlas. All messages are stored with sender, content, timestamp, and sessionId fields. Bot reply logic is customizable and responds to keywords and general conversation.

Environment variables (such as the MongoDB connection string) are managed using a .env file.

Includes a full test suite with unit tests for models and services, plus integration tests for API endpoints using Jest and Supertest.

To run the backend:

  1. Install dependencies:
    npm install
  2. Set up your .env file with your MongoDB URI:
    MONGO_URI=<mongoURL>
  3. Start the server:
    npm run dev

💻 Frontend

Built with React, TypeScript, and Vite. Features a modern, responsive chat interface styled with CSS Modules.

Key Features

  • Chat Window: User and bot messages in distinct chat bubbles, with clear alignment and sender labeling.
  • Session Management: Each chat session is tracked using a unique session ID stored in localStorage.
  • API Integration: Communicates with the backend via RESTful endpoints, using environment variables (VITE_API_URL) for local/production.
  • Message Deletion: Users can delete the entire conversation for the current session.
  • Loading Indicator: Visual indicator while waiting for bot replies.
  • Reusable Components: Modular chat window and button components.

Chat Popup Screenshot

To run the frontend:

  1. Install dependencies:
    npm install
  2. Set up your .env file with your API base URL:
    VITE_API_URL=http://localhost:5000/
  3. Start the development server:
    npm run dev

🧪 Testing

The backend includes a comprehensive test suite built with Jest and Supertest to ensure code quality and reliability.

Testing Stack

  • Jest: Testing framework for unit and integration tests
  • Supertest: HTTP assertion library for testing Express routes
  • MongoDB Memory Server: In-memory MongoDB instance for isolated testing
  • ts-jest: TypeScript preprocessor for Jest

Running Tests

Navigate to the backend directory and run:

cd chat-app-backend

# Run all tests
npm test

# Run tests in watch mode (re-runs on file changes)
npm run test:watch

# Run tests with coverage report
npm run test:coverage

# Run tests with verbose output
npm run test:verbose

Test Categories

Unit Tests

  • Models: Test Mongoose schema validation, model methods, and database operations
  • Services: Test business logic in isolation, different input scenarios, and edge cases

Integration Tests

  • Routes: Test complete API endpoints, request/response flow, database integration, and error handling

Test Database

Tests use MongoDB Memory Server which provides:

  • Isolated test environment with no external dependencies
  • Fast test execution
  • Automatic cleanup between tests
  • Fresh database for each test run

📝 Notes

  • The backend is ready for integration with the frontend and supports session-based chat tracking and message management.
  • The frontend supports session-based chat with message management and a polished user experience.
  • For deployment, set environment variables appropriately and ensure both backend and frontend servers are running and accessible.

Enjoy chatting! 🤖💬

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages