This API serves as the backend for a chat application built using Express.js, Drizzle, PostgreSQL, Socket.IO, TypeScript, Zod, Multer, Peer for video chat, and JWT for authentication. The API enables users to sign up, send friend requests, chat with friends via text or video, send photos in the chat, create chat groups with customizable capacities, and manage group memberships through moderators.
-
User Authentication: Users can sign up and authenticate using JSON Web Tokens (JWT), ensuring secure access to the application.
-
Friend Requests: Users can send and accept friend requests, establishing connections with other users.
-
One-on-One Chat: Users can engage in one-on-one text and video chats with their friends, enhancing communication flexibility.
-
Multimedia Messaging: Users can send photos in their chat conversations, enriching the messaging experience.
-
Group Creation: Users can create chat groups with specified capacities, allowing multiple users to participate in group discussions.
-
Group Membership Management: Each group has a moderator who can accept or reject membership requests and remove members from the group, ensuring efficient group management.
-
Video Chat: Utilizing Peer, users can initiate and participate in real-time video chats within the application.
- Express.js: A minimalist web framework for Node.js, facilitating the development of robust APIs.
- Drizzle: A lightweight ORM (Object-Relational Mapping) for TypeScript and JavaScript, simplifying database interactions.
- PostgreSQL: A powerful open-source relational database management system, used for storing user data and chat information.
- Socket.IO: A library enabling real-time, bidirectional communication between web clients and servers, crucial for instant messaging functionality.
- TypeScript: A statically typed superset of JavaScript, providing improved developer productivity and code maintainability.
- Zod: A TypeScript-first schema declaration and validation library, ensuring data consistency and integrity.
- Multer: A middleware for handling multipart/form-data, enabling the uploading of photos within chat conversations.
- Peer: A simple, peer-to-peer solution for video, voice, and data communication, facilitating real-time video chat features.
- JWT (JSON Web Tokens): A standard for securely transmitting information between parties as JSON objects, used for user authentication and authorization.
-
Clone the repository:
git clone https://github.com/JooZef315/Chatter-Island-API
-
Navigate to the project directory:
cd <project-directory>
-
Install dependencies:
npm install
Add .env
file and fill in the necessary environment variables.
ENVIRONMENT =
PORT =
DATABASE_URI =
ACCESS_TOKEN_SECRET =
REFRESH_TOKEN_SECRET =
UPLOADCARE_SECRET =
To start the server in development mode with Nodemon, run:
npm run dev
Detailed documentation for API endpoints can be found in the API Documentation section below.
-
Register a new user
- Description: Register a new user.
- Method: POST
- Route: /api/v1/users/
- Access: Public
- Output: Success message
-
Authenticate a user
- Description: Authenticate a user and get JWT token.
- Method: POST
- Route: /api/v1/auth/login
- Access: Public
- Output: JWT token
-
Logout a user
- Description: Logout a user.
- Method: POST
- Route: /api/v1/auth/logout
- Access: Private
- Output: Success message
-
Refresh the access token
- Description: Refresh the access token.
- Method: GET
- Route: /api/v1/auth/refresh
- Access: Private
- Output: Access token
-
Get all Users
- Description: get all users.
- Method: GET
- Route: /api/v1/users
- Access: Private
- Query Parameters:
- search (string): Optional. for searching for a user by username.
- Output: users
-
Get a user
- Description: get a user.
- Method: GET
- Route: /api/v1/users/:uid
- Access: Private
- Parameters:
- uid (string): User ID.
- Query Parameters:
- full (boolean): Optional. to fully populate the user.
- Output: user
-
Update a user
- Description: get a user.
- Method: PUT
- Route: /api/v1/users/:uid
- Access: Private
- Parameters:
- uid (string): User ID.
- Output: Success message
-
Delete a user
- Description: Delete a user.
- Method: DELETE
- Route: /api/v1/users/:uid
- Access: Private
- Parameters:
- uid (string): User ID.
- Output: Success message
-
get friends
- Description: get a user friends.
- Method: GET
- Route: /api/v1/users/:uid/friends
- Access: Private
- Parameters:
- uid (string): User ID.
- Output: friends
-
Friend request
- Description: send friend request to a user.
- Method: POST
- Route: /api/v1/users/:uid/addFriend
- Access: Private
- Parameters:
- uid (string): User ID.
- Output: Success message
-
confirm friend request
- Description: confirm friend request from a user.
- Method: PUT
- Route: /api/v1/users/:uid/confirmFriend
- Access: Private
- Parameters:
- uid (string): User ID.
- Output: Success message
-
Unfriend
- Description: unfriend a user.
- Method: DELETE
- Route: /api/v1/users/:uid/friends
- Access: Private
- Parameters:
- uid (string): User ID.
- Output: Success message
-
Get Chats
- Description: get all the chats for the current user.
- Method: GET
- Route: /api/v1/chats
- Access: Private
- Output: chats
-
Get messages
- Description: get messages in a single chat.
- Method: GET
- Route: /api/v1/chats/:cid/
- Access: Private
- Parameters:
- cid (string): chat ID.
- Query Parameters:
- page (number): for pagination. defualt = 1.
- Output: messages
-
Delete a message
- Description: delete a message.
- Method: DELETE
- Route: /api/v1/chats/:cid/:mid
- Access: Private
- Parameters:
- cid (string): chat ID.
- mid (string): message ID.
- Output: Success message
-
Send a message
- Description: send a new message to a user.
- Method: POST
- Route: /api/v1/chats/:cid
- Access: Private
- Parameters:
- cid (string): chat ID.
- Output: message
-
Get Group Chats
- Description: get all groups.
- Method: GET
- Route: /api/v1/groups
- Access: Private
- Output: Group
-
Get messages
- Description: get messages in a group chat.
- Method: GET
- Route: /api/v1/groups/:gid/
- Access: Private
- Parameters:
- gid (string): group ID.
- Query Parameters:
- page (number): for pagination. defualt = 1.
- Output: messages
-
Create Group Chat
- Description:create a group.
- Method: POST
- Route: /api/v1/groups
- Access: Private
- Output: Group
-
Update Group Chat
- Description: Update Group Chat.
- Method: PUT
- Route: /api/v1/chats/:cid
- Access: Private (Moderator)
- Parameters:
- gid (string): chat ID.
- Output: Updated Group
-
Delete Group Chat
- Description: delete a group.
- Method: DELETE
- Route: /api/v1/groups/:gid
- Access: Private (Moderator)
- Parameters:
- gid (string): chat ID.
- Output: Success message
-
Send messages
- Description: send a new message to a group.
- Method: POST
- Route: /api/v1/groups/:gid
- Access: Private
- Parameters:
- gid (string): group ID.
- Output: message
-
Get Members
- Description: get members of a group.
- Method: GET
- Route: /api/v1/groups/:gid/members
- Access: Private
- Parameters:
- gid (string): chat ID.
- Output: members
-
Join Request
- Description: send a join request to a group.
- Method: PUT
- Route: /api/v1/groups/:gid/join
- Access: Private
- Parameters:
- gid (string): chat ID.
- Output: Success message
-
Confirm join Request
- Description: confirm join request to a group from a user.
- Method: PUT
- Route: /api/v1/groups/:gid/members/:uid
- Access: Private (Moderator)
- Parameters:
- gid (string): chat ID.
- uid (string): user ID.
- Output: Success message
-
**Remove a Member **
- Description: remove a member / delete join request.
- Method: DELETE
- Route: /api/v1/groups/:gid/members/:uid
- Access: Private (Moderator)
- Parameters:
- gid (string): chat ID.
- Output: Success message
This project is licensed under the MIT License.