Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /