Skip to content

DevloperMM/chatapp-system-design

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

P1 — ChatApp

Simple microservices chat application composed of an API gateway, authentication service, chat service, and Next.js client(s). This repository contains Docker-friendly services and example Next.js clients to run and develop locally or in containers.

Overview

  • Purpose: Real-time chat demo built from small, focused services (auth, chat, gateway) with a Next.js frontend.
  • Core services: api-gateway, auth-server, chat-server, client, client-2.
  • Datastores: MongoDB for persistence (per-service db folders), Redis for chat/pubsub (see chat-server/redis).
  • Orchestration: docker-compose.yml at repository root for local multi-container setup.

Architecture

  • api-gateway: central entry point for frontend requests and proxying to backend services. See api-gateway/index.js.
  • auth-server: user management and JWT issuance. See auth-server/index.js and controllers in auth-server/controllers.
  • chat-server: handles messaging, stores chat documents in Mongo and uses Redis for pub/sub. See chat-server/index.js.
  • client and client-2: Next.js frontends demonstrating integration with the gateway and backend services (each is a separate Next app). See client/src/app.

Repository layout (top-level)

  • docker-compose.yml — orchestrates multi-service environment.
  • api-gateway/ — gateway server code.
  • auth-server/ — authentication service, routes and controllers.
  • chat-server/ — chat service, message controllers and Redis helper.
  • client/ — Next.js frontend application.
  • client-2/ — alternative Next.js frontend (duplicate/example).

Getting started

Prerequisites

  • Install Docker and Docker Compose (or Docker Desktop).
  • Node.js (for running services locally without Docker).

Quick start (recommended)

  1. From repository root run:
docker-compose up --build
  1. Docker Compose will start the API gateway, auth and chat servers, databases, Redis, and the client(s) (if configured in docker-compose.yml). Check service logs to find assigned ports.

Run services locally (without Docker)

  • Each service contains a package.json. Typical steps per service:
cd auth-server
npm install
npm run dev   # or npm start

Repeat for api-gateway, chat-server, and client (Next.js apps typically use npm run dev to start the dev server).

Environment variables

  • The services expect standard environment variables for DB and auth configuration. Common names used across microservices:

  • MONGO_URI — MongoDB connection string

  • REDIS_URL — Redis connection endpoint

  • JWT_SECRET — secret for signing JWTs

  • PORT — service port override

Check each service folder for environment usage and sample values (e.g., in auth-server, chat-server, or docker-compose.yml).

Important files and references

Development notes

  • The repository contains two Next.js clients (client and client-2) with similar structure under src/app and shared store hooks in src/app/store.
  • The chat service uses Redis for message pub/sub; ensure Redis is running when testing real-time features.
  • Mongo databases are connected per-service (db/connectMongo.js). Ensure MONGO_URI points to the correct DB instance used by your environment.

Troubleshooting

  • If ports conflict, stop other local services or adjust service PORT variables.
  • If authentication fails, verify JWT_SECRET is consistent between api-gateway and auth-server (or the gateway verifies tokens using the same secret or public key).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors