This repository is a monorepo for a scalable chat application built with Turborepo and utilizes multiple technologies to ensure scalability, efficiency, and real-time communication.
This chat application is built using:
- Frontend: Next.js for the web client.
- Backend: Node.js for the server-side logic.
- Message Channeling: Redis is used for pub/sub messaging.
- Data Storage: PostgreSQL with Prisma for database ORM.
- Message Queue: Kafka is utilized for distributed messaging and scalability.
- When a message is sent from the client, it is first sent to Redis for quick pub/sub handling.
- The message is then pushed to Kafka to handle distribution to multiple servers.
- The message is stored in PostgreSQL via Prisma for persistence.
- Finally, the message is distributed to all servers running the application to ensure all clients receive the message in real-time.
Ensure you have the following installed on your local development machine:
- Node.js v14.x or later
- Yarn
- PostgreSQL v12.x or later
- Redis v6.x or later
- Kafka v2.x or later
-
Clone this repository:
git clone https://github.com/priyanshusinha11/chat-app.git cd chat-app -
Install all dependencies:
yarn install
-
Set up the database:
Create a
.envfile in the root directory with your PostgreSQL connection details:DATABASE_URL="postgresql://user:password@localhost:5432/chatdb"
Then run the following command to set up the database schema:
yarn prisma migrate dev
To start both the client and server applications:
yarn dev
## Building the Application
This command will run both the Next.js frontend and the Node.js backend simultaneously.
### To build all apps and packages, run:
```bash
yarn build- Next.js: Framework for building the web client.
- Node.js: Server-side runtime for handling backend logic.
- Redis: In-memory data structure store for pub/sub messaging.
- PostgreSQL: Relational database for message persistence.
- Prisma: ORM for PostgreSQL to handle database operations.
- Kafka: Distributed event streaming platform for message queueing.
- Turborepo: Tool for managing monorepos, build optimization, and remote caching.
- Yarn: Package manager for managing project dependencies.
- Start Development: yarn dev - Starts both frontend and backend servers.
- Build Application: yarn build - Builds all apps and packages.
- Database Migration: yarn prisma migrate dev - Runs the Prisma migrations.
