Skip to content

swciitg/Hackstack-Portal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

37 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Hackstack Portal πŸš€

A modern Learning Management System (LMS) built by the Student Web Committee for hosting educational modules, quizzes, progress tracking, and leaderboards.

πŸ“‹ Table of Contents


πŸ› οΈ Tech Stack

Backend

  • Runtime: Node.js
  • Framework: Express.js
  • Database: MongoDB (Cloud: MongoDB Atlas)
  • Authentication: GitHub OAuth 2.0 + JWT
  • Package Manager: npm

Frontend

  • Framework: React 19
  • Router: React Router DOM v7
  • Build Tool: Vite
  • Styling: Tailwind CSS
  • Animations: Framer Motion
  • Package Manager: npm

πŸ“ Project Structure

Hackstack-Portal/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── db.js                 # Database connection config
β”‚   β”œβ”€β”€ controllers/              # Business logic
β”‚   β”‚   β”œβ”€β”€ authController.js
β”‚   β”‚   β”œβ”€β”€ moduleController.js
β”‚   β”‚   β”œβ”€β”€ userController.js
β”‚   β”‚   β”œβ”€β”€ progressController.js
β”‚   β”‚   └── quizController.js
β”‚   β”œβ”€β”€ middleware/               # Express middleware
β”‚   β”‚   β”œβ”€β”€ authMiddleware.js     # JWT verification
β”‚   β”‚   └── adminMiddleware.js    # Admin role check
β”‚   β”œβ”€β”€ models/                   # MongoDB schemas
β”‚   β”‚   β”œβ”€β”€ User.js
β”‚   β”‚   β”œβ”€β”€ Module.js
β”‚   β”‚   β”œβ”€β”€ Quiz.js
β”‚   β”‚   └── Progress.js
β”‚   β”œβ”€β”€ routes/                   # API endpoints
β”‚   β”‚   β”œβ”€β”€ authRoutes.js
β”‚   β”‚   β”œβ”€β”€ moduleRoutes.js
β”‚   β”‚   β”œβ”€β”€ userRoutes.js
β”‚   β”‚   β”œβ”€β”€ progressRoutes.js
β”‚   β”‚   β”œβ”€β”€ quizRoutes.js
β”‚   β”‚   └── adminRoutes.js
β”‚   β”œβ”€β”€ .env.example              # Environment template
β”‚   β”œβ”€β”€ package.json
β”‚   └── server.js                 # Express server entry point
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ assets/               # Images, icons, etc.
β”‚   β”‚   β”œβ”€β”€ context/
β”‚   β”‚   β”‚   └── AuthContext.jsx   # Global auth state
β”‚   β”‚   β”œβ”€β”€ pages/                # Page components
β”‚   β”‚   β”‚   β”œβ”€β”€ Login.jsx
β”‚   β”‚   β”‚   └── AuthCallback.jsx
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   └── authService.js    # API client for auth
β”‚   β”‚   β”œβ”€β”€ App.jsx               # Main app + routing
β”‚   β”‚   β”œβ”€β”€ main.jsx              # React entry point
β”‚   β”‚   └── index.css
β”‚   β”œβ”€β”€ public/                   # Static assets
β”‚   β”œβ”€β”€ .env.example              # Environment template
β”‚   β”œβ”€β”€ vite.config.js
β”‚   β”œβ”€β”€ package.json
β”‚   └── index.html
β”‚
β”œβ”€β”€ .gitignore
β”œβ”€β”€ README.md                     # This file
└── CODE_REVIEW_REPORT.md         # Detailed code review

πŸš€ Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • npm (v8 or higher)
  • MongoDB Account (MongoDB Atlas recommended - free tier available)
  • GitHub OAuth App (for authentication)

Step 1: Clone the Repository

git clone <repository-url>
cd Hackstack-Portal

Step 2: Set Up GitHub OAuth

  1. Go to GitHub Settings β†’ Developer settings β†’ OAuth Apps
  2. Click "New OAuth App"
  3. Fill in the form:
    • Application name: Hackstack Portal
    • Homepage URL: http://localhost:5173
    • Authorization callback URL: http://localhost:5000/api/auth/github/callback
  4. Copy your Client ID and Client Secret

