This document outlines the API routes for an Express.js-based web application, using the base path http://localhost:<port>/api/v1. The API supports core social media features, including user authentication, posts, comments, likes, stories, user profiles, and real-time private messaging and notifications.
All routes require the base path http://localhost:<port>/api/v1. Endpoints marked with π require a valid JWT token in the Authorization header (e.g., Bearer <token>).
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
| POST | /login |
Authenticate user with credentials π§βπ» | None |
| POST | /signup |
Register a new user account π | None |
| POST | /renew-tokens |
Refresh user authentication tokens π | None |
| GET | /logout |
Log out user πͺ | π Required |
| POST | /account/forgot-password |
Request a password reset link π | None |
| POST | /account/reset-password |
Reset user password π | None |
| GET | /account/reset-password-form |
Display password reset form π | None |
| GET | /account/verify-email |
Verify email address via link π§ | None |
| POST | /account/verify-email |
Send verification email π§ | π Required |
| POST | /account/verify-by-code |
Verify email using a code π¨ | None |
| DELETE | /account/delete |
Delete user account ποΈ | π Required |
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
| GET | /posts |
Retrieve all posts π | None |
| POST | /posts |
Create post (single file: post) πΌοΈ |
π Required |
| GET | /posts/:postId |
Retrieve specific post π | None |
| DELETE | /posts/:postId |
Delete post ποΈ | π Required |
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
| GET | /comments |
Retrieve all comments π£οΈ | None |
| POST | /comments |
Create comment βοΈ | π Required |
| PATCH | /comments/:commentId |
Update comment π | π Required |
| DELETE | /comments/:commentId |
Delete comment ποΈ | π Required |
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
| POST | /likes |
Add like π | π Required |
| DELETE | /likes/:postId |
Remove like π | π Required |
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
| POST | /stories |
Upload story (single file: story) π₯ |
π Required |
| GET | /stories/:storyId |
Retrieve specific story πΊ | None |
| PATCH | /stories/:storyId/view |
Increment story views π | None |
| DELETE | /stories/:storyId |
Delete specific story ποΈ | π Required |
| DELETE | /stories |
Delete all user stories ποΈ | π Required |
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
| GET | /profile/:username |
Retrieve user profile by username π€ | None |
| GET | /profile/current-user |
Retrieve current user profile πͺ | π Required |
| PATCH | /account/edit |
Update user settings βοΈ | π Required |
| PATCH | /profile/avatar |
Update avatar (single file: avatar) πΌοΈ |
π Required |
| DELETE | /profile/avatar |
Remove avatar ποΈ | π Required |
| PUT | /profile/change-password |
Change password π | π Required |
| POST | /profile/:userId/follow |
Follow user β | π Required |
| DELETE | /profile/:userId/unfollow |
Unfollow user β | π Required |
| GET | /profile/:username/followers |
Retrieve user's followers π₯ | None |
| GET | /profile/:username/following |
Retrieve user's following list π₯ | None |
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
| GET | /messages/:username |
Retrieve conversations for a user π¬ | π Required |
| DELETE | /messages/:messageId |
remove message from database ποΈ | π Required |
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
| GET | /health |
Check API health β | None |
- Authentication Routes:
- Handle user login, signup, token refresh, logout, and account management (password reset, email verification, account deletion).
- Example:
POST /loginexpects{ email, password }and returns JWT tokens.
- Posts Routes:
- Manage social media posts, including creation (with file upload), retrieval, and deletion.
- Example:
POST /postsrequires a multipart form with apostfile.
- Comments Routes:
- Allow users to view, create, update, or delete comments on posts.
- Example:
POST /commentsexpects{ text: string }.
- Likes Routes:
- Enable liking and unliking posts.
- Example:
POST /likesexpects{ postId: string }.
- Stories Routes:
- Support story uploads, views, and deletions.
- Example:
POST /storiesrequires a multipart form with astoryfile.
- User Profile Routes:
- Manage user profiles, avatars, passwords, and follow/unfollow actions.
- Example:
PATCH /profile/avatarrequires a multipart form with anavatarfile.
- Messages Route:
- Retrieve private conversations between the authenticated user and a specified user.
- Middleware:
validateAuthensures JWT authentication. - Example:
GET /messages/johndoereturns[{ id: 1, recipient: "johndoe", message: "Hello!", timestamp: "2025-05-16T12:13:00Z" }, ...].
- Health Check Route:
- Verify API availability.
- Example:
GET /healthreturns{ status: "OK" }.
- 400 Bad Request: Invalid request body or parameters.
- 401 Unauthorized: Missing or invalid JWT token.
- 404 Not Found: Resource (e.g., post, user) not found.
- 500 Internal Server Error: Unexpected server issues.
The API supports real-time private messaging and notifications to enable instant communication between users. Private messaging allows users to send and receive messages in real time, with messages stored in MongoDB for persistence. Notifications are triggered for events like new messages, likes, follows, or other interactions.
- Private Messaging: Users can join private conversation rooms and exchange messages instantly. Messages are saved in MongoDB for chat history retrieval.
- Notifications: Real-time alerts for new messages, likes, follows, or other interactions, with RESTful routes for managing notification state.
- Security: All real-time interactions require JWT authentication to ensure only authorized users can send or receive messages and notifications.
- Docker
- Docker Compose
- Node.js (for local development)
The compose.yml defines the service configuration for the API and MongoDB.
- Create a
.envfile in the project root to configure environment variables. Example:Ensure sensitive information likeNODE_ENV=development PORT=3000 DATABASE_URL=mongodb://mongodb:27017/instagram ARGON2_ROUND=10 JWT_ACCESS_TOKEN_SECRET_KEY=your_access_secret JWT_REFRESH_TOKEN_SECRET_KEY=your_refresh_secret JWT_ACCESS_TOKEN_EXPIRY_TIME=1d JWT_REFRESH_TOKEN_EXPIRY_TIME=7d CLOUDINARY_CLOUD_NAME=your_cloud_name CLOUDINARY_API_KEY=your_api_key CLOUDINARY_API_SECRET=your_api_secret RESEND_API_KEY=your_resend_api_key CLIENT_ORIGIN=http://localhost:3000RESEND,CLOUDINARY, andJWTsecrets is securely generated and stored. π
- Clone repository:
git clone https://github.com/pxycknomdictator/instagram-backend-api.git cd instagram-backend-api - Install dependencies:
npm install
- Create and configure the
.envfile as described above. π - Start services:
docker-compose up
This project is licensed under the MIT License. See the LICENSE file for details.