A modern real-time chat application built with Next.js, Socket.io, and Prisma. ChatHub provides a seamless messaging experience with a clean, responsive interface and robust backend architecture.
- π User authentication and authorization
- π¬ Real-time messaging with Socket.io
- π± Responsive web interface
- ποΈ PostgreSQL database with Prisma ORM
- π¨ Modern UI components with Tailwind CSS
- π¦ Monorepo architecture with Turborepo
- π§ Type-safe development with TypeScript
This project uses a monorepo structure powered by Turborepo and PNPM workspaces:
apps/web- Next.js frontend application (Port 3000)apps/ws-server- WebSocket server for real-time communicationapps/http-server- Express.js HTTP API server
packages/database- Prisma database client and schemapackages/ui- Shared React UI componentspackages/cache- Caching utilitiespackages/eslint-config- Shared ESLint configurationspackages/typescript-config- Shared TypeScript configurationspackages/tailwind-config- Shared Tailwind CSS configuration
- Node.js 18+
- PNPM 9.0.0+
- PostgreSQL database
-
Clone the repository
git clone <repository-url> cd ChatHub
-
Install dependencies
pnpm install
-
Set up environment variables
cp .env.example .env # Edit .env with your database URL and other configurations -
Set up the database
pnpm db:migrate pnpm db:generate
-
Start development servers
pnpm dev
This will start all applications in development mode:
- Web app: http://localhost:3000
- WebSocket server: Configured port
- HTTP server: Configured port
pnpm dev- Start all applications in development modepnpm build- Build all applications for productionpnpm lint- Run ESLint across all packagespnpm format- Format code with Prettierpnpm check-types- Type check all packagespnpm db:migrate- Run database migrationspnpm db:generate- Generate Prisma client
The application uses PostgreSQL with Prisma ORM. Key models include:
- User: User accounts with authentication
id,email,username,passwordHashavatar,createdAt,updatedAt
- Next.js 16 - React framework with App Router
- React 19 - UI library
- Tailwind CSS 4 - Utility-first CSS framework
- TypeScript - Type safety
- Express.js - HTTP server framework
- Socket.io - Real-time communication
- Prisma - Database ORM
- PostgreSQL - Database
- Turborepo - Monorepo build system
- PNPM - Fast, efficient package manager
- ESLint - Code linting
- Prettier - Code formatting
- TypeScript - Static type checking
ChatHub/
βββ apps/
β βββ web/ # Next.js frontend
β βββ ws-server/ # Socket.io WebSocket server
β βββ http-server/ # Express.js HTTP API
βββ packages/
β βββ database/ # Prisma schema and client
β βββ ui/ # Shared React components
β βββ cache/ # Caching utilities
β βββ eslint-config/ # ESLint configurations
β βββ typescript-config/ # TypeScript configurations
β βββ tailwind-config/ # Tailwind CSS configuration
βββ package.json # Root package.json
βββ turbo.json # Turborepo configuration
βββ pnpm-workspace.yaml # PNPM workspace configuration
You can develop specific applications using Turborepo filters:
# Develop only the web app
pnpm turbo dev --filter=web
# Build only the HTTP server
pnpm turbo build --filter=http-server
# Lint only the UI package
pnpm turbo lint --filter=@repo/ui# Generate Prisma client after schema changes
pnpm turbo db:generate
# Create and apply new migration
pnpm turbo db:migrate
# Reset database (development only)
pnpm turbo db:resetThe project enforces code quality through:
- ESLint for consistent code style
- TypeScript for type safety
- Prettier for code formatting
Run quality checks:
# Check types across all packages
pnpm check-types
# Lint all code
pnpm lint
# Format all code
pnpm formatCreate a .env file in the root directory:
# Database
DATABASE_URL="postgresql://username:password@localhost:5432/chathub"
# Next.js
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-secret-key"
# WebSocket Server
WS_PORT=3001
# HTTP Server
HTTP_PORT=3002# Build all applications
pnpm build
# Build specific application
pnpm turbo build --filter=web(Add Docker configuration if needed)
# Build Docker image
docker build -t chathub .
# Run container
docker run -p 3000:3000 chathub# Run all tests
pnpm test
# Run tests for specific package
pnpm turbo test --filter=@repo/ui
# Run tests in watch mode
pnpm test:watch- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow the existing code style
- Write tests for new features
- Update documentation as needed
- Ensure all CI checks pass
(Add API documentation once implemented)
GET /api/users- Get user listPOST /api/auth/login- User authenticationPOST /api/messages- Send message
(Add WebSocket event documentation once implemented)
connection- User connectsmessage- Send/receive messagesdisconnect- User disconnects
-
Database Connection Error
- Verify PostgreSQL is running
- Check DATABASE_URL in .env file
- Run migrations:
pnpm db:migrate
-
Port Already in Use
- Check for running processes on ports 3000, 3001, 3002
- Kill processes or change ports in configuration
-
TypeScript Errors
- Run
pnpm check-typesto see detailed errors - Ensure all packages are built:
pnpm build
- Run
This project is licensed under the MIT License - see the LICENSE file for details.
- Next.js team for the amazing React framework
- Socket.io team for real-time communication tools
- Prisma team for the excellent ORM
- Vercel for Turborepo and deployment platform