Skip to content

Vintanina/chat-api

Repository files navigation

🟢 NestJS Chat API

Overview

This is a real-time chat API built with NestJS, TypeORM, and PostgreSQL (running in Docker). It provides:

  • User registration & authentication (JWT-based)
  • Chat messaging between users
  • Database persistence with PostgreSQL
  • Dockerized setup for easy local development
  • Ready to scale for real-time features or microservices integration

Tech Stack

  • Backend: NestJS, TypeScript, TypeORM
  • Database: PostgreSQL (Dockerized)
  • Authentication: JWT
  • Dev Tools: Docker Compose, npm

Features

  • User management (register, login)
  • CRUD operations for chat messages
  • Modular and clean architecture
  • Easily extensible for future real-time updates (WebSockets)

Folder Structure

src ├── auth │ ├── dto │ │ └── login.dto.ts │ ├── auth.controller.ts │ ├── auth.module.ts │ ├── auth.service.ts │ ├── jwt-auth.guard.ts │ └── jwt.strategy.ts ├── chat │ ├── dto │ │ ├── create-room.dto.ts │ │ └── send-message.dto.ts │ ├── entities │ │ ├── message.entity.ts │ │ └── room.entity.ts │ ├── chat.controller.ts │ ├── chat.gateway.ts │ ├── chat.module.ts │ └── chat.service.ts ├── users │ ├── dto │ │ └── create-user.dto.ts │ ├── entities │ │ └── user.entity.ts │ ├── users.controller.ts │ ├── users.module.ts │ └── users.service.ts ├── app.controller.spec.ts ├── app.controller.ts ├── app.module.ts ├── app.service.ts └── main.ts 

🛠 Setup & Run

  1. Clone the repository

git clone https://github.com/Vintanina/chat-api.git

cd chat-api

  1. Create .env file

DATABASE_URL=postgres://chat:chat@localhost:6543/chat_db PORT=3000 JWT_SECRET=your_jwt_secret

Adjust DATABASE_URL if Postgres is running in Docker with a different port or credentials. 
  1. Start PostgreSQL with Docker (Optionnal)

docker compose up -d

The container exposes Postgres on port 6543. Check logs if needed: 

docker compose logs -f db

  1. Install dependencies

npm install

  1. Run the NestJS application

npm run start:dev

The API runs on http://localhost:3000 
  1. Test the API

Example: register a user via curl:

curl -X POST http://localhost:3000/auth/register
-H "Content-Type: application/json"
-d '{"username":"alice","email":"alice@mail.com","password":"secret123"}'

  1. Notes

    Make sure TypeOrmModule is properly configured with your entities and autoLoadEntities: true.

    If the database is slow to start, NestJS retries automatically (configured via retryAttempts and retryDelay).

    Use docker compose down -v to clean volumes if you want a fresh database.

About

A lightweight template for a real-time chat API built with NestJS, TypeORM, and PostgreSQL. Includes Docker setup for quick local development and scalable architecture for authentication, messaging, and microservices-ready features.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors