Full‑stack learning platform built with React (Vite) and Express/MongoDB. It includes email/password auth, GitHub OAuth login, course/quiz content, a streaming AI chatbot (Gemini), comments, progress tracking, and a responsive UI.
- React + Vite SPA with React Router
- Auth: Email/Password and “Continue with GitHub” OAuth
- AI Chatbot: Gemini streaming responses with URL context ingestion
- Courses, quizzes, comments, and progress tracking
- Rate limiting, static uploads, and 404 handling on the backend
- Tailwind CSS styling and a clean, componentized UI
- Frontend: React 19, Vite 7, React Router, Tailwind CSS
- Backend: Node/Express, MongoDB/Mongoose, JWT
- AI: @google/generative‑ai (Gemini)
sp-webapp/
├─ backend/
│ ├─ server.js # Express bootstrap, CORS, rate-limits, routes, uploads
│ ├─ models/
│ │ └─ user.js # Mongoose User model
│ ├─ routes/
│ │ ├─ auth.js # Register/Login/Me
│ │ ├─ oauth.js # GitHub OAuth start + callback
│ │ ├─ gemini.js # Chat + streaming + URL summarization
│ │ ├─ courses.js, quizzes.js, comments.js, ...
│ └─ uploads/ # Static files served at /uploads
├─ src/
│ ├─ App.jsx # Router + protected/public routes
│ ├─ context/AuthContext.jsx # Auth state, token storage, helpers
│ ├─ lib/api.js # API base URL helper
│ ├─ pages/ # Route pages (login, register, home, chatbot, etc.)
│ │ ├─ login.jsx # Email/password + GitHub button
│ │ └─ oauth-success.jsx # OAuth token handoff and redirect
│ └─ components/, features/ # UI components and features
├─ public/ # Static assets served by Vite
├─ vite.config.js # Vite dev server + API proxy (to 5050)
├─ package.json # Scripts and dependencies
└─ README.md # You are here
Backend (required):
MONGO_URI— MongoDB connection stringJWT_SECRET— Secret to sign app JWTs
Backend (optional / recommended):
PORT— API port (default: 5050)HOST— API host (default: 0.0.0.0 for containers/Render)FRONTEND_URL— SPA origin for OAuth redirects (e.g., http://localhost:5173 or https://app.example.com)GITHUB_CLIENT_ID— GitHub OAuth App client IDGITHUB_CLIENT_SECRET— GitHub OAuth App client secretGITHUB_REDIRECT_URI— Explicit callback URL if needed (defaults tohttps://<host>/api/oauth/github/callback)
Frontend (optional):
VITE_API_BASE_URL— Absolute API base (omit when using Vite proxy)VITE_GITHUB_OAUTH_URL— Absolute OAuth start URL (defaults to/api/oauth/github)
Prereqs:
- Node.js 18+ (backend uses global fetch)
- MongoDB instance (local or hosted)
Install dependencies:
npm installSet environment variables (create a .env in repo root):
MONGO_URI="mongodb://localhost:27017/sp-webapp"
JWT_SECRET="replace-with-strong-secret"Run in development (two processes):
# Terminal 1: start the API server (http://localhost:5050)
npm run server
# Terminal 2: start the Vite dev server (http://localhost:5173)
npm run devOr run both with one command:
npm run dev:fullBuild for production:
npm run build
# then start only the backend; it serves API only (front-end is static elsewhere)
npm startNote: The Vite dev server proxies /api and /uploads to http://localhost:5050 (see vite.config.js).
- Create a GitHub OAuth app: https://github.com/settings/developers
- Set the Authorization callback URL(s):
- Local:
http://localhost:5050/api/oauth/github/callback - Prod:
https://<your-api-host>/api/oauth/github/callback
- Local:
- Add env vars to your backend environment:
GITHUB_CLIENT_ID,GITHUB_CLIENT_SECRET, optionallyFRONTEND_URLandGITHUB_REDIRECT_URI.
- Flow:
- Login page → “Continue with GitHub” →
/api/oauth/github - GitHub consent →
/api/oauth/github/callback - Backend issues JWT, redirects to SPA
/oauth/success?token=...&user=... - Frontend stores token/user and navigates to home
- Login page → “Continue with GitHub” →
npm run dev— Start Vite dev server (frontend)npm run server— Start backend Express servernpm run dev:full— Run both servers concurrentlynpm run build— Build frontend assetsnpm start— Start backend (suitable for hosting providers)
This project is open-source; feel free to use and customize it.
