- Node.js v18.0.0 or higher (tested on 20.18.3)
- npm v9.x or higher
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:
- Install dependencies:
npm install
- Set up your
.envfile with your MongoDB URI:MONGO_URI=<mongoURL>
- Start the server:
npm run dev
Built with React, TypeScript, and Vite. Features a modern, responsive chat interface styled with CSS Modules.
- 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.
To run the frontend:
- Install dependencies:
npm install
- Set up your
.envfile with your API base URL:VITE_API_URL=http://localhost:5000/
- Start the development server:
npm run dev
The backend includes a comprehensive test suite built with Jest and Supertest to ensure code quality and reliability.
- 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
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
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
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
- 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! 🤖💬