# mvarunreddy8203/sendit architecture

> Architecture diagram of the GitHub repository mvarunreddy8203/sendit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mvarunreddy8203/sendit
- Repository: https://github.com/mvarunreddy8203/sendit

## Overview

##### Project Overview
- SendIt is a full-stack file transfer service that allows users to send files to an email address without any signup. It consists of a clear separation between frontend and backend components.
- The frontend is built on React (with Vite as a build tool) and uses ChakraUI for its UI components. The backend is a NodeJS-based server using Express, which handles file uploads, file metadata management (with Firebase Firestore and Firebase Storage), rate limiting via Redis (Upstash), and sending emails via NodeMailer.

##### Main Components
a. Frontend:
- Represents the user interface where users interact, fill in details (email and file upload), and show status notifications (via the custom toast hook).
- Architecturally, it interacts with the backend via the /upload and /warmup API endpoints.

b. Backend:
- Acts as the API layer handling file upload (POST /upload), file download (GET /download/:fileID), and server warmup (GET /warmup).
- Contains middleware such as the rateLimiter, which consults Redis to prevent abuse.
- Implements background tasks (via a setInterval mechanism) to check and delete expired files.

c. External and Supporting Services:
- Firebase Firestore: NoSQL database for storing file metadata.
- Firebase Storage: For actually storing the uploaded file objects.
- Redis (via Upstash): For in-memory caching and rate limiting.
- Email Service: Managed through NodeMailer (configured with a Gmail account) to send file download links and metadata.
- Optional: Cron-job or periodic pinging mechanism for keeping the backend “warmed up” to counteract Render’s sleep mode.

##### Relationships and Data Flow
- User submits file and email via the frontend.
- The Frontend sends a POST request to the backend’s /upload endpoint.
- The backend uses Multer to handle file upload, then generates a unique filename using uuid, and uploads the file to Firebase Storage under a ‘files’ folder.
- After the file is stored, file metadata (including upload and expiry dates) is saved in Firestore.
- A signed URL (with 7-day expiry) is generated and returned in response.
- The backend then sends an email (using NodeMailer) with download details to the user.
- Additional data flows:
- GET /download/:fileID: retrieves file metadata, generates a signed URL valid for 15 minutes, and sends the file to the user.
- GET /warmup: used for pinging the backend server to keep it active.
- The rate limiter communicates with Redis to verify request frequency.
- A background worker (using setInterval) periodically checks for and deletes expired files.

##### Architectural Patterns and Principles
- Layered architecture, with clear separation between frontend (UI), backend (API/business logic), and external services (Firebase, Redis, Email).
- Use of middleware (rateLimiter) and background processing for maintenance tasks.
- Deployment separation: the frontend is deployed on Vercel, and the backend on Render, with environment-specific configuration provided via .env files.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    User["User (Browser)"]:::external

    %% Frontend
    subgraph "SendIt Frontend"
        FE1["React Frontend\n(Vite, ChakraUI)"]:::frontend
        FE2["React Components & UI"]:::frontend
        FE3["Custom Toast Hook\n(useShowToast)"]:::frontend
        FE4["Firebase Setup\n(Firebase Storage/Firestore)"]:::frontend
    end

    %% Backend
    subgraph "SendIt Backend"
        BE1["Express API Server\n(NodeJS, Express)"]:::backend
        BE2["File Handling\n(Multer, UUID)"]:::backend
        BE3["API Endpoints\n/upload, /download/:fileID, /warmup"]:::backend
        BE4["Rate Limiter\n(Upstash Redis)"]:::backend
        BE5["Background Worker\n(File Deletion Task)"]:::backend
        BE6["Email Sending\n(NodeMailer)"]:::backend
    end

    %% External Services
    subgraph "External Services"
        EX1["Firebase Firestore\n(File Metadata)"]:::external
        EX2["Firebase Storage\n(File Storage)"]:::external
        EX3["Redis Cache\n(Rate Limiting)"]:::external
        EX4["Email Service\n(Gmail via NodeMailer)"]:::external
    end

    %% Data Flow / Relationships
    User -->|"Uses" | FE1
    FE1 -->|"POST/upload\nGET/warmup" | BE1
    FE1 -->|"GET/download/:fileID" | BE1

    BE1 -->|"Handles file upload" | BE2
    BE1 -->|"API Endpoints" | BE3
    BE1 -->|"Checks rate limits" | BE4
    BE1 -->|"Sends emails" | BE6
    BE1 -->|"Triggers background tasks" | BE5

    BE2 -->|"Uploads file" | EX2
    BE2 -->|"Generates metadata" | EX1

    BE4 -->|"Verifies requests" | EX3

    BE6 -->|"Sends download link" | EX4

    %% Styling Classes
    classDef frontend fill:#e0f7fa,stroke:#00796b,stroke-width:2px;
    classDef backend fill:#f1f8e9,stroke:#33691e,stroke-width:2px;
    classDef external fill:#ffecb3,stroke:#ff6f00,stroke-width:2px;

    %% Click Events for Frontend Components
    click FE1 "https://github.com/mvarunreddy8203/sendit/tree/main/sendit_frontend/" "Frontend Root"
    click FE2 "https://github.com/mvarunreddy8203/sendit/blob/main/sendit_frontend/src/App.jsx" "App.jsx"
    click FE2 "https://github.com/mvarunreddy8203/sendit/blob/main/sendit_frontend/src/components/InputForm/InputForm.jsx" "Input Form Component"
    click FE2 "https://github.com/mvarunreddy8203/sendit/tree/main/sendit_frontend/src/test/" "Test Components Directory"
    click FE3 "https://github.com/mvarunreddy8203/sendit/blob/main/sendit_frontend/src/hooks/useShowToast.js" "Custom Toast Hook"
    click FE4 "https://github.com/mvarunreddy8203/sendit/blob/main/sendit_frontend/src/firebase/firebase.js" "Frontend Firebase Setup"

    %% Click Events for Backend Components
    click BE1 "https://github.com/mvarunreddy8203/sendit/tree/main/sendit_backend/" "Backend Root"
    click BE3 "https://github.com/mvarunreddy8203/sendit/blob/main/sendit_backend/index.js" "Backend API and Endpoints"
```
