This repository contains the backend server for SyncTalk, a full-stack, real-time chat application. It provides a hybrid architecture with a secure REST API for authentication and a real-time WebSocket server for instant messaging.
- Real-Time Communication: Utilizes WebSockets via Socket.IO to push messages and updates to all connected clients instantly.
- Secure User Authentication: Implements a complete email/password registration and login system from scratch, featuring secure password hashing with Argon2.
- JWT-Based Authorization: Uses JSON Web Tokens to secure all private API endpoints and WebSocket events.
- Multi-Room Chat: Includes API endpoints for creating and listing chat rooms, with WebSocket logic to manage users joining and leaving rooms.
- Robust & Type-Safe: Built with TypeScript and uses Zod for strict, schema-based input validation on all critical API routes.
- Persistent Database: Comes with a pre-configured Docker Compose file for a consistent and persistent local PostgreSQL database, managed by the Prisma ORM.
- Runtime: Node.js
- Framework: Express.js
- Real-time Engine: Socket.IO
- Language: TypeScript
- Database: PostgreSQL
- ORM: Prisma
- Password Hashing: Argon2
- Validation: Zod
Follow these instructions to get a local copy of the backend up and running.
-
Clone the repository:
git clone [https://github.com/your-username/synctalk-backend.git](https://github.com/your-username/synctalk-backend.git) cd synctalk-backend
-
Install dependencies:
npm install
-
Set up environment variables:
- Make a copy of the example environment file:
cp .env.example .env
- Open the
.env
file and fill in your database password and a strongJWT_SECRET
.
- Make a copy of the example environment file:
-
Start the database:
- Make sure Docker is running.
- Run
docker-compose up -d
to start the PostgreSQL container.
-
Run database migrations:
- This will create the
User
,Room
, andMessage
tables.npx prisma migrate dev
- This will create the
- To start the development server with hot-reloading:
npm run dev
- The server will be running at
http://localhost:3001
.
Method | Route | Protection | Description |
---|---|---|---|
POST |
/api/auth/register |
Public | Creates a new user account. |
POST |
/api/auth/login |
Public | Logs in a user and returns a JWT. |
POST |
/api/rooms |
Private | Creates a new chat room. |
GET |
/api/rooms |
Private | Retrieves a list of all available rooms. |
GET |
/api/rooms/:roomId/messages |
Private | Retrieves message history for a room. |
</markdo