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
dbfolders), Redis for chat/pubsub (seechat-server/redis). - Orchestration:
docker-compose.ymlat 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.clientandclient-2: Next.js frontends demonstrating integration with the gateway and backend services (each is a separate Next app). Seeclient/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)
- From repository root run:
docker-compose up --build
- 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
- Gateway entry: api-gateway/index.js
- Auth entry: auth-server/index.js
- Chat entry: chat-server/index.js
- Client Next app: client/src/app/page.js
Development notes
- The repository contains two Next.js clients (
clientandclient-2) with similar structure undersrc/appand shared store hooks insrc/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). EnsureMONGO_URIpoints to the correct DB instance used by your environment.
Troubleshooting
- If ports conflict, stop other local services or adjust service
PORTvariables. - If authentication fails, verify
JWT_SECRETis consistent betweenapi-gatewayandauth-server(or the gateway verifies tokens using the same secret or public key).