A modern learning platform designed specifically for freshmen students, providing access to course modules, educational resources, quizzes, exams, and video content. Built with SvelteKit and optimized for Telegram Web Apps.
FreshHub is a comprehensive educational platform that enables students to:
- Browse and access course materials
- View PDF modules and short notes
- Watch educational videos
- Take timed exams and quizzes
- Get personalized learning experiences through Telegram integration
- Course Management: Browse and access multiple courses with organized modules
- Resource Library: Access PDFs, modules, and short notes per course
- Video Learning: Integrated YouTube video player for course content
- Exam System: Timed exams and quizzes with multiple-choice and fill-in-the-blank questions
- PDF Viewer: Built-in PDF viewer using PDF.js Express
- Search: Search functionality across courses and resources
- Telegram Integration: Seamless authentication and experience within Telegram Web App
- Dark Mode: Full dark mode support with system preference detection
- Responsive Design: Modern, mobile-first UI built with Tailwind CSS
- Animations: Smooth Lottie animations for enhanced UX
- Theme Toggle: Easy switching between light and dark themes
- Serverless Architecture: All API routes are serverless functions (no separate backend deployment)
- Real-time Authentication: Telegram-based and credential-based authentication
- State Management: Efficient Svelte stores for global state
- API Integration: RESTful API via SvelteKit serverless endpoints
- Database: Supabase (PostgreSQL) for data persistence
- AI Integration: Google Gemini API for question extraction from PDFs
- Security: Input validation, rate limiting, and standardized error handling
- Framework: SvelteKit 2.x
- Language: TypeScript
- Styling: Tailwind CSS 4.x
- PDF Viewer: PDF.js Express 8.7.5
- Video Player: Svelte YouTube Lite
- Animations: Lottie Web
- Icons: Custom Lottie animations
- Framework: SvelteKit API Routes (serverless functions)
- Runtime: Node.js (via SvelteKit adapter)
- Database: Supabase (PostgreSQL)
- Authentication: Telegram Web App + Supabase Auth
- Validation: Zod schema validation
- Rate Limiting: In-memory rate limiting (configurable per endpoint)
- AI: Google Generative AI (Gemini)
- Build Tool: Vite 7.x
- Package Manager: npm
- Code Quality: Prettier, Svelte Check
- Deployment: Vercel/Cloudflare (adapter-auto)
Before you begin, ensure you have:
- Node.js (v18 or higher)
- npm or yarn
- A Supabase account and project
- A Telegram Bot Token (for Telegram integration)
- Google Gemini API Key (for question extraction feature)
git clone <repository-url>
cd FreshHubnpm installCreate a .env file in the root directory:
# Supabase Configuration
PUBLIC_SUPABASE_URL=your_supabase_url
PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
# For serverless functions (private)
SUPABASE_URL=your_supabase_url
SUPABASE_ANON_KEY=your_supabase_anon_key
# Telegram Configuration
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
# Google Gemini API (Optional, for question extraction)
GEMINI_API_KEY=your_gemini_api_key
# Environment
NODE_ENV=developmentSet up your Supabase database with the following tables:
courses- Course informationresources- PDFs, modules, and notesvideos- Video resourcesexams- Exam metadataexam_questions- Questions for examsusers- User accountsfeedback_messages- User feedback
Refer to implementation_guide_exam_quiz.txt for detailed database schema.
npm run devThe frontend will be available at http://localhost:5173 (or the port Vite assigns).
cd backend
npm run devThe backend API will be available at http://localhost:4000.
npm run build
npm run move-pdfjs # Copies PDF.js assets to static folder
npm run preview # Preview production buildFreshHub/
βββ src/
β βββ api/ # API controllers and fetchers
β β βββ controllers/ # Business logic controllers
β βββ components/ # Svelte components
β βββ config/ # Configuration files
β β βββ supabase/ # Supabase client setup
β βββ lib/ # Shared libraries
β β βββ server/ # Serverless utilities
β β β βββ errors.ts # Error handling
β β β βββ validation.ts # Input validation
β β β βββ rateLimit.ts # Rate limiting
β β β βββ logger.ts # Logging
β β β βββ verifyTelegram.ts # Telegram verification
β β βββ actions/ # Svelte actions
β β βββ stores/ # Svelte stores (state management)
β βββ routes/ # SvelteKit routes
β β βββ api/ # Serverless API endpoints
β β β βββ auth/ # Authentication endpoints
β β β βββ courses/ # Course endpoints
β β β βββ exams/ # Exam endpoints
β β β βββ resources/ # Resource endpoints
β β β βββ videos/ # Video endpoints
β β βββ course/ # Course pages
β β βββ courses/ # Courses listing
β βββ types/ # TypeScript type definitions
β βββ utils/ # Utility functions
βββ static/ # Static assets
β βββ lottie/ # Lottie animation files
β βββ pdfjs-express/ # PDF.js Express assets
βββ scripts/ # Utility scripts
β βββ SetWebHook.js # Telegram webhook setup
βββ package.json # Project dependencies
The project uses a centralized UI store to manage page titles:
import { onMount } from 'svelte';
import { setPageTitle } from '$lib/stores/uiStore';
onMount(() => setPageTitle('My Page Title'));Two authentication methods are supported:
- Telegram Authentication: Automatic authentication via Telegram Web App
- Credential Authentication: Username/password authentication
The auth store (src/lib/stores/auth.ts) provides:
isAuthenticated- Writable store for auth statusloginDemo()- Demo login functionloginWithTelegramInit()- Telegram-based loginloginWithBackend()- Credential-based loginlogout()- Logout function
Svelte stores are used for state management:
auth.ts- Authentication statecoursesContext.ts- Course data and cachingresourcesContext.ts- Resource datathemeStore.ts- Theme preferencesuiStore.ts- UI state (page titles, etc.)overlayLoader.ts- Loading overlay state
The app detects if it's running in a Telegram Web App and:
- Automatically authenticates users
- Syncs theme with Telegram's color scheme
- Expands to full screen
- Enables closing confirmation
GET /api/courses- Get all courses (rate limited)GET /api/resources?courseId={uuid}&type={optional}- Get resources by course (rate limited, validated)GET /api/videos?courseId={uuid}- Get videos by course (rate limited, validated)GET /api/exams?courseId={uuid}- Get exams by course (strict rate limit, validated)GET /api/exams/all- Get all exams (strict rate limit)GET /api/questions?examId={uuid}- Get questions for an exam (strict rate limit, validated)POST /api/auth/login- Telegram login (strict rate limit, validated)POST /api/auth/signup- Telegram signup (strict rate limit, validated)POST /api/feedback- Submit feedback (rate limited, validated)POST /api/telegram- Telegram webhook (for bot commands)GET /api/users- Get all users (rate limited)
All endpoints:
- Return standardized JSON responses with
{ ok: boolean, data?: T, error?: string, code?: string } - Include rate limit headers (
X-RateLimit-*) - Validate input using Zod schemas
- Handle errors consistently
npm run dev # Start development server
npm run build # Build for production
npm run preview # Preview production build
npm run check # Type check with svelte-check
npm run check:watch # Type check in watch mode
npm run format # Format code with Prettier
npm run lint # Lint code
npm run move-pdfjs # Copy PDF.js assetsThe project includes a vercel-build script:
npm run vercel-buildEnsure all environment variables are set in your deployment platform:
SUPABASE_URLSUPABASE_ANON_KEYTELEGRAM_BOT_TOKENGEMINI_API_KEY(if using AI features)
The project uses:
- Prettier for code formatting
- TypeScript for type safety
- Svelte Check for Svelte-specific validation
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is private and proprietary.
Run npm run move-pdfjs after installing dependencies or building.
- Ensure
TELEGRAM_BOT_TOKENis set correctly - Verify webhook is configured (use
scripts/SetWebHook.js) - Check that the app is running within Telegram Web App context
- Verify
SUPABASE_URLandSUPABASE_ANON_KEYare correct - Check Supabase project settings and API access
- Ensure database tables are created
- Verify environment variables are set correctly
- Check that Supabase connection is working
- Review rate limit headers if getting 429 errors
- Check serverless function logs in your deployment platform
- SvelteKit Documentation
- Supabase Documentation
- Telegram Bot API
- Tailwind CSS Documentation
- PDF.js Express Documentation
FreshHub Development Team
Note: This project is designed to work primarily as a Telegram Web App but can also function as a standalone web application.