How kuzma02/secured-file-share works
Project type and purpose
• This is a full-stack web application (“Secured File Share”) built with the MERN stack (MongoDB, Express.js, React, Node.js).
• Purpose: allow users to upload/download files securely with end-to-end encryption, password protection, brute-force protection, input sanitization, and email notifications.
File structure
• Root:
• app.js – entry point for the Express server
• routes/main.js – defines REST endpoints (upload, download, history, etc.)
• controllers/ – implements business logic (main.js handles file operations; sendEmail.js handles Mailjet integration)
• db/connect.js – MongoDB connection setup
• models/File.js – Mongoose schema for file metadata
• package.json & .env – server dependencies and config
• client/:
• index.html, vite.config.js, tailwind.config.js – front-end build/config
• src/: React code (pages, components, assets)
• package.json – React, Vite, Clerk (authentication), Tailwind CSS
• uploads/ (created at runtime) – local file storage for encrypted payloads
README for additional insights
• Security measures: Helmet, express-mongo-sanitize, xss-clean, rate-limiting
• External services: Clerk for authentication, Mailjet for transactional emails
• Deployment: Node.js server and Vite dev server
Main components and their interactions
a. Front-End (React/Vite)
• Pages/components under client/src
• Responsible for UI: upload forms, password prompts, file history, download pages
• Auth flow via Clerk (VITE_CLERK_PUBLISHABLE_KEY)
b. API Layer (Express.js server)
• app.js configures middleware (CORS, security headers, rate-limit, sanitizers)
• routes/main.js delegates to controllers
• controllers/main.js: handle encryption/decryption, file I/O, input validation
• controllers/sendEmail.js: integrate with Mailjet API to send download links
c. Data Layer
• MongoDB (db/connect.js + models/File.js) stores file metadata (owner, filename, encryption key hash, password hash, expiration)
• File System (“uploads/” directory) stores encrypted binaries
d. External Services
• Clerk (Auth provider) for user identity management
• Mailjet API for email notifications
Relationships & data flow:
1. User (Browser) ↔ Clerk (OAuth/webhooks)
2. Browser → Express API (/api/upload, /api/request-download)
3. Express → MongoDB (CRUD on File metadata)
4. Express → File System (read/write encrypted files)
5. Express → Mailjet (send download password/email link)
6. Browser ← Express API (download streams, history data)
Architectural patterns and design principles
• Layered MVC-style structure:
Presentation (React UI) ↔ Controllers (Express) ↔ Models (Mongoose)
• Security-first: centralized middleware for sanitization, rate-limiting, headers
• Single codebase separation: “client” folder vs. server root
• RESTful API design
Essential details to capture
• Separation of concerns: UI vs. API vs. Data
• Security middleware chain in Express
• End-to-end encryption flow (client encrypts → server stores encrypted → client decrypts)
• Password protection and validation logic
• External auth (Clerk) and email service (Mailjet) integration points