A scalable real-time chat system built with NestJS, GraphQL, PostgreSQL, and Prisma. This project leverages modern technologies to provide a robust backend for a chat application, focusing on real-time communication and secure authentication.
Clone the repository:
git clone https://github.com/phambaophuc/chat-graphql.git
cd chat-graphql
Install dependencies:
npm install
Configure Environment Variables:
Copy the example environment file and fill in your database connection details and JWT secret:
cp .env.example .env
# Edit .env with your database URL and JWT_SECRET
Set up the Database:
chat_db).DATABASE_URL in your .env file accordingly.Generate Prisma Client:
This command generates the Prisma Client based on your schema.
npm run db:generate
Run Database Migrations:
Applies the database schema to your PostgreSQL instance.
npm run db:migrate
Seed the Database (Optional but recommended for development):
Populates the database with mock data using faker.
npm run db:seed
Start the NestJS application in development mode with hot-reloading:
npm run start:dev
The server will typically run on http://localhost:3000.
Once the server is running, you can access the GraphQL Playground at http://localhost:3000/graphql. This interactive interface allows you to explore the schema, test queries, and mutations.
1. User Registration:
mutation {
register(input: {
username: "john_doe"
password: "password123"
}) {
userId
token
}
}
2. User Login:
mutation {
login(input: {
username: "john_doe"
password: "password123"
}) {
userId
token
}
}
*Note: For real-time messaging and subscriptions, you would typically use a GraphQL client that supports subscriptions (e.g., Apollo Client) and connect to the WebSocket endpoint.
This project exposes a GraphQL API. The schema is defined in schema.gql and generated dynamically.
Key areas covered by the API include:
Refer to the GraphQL Playground (/graphql) for the most up-to-date schema and available operations.
This project is licensed under the MIT License - see the LICENSE file for details.
This project is the chat-graphql repository.
Built with ❤️ by phambaophuc