Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

44 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ UpBox Backend – Scalable Cloud Storage API

πŸ“Œ Overview

This repository contains the backend system for UpBox, a cloud storage platform inspired by Google Drive.

It is responsible for:

  • Authentication & authorization
  • File & folder management
  • Multipart upload handling (AWS S3)
  • Upload session tracking
  • Real-time updates using Server-Sent Events (SSE)
  • Search functionality (MongoDB Atlas Search)
  • Background processing via AWS Lambda

πŸ—οΈ Backend Architecture

Client (React / Next.js)
        β”‚
        β–Ό
Express API Server (Node.js)
        β”‚
 β”Œβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚      β”‚          β”‚
 β–Ό      β–Ό          β–Ό
MongoDB  AWS S3   SSE Server
(Atlas)  (Storage) (Realtime)
        β”‚
        β–Ό
AWS Lambda (Event Processing)

πŸ“‚ Project Structure

src/
β”œβ”€β”€ controllers/        # Handles request/response logic
β”œβ”€β”€ services/           # Business logic layer
β”œβ”€β”€ middlewares/        # Auth, validation, error handling
β”œβ”€β”€ models/             # Mongoose schemas
β”œβ”€β”€ routes/             # API routes
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ sse/            # SSE connection + broadcast manager
β”‚   └── aws/            # S3 helpers (multipart, presigned URLs)
β”œβ”€β”€ config/             # DB & environment configs

πŸ” Authentication & Authorization

  • JWT-based authentication
  • Middleware-protected routes
  • User-level data isolation (userID enforced across all queries)

Flow:

User Login/Register
        ↓
JWT issued
        ↓
Protected routes validate token
        ↓
UserID injected into request

πŸ“ File Upload System (Multipart – AWS S3)

Why Multipart?

  • Efficient large file uploads
  • Supports resume
  • Parallel chunk uploads

Upload Flow

1. Client β†’ Create upload session
2. Backend β†’ Generate uploadId (S3), Metadata in DB
3. Client β†’ Request presigned URL per chunk
4. Client β†’ Upload chunks directly to S3
5. Backend β†’ Track uploaded parts
6. Backend β†’ Complete multipart upload

Key APIs

  • POST /user/uploadfileΒ β†’ Create upload session, File Metadata
  • GET /user/``file/:fileIDΒ β†’ Get presigned URL
  • POST /user``/uploadfile/initiate β†’ Save uploaded chunk info
  • POST /user/upload/complete β†’ Finalize upload

🧾 Upload Session Management

Schema: UploadSession

Tracks:

  • uploadId
  • fileID
  • uploadedParts
  • chunkSize
  • totalParts

Purpose:

  • Resume uploads
  • Prevent data loss
  • Track upload progress

πŸ“‚ File & Folder System

Features:

  • Nested folder hierarchy
  • Path tracking (pathIds, pathNames)
  • Copy / Paste (recursive cloning)
  • Duplicate handling (auto rename)

Schemas:

File

  • filename
  • storagePath
  • parentID
  • pathIds
  • pathNames
  • size, type
  • status

Folder

  • name
  • parentID
  • pathIds
  • pathNames

πŸ“‘ Real-Time System (SSE)

Why SSE?

  • Lightweight
  • One-way real-time updates
  • Perfect for upload events

Flow:

Client connects β†’ /connection/:userID
        ↓
Server stores connection
        ↓
Events triggered (upload, folder, etc.)
        ↓
Server pushes updates to client

Events:

  • file_uploaded
  • folder_created
  • folder_uploaded
  • file_renamed

πŸ” Search System (MongoDB Atlas Search)

Features:

  • Full-text search
  • Autocomplete
  • Fast indexed queries
  • User-isolated results

Example:

$search:
  compound:
    must β†’ autocomplete/text
    filter β†’ userID

⚑ AWS Integration

S3

  • Multipart upload
  • Pre-signed URLs
  • Direct client uploads

Lambda

Used for:

  • Post-file upload processing
  • Metadata extraction
  • Notifying backend via webhook

πŸ”„ Folder Upload Handling

  • Metadata stored first
  • Files uploaded individually
  • Supports partial success
  • Status-based tracking (pending, completed, failed)

🧠 Design Decisions

1. Direct S3 Upload

  • Reduces backend load
  • Improves scalability

2. Upload Session Layer

  • Enables resume functionality
  • Keeps upload state consistent

3. SSE for Real-Time

  • Simpler than WebSockets
  • Ideal for event-based updates

4. Service Layer Separation

  • Controllers β†’ request/response
  • Services β†’ business logic

πŸ“Š Performance Optimizations

  • Chunked uploads
  • Indexed search (Atlas Search)
  • Parallel upload support
  • SSE instead of polling

πŸ” Security

  • JWT authentication
  • User-scoped queries
  • Pre-signed URL expiration
  • Validation middleware

πŸš€ Setup & Installation

git clone <repo-url>
cd upbox-backend
npm install

Environment Variables

PORT=
MONGO_URI=
JWT_SECRET=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=
S3_BUCKET_NAME=

▢️ Run Server

npm start

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages