ChatMu is a real-time chat application built with a modern architecture using npm workspaces.
ChatMu/
βββ apps/
β βββ web/ # Next.js frontend application
β βββ server/ # Express + Socket.IO backend server
βββ packages/
β βββ shared/ # Shared types, schemas, and utilities
β βββ database/ # Database models and data access layer
β βββ ui/ # Shared UI components (Shadcn/UI)
βββ package.json # Root workspace configuration
- Framework: Next.js 14 (App Router)
- State Management: Redux Toolkit
- UI Components: Shadcn/UI + Tailwind CSS
- Authentication: NextAuth.js
- Real-time: Socket.IO Client
- Server: Express.js
- Real-time: Socket.IO
- Language: TypeScript
@chatmu/shared: Types, schemas (Zod), utilities@chatmu/database: MongoDB models (Mongoose), data access@chatmu/ui: Reusable UI components
- Real-time messaging
- User authentication
- Private chat
- Message history
- Online/offline status
- Message read receipts
- Node.js 20+
- npm (comes with Node.js)
- MongoDB (or use Docker Compose)
-
Clone the repository
git clone https://github.com/inifitrah/ChatMu.git cd ChatMu -
Install dependencies
npm install
-
Setup environment variables
cp .env.example .env.local # Edit .env.local with your configuration -
Start MongoDB (using Docker)
docker compose up mongo mongo-express -d
Option 1: Run all apps simultaneously
npm run devOption 2: Run apps individually
# Terminal 1 - Start backend server
npm run dev:server
# Terminal 2 - Start frontend web app
npm run dev:webThe applications will be available at:
- Frontend: http://localhost:3000
- Backend: http://localhost:3003
- MongoDB Express: http://localhost:8081
npm run buildnpm run build:web # Build web app only
npm run build:server # Build server onlyBuild and run all services with Docker Compose:
docker compose up --buildThis will start:
- MongoDB database
- MongoDB Express (admin UI)
- Socket.IO server
- Next.js web application
npm install <package> --workspace=apps/web
npm install <package> --workspace=packages/sharednpm run <script> --workspace=apps/webnpm run cleanContains shared code used across the monorepo:
- Types: TypeScript type definitions
- Schemas: Zod validation schemas
- Utils: Utility functions
Database layer:
- Models: Mongoose models for MongoDB
- Data Access: Database query functions
Reusable UI components:
- Shadcn/UI components
- Shadcn/UI hooks (useToast, etc.)
- Custom styled components
- Shared utilities (cn helper)
Backend server:
- Express.js API server
- Socket.IO real-time messaging
- Health check endpoints
Frontend application:
- Next.js 14 with App Router
- User authentication
- Real-time chat interface
- Profile management
To a specific workspace:
npm install <package> -w apps/web
npm install <package> -w packages/sharedTo root (dev dependencies):
npm install -D <package>In apps/web or apps/server, import from internal packages:
import { IMessage } from "@chatmu/shared";
import { User } from "@chatmu/database";
import { Button } from "@chatmu/ui";Each app/package has path aliases configured in tsconfig.json:
@chatmu/sharedβ../../packages/shared/src@chatmu/databaseβ../../packages/database/src@chatmu/uiβ../../packages/ui/src
See .env.example for all required environment variables.
Key variables:
MONGODB_URI: MongoDB connection stringNEXTAUTH_SECRET: NextAuth.js secretNEXT_PUBLIC_SOCKET_URL: Socket.IO server URLRESEND_API_KEY: Email service API keyCLOUDINARY_*: Image upload configuration
- Implement group chat functionality
- Improve user interface and experience
- Develop mobile application
- Add support for multiple languages
- File sharing support
- Voice/video calling
This project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