Step 3: Set Up MongoDB

  1. Go to MongoDB Atlas
  2. Create a free account and cluster
  3. Create a database user with a strong password
  4. Get your connection URI (looks like: mongodb+srv://username:password@cluster.mongodb.net/hackstack)

Step 4: Backend Setup

cd backend

# Install dependencies
npm install

# Create .env file
cp .env.example .env

# Edit .env with your credentials:
# - MONGO_URI: Your MongoDB connection string
# - JWT_SECRET: Generate a random secret (e.g., openssl rand -hex 32)
# - GITHUB_CLIENT_ID: Your GitHub OAuth Client ID
# - GITHUB_CLIENT_SECRET: Your GitHub OAuth Client Secret
# - FRONTEND_URL: http://localhost:5173 (for development)

# Start the server
npm run dev

Server runs on http://localhost:5000

Step 5: Frontend Setup

cd ../frontend

# Install dependencies
npm install

# Create .env file
cp .env.example .env

# Verify VITE_API_URL=http://localhost:5000/api

# Start the development server
npm run dev

Frontend runs on http://localhost:5173

Step 6: Test Authentication

  1. Navigate to http://localhost:5173/login
  2. Click "Continue with GitHub"
  3. You should be redirected to login and then to the dashboard
  4. βœ… If you see the dashboard, authentication is working!

πŸ’» Development

Backend Commands

cd backend

# Start development server (with hot reload via nodemon)
npm run dev

# Run linting (if configured)
npm run lint

# Note: Test suite not yet implemented

Frontend Commands

cd frontend

# Start development server
npm run dev

# Build for production
npm run build

# Preview production build locally
npm run preview

# Run linting
npm run lint

Key Environment Variables

Backend (.env):

MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/hackstack
JWT_SECRET=your_random_secret_here
GITHUB_CLIENT_ID=your_client_id
GITHUB_CLIENT_SECRET=your_client_secret
FRONTEND_URL=http://localhost:5173
PORT=5000

Frontend (.env):

VITE_API_URL=http://localhost:5000/api

πŸ“š API Documentation

Authentication Endpoints

Method Endpoint Description Auth Required
GET /api/auth/github Redirect to GitHub OAuth ❌
GET /api/auth/github/callback OAuth callback handler ❌
GET /api/auth/me Get current user βœ…

Module Endpoints

Method Endpoint Description Auth Required
GET /api/modules List all modules ❌
GET /api/modules/:slug Get module by slug ❌
POST /api/modules/:id/register Register for module βœ…
POST /api/modules Create module βœ… Admin
PUT /api/modules/:id Update module βœ… Admin
DELETE /api/modules/:id Delete module βœ… Admin

Quiz Endpoints

Method Endpoint Description Auth Required
GET /api/quizzes List all quizzes ❌
GET /api/quizzes/:id Get quiz by ID ❌
POST /api/quizzes/:id/submit Submit quiz answers βœ…
POST /api/quizzes Create quiz βœ… Admin
PATCH /api/quizzes/:id Update quiz βœ… Admin
DELETE /api/quizzes/:id Delete quiz βœ… Admin

Progress Endpoints

Method Endpoint Description Auth Required
GET /api/progress List progress records ❌
GET /api/progress/:id Get progress record ❌
PATCH /api/progress/:id Update progress βœ…

User Endpoints

Method Endpoint Description Auth Required
GET /api/users List all users ❌
GET /api/users/:id Get user by ID ❌
POST /api/users Create user ❌
PATCH /api/users/:id Update user ❌
DELETE /api/users/:id Delete user ❌

Admin Endpoints

All admin endpoints require auth + admin middleware:

  • GET /api/admin/modules - List modules
  • POST /api/admin/modules - Create module
  • PUT /api/admin/modules/:id - Update module
  • DELETE /api/admin/modules/:id - Delete module
  • Similar endpoints for /admin/quizzes, /admin/progress, /admin/users

Before Submitting a Pull Request

  1. Create a feature branch:

    git checkout -b feature/your-feature-name
  2. Make your changes and test thoroughly

  3. Lint your code:

    # Frontend
    cd frontend && npm run lint
    
    # Backend (if linting is configured)
    cd backend && npm run lint
  4. Commit with clear messages:

    git add .
    git commit -m "feat: describe your changes"
  5. Push your branch:

    git push origin feature/your-feature-name
  6. Create a Pull Request on GitHub with a clear description

Code Style Guidelines

  • JavaScript: Use ES6+ syntax
  • React: Use functional components with hooks
  • Naming: Use camelCase for variables/functions, PascalCase for components
  • Imports: Organize imports (React, third-party, local)
  • Comments: Add comments for complex logic

πŸ› Troubleshooting

"Cannot find module" errors

# Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm install

Port already in use

# Backend (Port 5000)
lsof -i :5000
kill -9 <PID>

# Frontend (Port 5173)
lsof -i :5173
kill -9 <PID>

MongoDB connection failed

  • Verify connection URI in .env
  • Check MongoDB Atlas IP whitelist (add your IP or 0.0.0.0)
  • Ensure database user has correct credentials
  • Test connection: mongo "your-connection-string"

GitHub OAuth not working

  • Verify Client ID and Client Secret in .env
  • Check OAuth redirect URL matches http://localhost:5000/api/auth/github/callback
  • Ensure FRONTEND_URL is correctly set

CORS errors

  • Verify FRONTEND_URL in backend .env matches your frontend URL
  • Check that CORS middleware in server.js allows your frontend domain

Vite not loading styles

# Rebuild Vite cache
rm -rf frontend/node_modules/.vite
npm run dev

🎯 Roadmap

  • Complete Dashboard component
  • Module detail pages with content rendering
  • Quiz taking interface
  • Progress tracking dashboard
  • Leaderboard implementation
  • Admin panel UI
  • User profile pages
  • Notification system
  • Test suite (Jest + Supertest for backend, Vitest for frontend)
  • API documentation (Swagger/OpenAPI)
  • Production deployment guide

About

Portal to maintain and conduct HackStack

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors