Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

121 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š StudyVault

Built by students, for students across India.

A study resource vault β€” upload, browse, bookmark, and review previous year papers, notes, and guides. Built with Node.js, Express, Firebase Firestore, and Cloudinary.

License Node Status

✨ Features

  • Browse & search β€” server-side search with debounce, filters by course/type, 12 papers per page with Load More + infinite scroll
  • Upload resources β€” papers, notes, PYQs, booklets (PDFs, images, docs) β€” new uploads are moderated before going live
  • Bookmarks β€” save papers for quick access (requires sign-in)
  • Reviews & ratings β€” star ratings and reviews, top 3 highest-rated shown on the homepage (requires sign-in)
  • Admin panel β€” manage papers (edit title, type, course, university, year), moderate uploads, view reviews
  • Email notifications β€” for new uploads, reviews, and contact messages (via Resend)
  • Security β€” Firestore rules lock down client writes, rate limiting, input sanitization, XSS-safe rendering, approved-only serving
  • Responsive design β€” works on mobile

πŸ›  Tech Stack

Layer Technology
Frontend Vanilla HTML/CSS/JS (no framework)
Backend Node.js + Express
Database Firebase Firestore
Auth Firebase Auth (Google sign-in)
Storage Cloudinary (files & images)
Email Resend
Hosting Vercel (frontend) + Render (API)

βœ… Prerequisites

πŸš€ Local Setup

1. Clone & Install

git clone https://github.com/umar24nov/StudyVault.git
cd StudyVault
npm install

2. Firebase Setup (Server-side)

  1. Go to Firebase Console β†’ create a project
  2. Build β†’ Firestore Database β†’ Create database (start in test mode)
  3. Project Settings β†’ Service accounts β†’ Generate new private key
  4. Download the JSON file β€” you'll need project_id, client_email, private_key

3. Firebase Setup (Web β€” client-side)

  1. Project Settings β†’ General β†’ Your apps β†’ Add web app
  2. Copy the firebaseConfig object β€” you'll need apiKey, authDomain, projectId, appId, messagingSenderId
  3. Open frontend/index.html and frontend/admin/index.html, find the firebaseConfig object, and replace the placeholder values with your real ones

4. Cloudinary Setup

  1. Sign up at cloudinary.com
  2. From Dashboard, copy: Cloud Name, API Key, API Secret

5. Environment File

Create .env in the project root:

# Server-side Firebase (from service account JSON)
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_CLIENT_EMAIL=your-client-email@your-project.iam.gserviceaccount.com
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYourKeyHere\n-----END PRIVATE KEY-----\n"

# Cloudinary
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secret

# Resend (optional β€” for email notifications)
# Sign up at https://resend.com. Sends emails for contact form, new uploads, and new reviews.
RESEND_API_KEY=re_xxxxxxxxxxxx

Important for FIREBASE_PRIVATE_KEY: Wrap in double quotes and keep \n as literal characters. The server normalizes them automatically.

6. Run

node backend/server.js
# or: npm start / npm run dev

Open http://localhost:3000 in your browser.

πŸ—„ Firestore Rules

Deploy the locked-down rules before going to production:

firebase deploy --only firestore:rules

All writes go through the API (Firebase Admin SDK), so clients can only read approved data and manage their own bookmarks/profile.

πŸ” Firestore Indexes

After your app is running, create these composite indexes in Firebase Console β†’ Firestore β†’ Indexes:

Collection Fields
papers status Asc, createdAt Desc
papers status Asc, downloads Desc
bookmarks userId Asc, createdAt Desc
bookmarks userId Asc, paperId Asc

Without these indexes, queries will fail with a 500 error.

πŸ›‘ Making an Admin

  1. In Firebase Console β†’ Firestore, create a collection called admins
  2. Create a document with the user's Firebase UID as the document ID
  3. Add a field role: "admin"
  4. That user will now see the Admin link in the navbar and can access /admin/

πŸ§ͺ Tests

npm test

The test suite validates all API endpoints (papers, search, downloads, bookmarks, reviews, feedback, contact, admin auth) β€” 14 tests passing. A GitHub Actions CI workflow runs tests and syntax checks on Node 18/20/22.

🌍 Deployment

Frontend (Vercel)

  1. Connect your GitHub repo to Vercel
  2. Set Root Directory to frontend
  3. Deploy β€” no build step needed for static files

API Server (Render)

  1. Create a Web Service on Render, connected to your GitHub repo
  2. Build Command: (leave empty)
  3. Start Command: node backend/server.js
  4. Add environment variables from your .env file
  5. Required: Add NODE_OPTIONS=--openssl-legacy-provider (needed for OpenSSL 3.x / Node 22 compatibility with firebase-admin)
  6. Set app.set('trust proxy', 1) β€” already in server.js (needed behind Render's reverse proxy)

πŸ“ Project Structure

StudyVault/
β”œβ”€β”€ backend/                # All server-side code
β”‚   β”œβ”€β”€ server.js           # Express server (entry point)
β”‚   β”œβ”€β”€ firestore.rules     # Firestore security rules
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”œβ”€β”€ env.js          # Environment variable validation (Zod)
β”‚   β”‚   β”œβ”€β”€ firebase.js     # Firebase Admin SDK init
β”‚   β”‚   β”œβ”€β”€ cloudinary.js   # Cloudinary init
β”‚   β”‚   └── email.js        # Resend email helper
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”œβ”€β”€ auth.js         # Auth middleware (verifyToken, requireAdminAuth)
β”‚   β”‚   β”œβ”€β”€ rateLimit.js    # Rate limiters
β”‚   β”‚   β”œβ”€β”€ upload.js       # Multer file upload config
β”‚   β”‚   β”œβ”€β”€ sanitize.js     # Input sanitization (stripDangerous, validation)
β”‚   β”‚   └── errorHandler.js # Global error handler
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ papers.js       # Paper browse/search/download
β”‚   β”‚   β”œβ”€β”€ bookmarks.js    # Bookmark toggle / list
β”‚   β”‚   β”œβ”€β”€ reviews.js      # Ratings & reviews (requires auth)
β”‚   β”‚   β”œβ”€β”€ feedback.js     # Feedback & contact form submissions
β”‚   β”‚   β”œβ”€β”€ admin.js        # Admin-only endpoints (incl. paper editing)
β”‚   β”‚   └── users.js        # User profile data
β”‚   β”œβ”€β”€ scripts/
β”‚   β”‚   └── migrate-status.js # Legacy record migration
β”‚   β”œβ”€β”€ utils/
β”‚   └── __tests__/
β”‚       └── api.test.js     # API integration tests (14 tests)
β”œβ”€β”€ frontend/               # All client-side code (Vercel root = frontend)
β”‚   β”œβ”€β”€ index.html          # Main frontend
β”‚   β”œβ”€β”€ admin/              # Admin panel (served at /admin/)
β”‚   β”‚   β”œβ”€β”€ index.html
β”‚   β”‚   β”œβ”€β”€ admin.js
β”‚   β”‚   └── admin.css
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   └── style.css       # All frontend styles
β”‚   β”œβ”€β”€ js/
β”‚   β”‚   └── app.js          # Frontend logic
β”‚   β”œβ”€β”€ assets/
β”‚   β”‚   β”œβ”€β”€ logo.svg        # Brand logo
β”‚   β”‚   └── favicon.ico     # Browser favicon
β”‚   β”œβ”€β”€ robots.txt
β”‚   └── sitemap.xml
β”œβ”€β”€ .github/workflows/
β”‚   └── ci.yml              # CI β€” syntax checks + tests on Node 18/20/22
β”œβ”€β”€ firebase.json           # Points firestore rules β†’ backend/firestore.rules
β”œβ”€β”€ .env                    # Local env vars (not committed)
β”œβ”€β”€ package.json
β”œβ”€β”€ LICENSE
└── .gitignore

πŸ“§ Email Notifications

When RESEND_API_KEY is set, email notifications are sent to studyvaultapp@gmail.com for:

  • New uploads β€” title, course, type, uploader name
  • New reviews β€” name, star rating, review text
  • Contact form β€” name, email, message

Without the key, notifications are silently skipped (data is still saved to Firestore).

🀝 Contributing

  1. Fork the repo
  2. Create a branch: git checkout -b feature/your-feature
  3. Commit changes: git commit -m "Add your feature"
  4. Push: git push origin feature/your-feature
  5. Open a Pull Request

πŸ“„ License

MIT Β© Mohammad Umar

About

A centralized platform for students to store, share, and discover study materials.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages