A modern, full-stack real-time chat application built with Next.js 15, Express.js, Socket.IO, and TypeScript.
- Real-time messaging with Socket.IO
- User authentication (signup/signin)
- Multiple conversation support with participant management
- Responsive design with Tailwind CSS
- Type-safe development with TypeScript
- Modern UI with React 19 and Next.js 15 App Router
- SQLite database with Drizzle ORM
- JWT-based authentication
This is a monorepo structure with three main parts:
chat-app/
├── client/ # Next.js 15 frontend with App Router
├── server/ # Express.js backend with Socket.IO
└── shared/ # Shared TypeScript types
Frontend (client/)
- Framework: Next.js 15 with App Router + React 19
- Styling: Tailwind CSS 3.x with @tailwindcss/forms
- State Management: TanStack Query for server state
- Real-time: Socket.IO client
- Language: TypeScript
Backend (server/)
- Framework: Express.js with TypeScript
- Real-time: Socket.IO for WebSocket communication
- Database: SQLite with Drizzle ORM
- Authentication: JWT + bcrypt
- Language: TypeScript
Shared (shared/)
- Common TypeScript interfaces for
User,Conversation,Message, andSocketEvents
- Node.js (version 18+ recommended)
- npm or yarn
-
Clone the repository
git clone <your-repo-url> cd chat-app
-
Install server dependencies
cd server npm install -
Install client dependencies
cd ../client npm install -
Set up environment variables
Server (.env in
/serverdirectory):PORT=3001 CLIENT_URL=http://localhost:3000 JWT_SECRET=your-super-secret-jwt-key-here
Client (.env.development in
/clientdirectory):NEXT_PUBLIC_API_URL=http://localhost:3001/api NEXT_PUBLIC_SOCKET_URL=http://localhost:3001
-
Set up the database
cd server # Generate and apply database schema npx drizzle-kit push
You'll need to run both the server and client in separate terminals.
Terminal 1 - Start the backend server:
cd server
npm run devThe server will start on http://localhost:3001
Terminal 2 - Start the frontend client:
cd client
npm run devThe client will start on http://localhost:3000
- Open your browser and navigate to
http://localhost:3000 - Create an account or sign in with existing credentials
- Create a new conversation by clicking "Create New Conversation"
- Add participants by entering their usernames
- Start chatting in real-time!
- Start both server and client (see Running the Application above)
- Open multiple browser tabs/windows to
http://localhost:3000 - Create different user accounts in each tab
- Test real-time messaging between users
- Test conversation creation and participant management
- User registration works
- User login works
- User can create conversations
- User can add participants to conversations
- Messages are sent and received in real-time
- Connection status indicator works
- Logout functionality works
- Application works across multiple browser tabs
- Responsive design works on mobile devices
Server (/server):
npm run dev- Start development server with nodemonnpm run build- Compile TypeScript to dist/npm start- Run production buildnpx drizzle-kit generate- Generate database migrationsnpx drizzle-kit push- Apply schema changes to database
Client (/client):
npm run dev- Start Next.js development servernpm run build- Build for productionnpm start- Start production servernpm run lint- Run Next.js ESLint
Database Schema:
users- User accounts with id, email, username, createdAtconversations- Chat rooms with id, name, createdAt, updatedAtmessages- Individual messages linking users to conversationsconversation_participants- Many-to-many relationship between users and conversations
Socket.IO Events:
- Client→Server:
join,join_conversation,send_message - Server→Client:
joined,conversation_history,new_message,user_connected,user_disconnected,error
Authentication Flow:
- User registers/logs in via REST API
- Server returns JWT token
- Client stores token in localStorage
- Client connects to Socket.IO with token
- All subsequent API calls include JWT token
Port conflicts:
- Server default:
3001 - Client default:
3000 - If ports are in use, the apps will try alternative ports
Database issues:
cd server
# Reset database schema
npx drizzle-kit pushDependencies issues:
# Clean install server
cd server
rm -rf node_modules package-lock.json
npm install
# Clean install client
cd client
rm -rf node_modules package-lock.json .next
npm installEnvironment variables:
- Make sure
.envfiles are in the correct directories - Don't commit
.envfiles to version control - Restart servers after changing environment variables
This project is licensed under the MIT License.