A robust, scalable social media backend service designed to handle user authentication, post management, and secure media uploads.
- Secure Media Storage: Direct integration with AWS S3 buckets for highly available and scalable image hosting.
- RESTful Architecture: Clean, modular API design following industry best practices for routing and controller logic.
- Database Management: Efficient data modeling and querying using MongoDB and Mongoose.
- Authentication: Secure user session management and password hashing (Custom auth flow, no third-party OAuth providers).
- Caching & Performance: Integration with Redis to optimize data retrieval and API response times.
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB
- Cloud Storage: AWS S3
- Caching: Redis
Here is a high-level overview of the primary RESTful routes:
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/api/users/register |
Register a new user | No |
POST |
/api/users/login |
Authenticate and start session | No |
POST |
/api/posts/upload |
Upload image to AWS S3 & create post | Yes |
GET |
/api/posts/feed |
Retrieve paginated user feed | Yes |
DELETE |
/api/posts/:id |
Remove post and associated S3 media | Yes |
Here is a high-level overview of how the backend services interact and the structure of our data.
graph TD
Client[📱 Client / Frontend] -->|API Request| API[🚀 Express API Server]
subgraph "Backend Services (Node.js)"
API -->|1. Auth Middleware| Auth[🔒 JWT Auth]
Auth -->|2. Route Handler| API
end
subgraph "Data & Storage Layers"
API <-->|Cache Lookup/Write| Redis[(🧠 Redis Cache)]
API <-->|CRUD Operations| DB[(🍃 MongoDB Database)]
API <-->|Image Upload/Delete| S3[(☁️ AWS S3 Bucket)]
end
classDef client fill:#f9f,stroke:#333,stroke-width:2px;
classDef server fill:#bbf,stroke:#333,stroke-width:2px;
classDef storage fill:#dfd,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5;
class Client client;
class API server;
class Auth,Redis,DB,S3 storage;
erDiagram
USER ||--o{ POST : creates
USER {
ObjectId _id PK
string username
string email
string passwordHash
date createdAt
}
POST {
ObjectId _id PK
ObjectId userId FK
string s3ImageUrl
string s3Key
string caption
date createdAt
}
To run this project, you will need to add the following environment variables to your .env file:
PORT
MONGO_URI
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_REGION
AWS_BUCKET_NAME
REDIS_URL
- Clone the repository:
git clone https://github.com/Hexacoder5678/ImageGram.git