Real-time chat application with a modern Next.js frontend and an Express + Socket.IO backend.
- Real-time room messaging with Socket.IO
- JWT-based authentication
- Room creation and join-by-code flow
- MongoDB persistence for users, rooms, and messages
- TypeScript frontend with App Router (Next.js)
fchat/
app/ # Next.js frontend (UI, state, client sockets)
server/ # Express API, Socket.IO server, MongoDB models
- Frontend: Next.js, React, Tailwind CSS, Zustand, Axios, Socket.IO client
- Backend: Node.js, Express, Socket.IO, Mongoose, JWT, bcrypt
- Database: MongoDB
- Package manager: pnpm
- Node.js 20+
- pnpm 9+
- MongoDB instance (local or remote)
Create a file named .env inside server/ with:
PORT=5000
MONGODB_URI=mongodb://localhost:27017
MONGODB_DB_NAME=chat_db
JWT_SECRET=replace-with-a-long-random-secret
FRONTEND_ORIGIN=http://localhost:3000Create a file named .env.local inside app/ with:
NEXT_PUBLIC_API_URL=http://localhost:5000cd server
pnpm install
cd ../app
pnpm installUse two terminals.
Terminal 1:
cd server
pnpm devTerminal 2:
cd app
pnpm devBuild and start each app separately.
Backend:
cd server
pnpm startFrontend:
cd app
pnpm build
pnpm start- pnpm dev
- pnpm build
- pnpm start
- pnpm lint
- pnpm dev
- pnpm start
- pnpm create:user
- Backend API docs are in server/README.md
- Frontend setup docs are in app/README.md
The project is currently split into two deployable apps:
- app: frontend client
- server: backend API + WebSocket server
This is a clean modular base and can later be migrated into a monolith if desired.
- Monolithic deployment option (single process)
- Message reactions and read receipts
- Presence indicators and typing status
- Rate limiting and enhanced security middleware
- CI checks and automated tests
- Fork the repository
- Create a feature branch
- Make your changes
- Open a pull request with a clear summary