Skip to content

rohit-ganesan/edverse-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EdVerse Backend

Pure Supabase backend services for the EdVerse learning management system.

🏗️ Architecture

This backend provides:

  • Authentication: Supabase Auth for user management
  • Database: PostgreSQL via Supabase for data storage
  • Functions: Supabase Edge Functions for serverless API endpoints
  • Storage: Supabase Storage for file uploads
  • Security: Row Level Security (RLS) policies

📁 Project Structure

edverse-project/
├── edverse-frontend/         # React Frontend Application
│   ├── src/                 # React components, pages, hooks
│   ├── public/              # Static assets
│   ├── package.json         # Frontend dependencies
│   └── supabase/            # Local development config only
│       ├── config.toml      # Supabase local settings
│       └── .gitignore       # Supabase gitignore
└── edverse-backend/         # Pure Supabase Backend
    ├── supabase/
    │   └── functions/       # Supabase Edge Functions (15 total)
    │       ├── create-course/
    │       ├── create-notification/
    │       ├── create-user-profile/
    │       ├── delete-user/
    │       ├── enroll-student-in-course/
    │       ├── get-dashboard-stats/
    │       ├── get-instructors/
    │       ├── get-notifications/
    │       ├── get-students/
    │       ├── get-user-by-id/
    │       ├── get-user-courses/
    │       ├── get-users/
    │       ├── health-check/
    │       ├── test-connection/
    │       ├── update-user-profile/
    │       └── _shared/      # Shared utilities
    ├── supabase-rls-policies-enhanced.sql  # Database security policies
    ├── package.json         # Backend tooling configuration
    └── README.md            # This file

Important: Edge Functions only exist in the backend directory. The frontend communicates with these functions via HTTP calls to the deployed Supabase Edge Functions.

🚀 Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • Supabase CLI (npm install -g supabase)
  • Supabase project setup

Installation

  1. Navigate to the backend directory:

    cd edverse-backend
  2. Install dependencies:

    npm install
  3. Set up environment variables:

    cp .env.example .env
    # Edit .env with your Supabase project details
  4. Start the Edge Functions locally:

    supabase functions serve

🔧 Available Scripts

Development

# Start Edge Functions locally
supabase functions serve

# Start without JWT verification (for testing)
supabase functions serve --no-verify-jwt

# Deploy all functions
supabase functions deploy

# Deploy a specific function
supabase functions deploy <function-name>

# Test a function
curl -X POST "http://localhost:54321/functions/v1/<function-name>" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{"key": "value"}'

Deployment

# Deploy all Edge Functions to production
npm run deploy

# Deploy specific function
supabase functions deploy create-course

# Check function logs
supabase functions logs

# View function status
supabase functions list

🛠️ Supabase Services

Authentication

  • Email/password authentication
  • OAuth integration (Google, GitHub, etc.)
  • Row Level Security for role-based access
  • JWT-based authentication tokens

PostgreSQL Database

  • User profiles and preferences
  • Course and curriculum data
  • Student and instructor records
  • Attendance and grade tracking
  • Real-time notifications

Edge Functions

  • User profile creation and management
  • Data validation and processing
  • API endpoints for complex operations
  • Real-time event handling
  • Background job processing

Storage

  • Profile pictures and avatars
  • Course materials and documents
  • Assignment submissions
  • Media files for courses

📋 Security Policies

Row Level Security (RLS)

Located in supabase-rls-policies-enhanced.sql, these policies control:

  • User data access permissions
  • Role-based data visibility
  • Data validation on writes
  • Real-time subscription security

Storage Policies

Control file upload and access:

  • User-specific file access
  • File type validation
  • Size limits
  • Public vs private files

🧪 Testing

Local Testing

# Start Edge Functions locally
supabase functions serve

# Test health check
curl http://localhost:54321/functions/v1/health-check

# Test with authentication
curl -X POST "http://localhost:54321/functions/v1/create-course" \
  -H "Authorization: Bearer <your-jwt-token>" \
  -H "Content-Type: application/json" \
  -d '{"title": "Test Course", "description": "Test"}'

Integration Testing

# Run test suite
npm test

# Test specific function
supabase functions deploy test-connection --project-ref <project-id>

📊 Monitoring

Supabase Dashboard

  • Function logs and metrics
  • Database usage and performance
  • Authentication statistics
  • Storage usage
  • Real-time activity

Error Reporting

  • Automatic error collection
  • Performance monitoring
  • Custom metrics tracking
  • Edge Function analytics

🔐 Environment Variables

Create a .env file in the project root:

# Supabase Configuration
SUPABASE_URL=your_supabase_project_url
SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key

# Optional: Additional service integrations
SENDGRID_API_KEY=your_sendgrid_key
STRIPE_SECRET_KEY=your_stripe_key

📚 API Documentation

Edge Functions Endpoints

User Management

  • POST /functions/v1/create-user-profile - Create user profile
  • GET /functions/v1/get-user-by-id - Get user profile
  • POST /functions/v1/update-user-profile - Update user profile
  • GET /functions/v1/get-users - List all users
  • POST /functions/v1/delete-user - Delete user

Course Management

  • GET /functions/v1/get-user-courses - List user courses
  • POST /functions/v1/create-course - Create course

Student Management

  • GET /functions/v1/get-students - List students
  • POST /functions/v1/enroll-student-in-course - Enroll student

Instructor Management

  • GET /functions/v1/get-instructors - List instructors

Dashboard & Analytics

  • GET /functions/v1/get-dashboard-stats - Get dashboard statistics

Notifications

  • GET /functions/v1/get-notifications - Get notifications
  • POST /functions/v1/create-notification - Create notification

System

  • GET /functions/v1/health-check - Health check
  • GET /functions/v1/test-connection - Test connection

🚀 Deployment

Production Deployment

# Deploy all functions to production
supabase functions deploy --project-ref <your-project-ref>

# Deploy specific function
supabase functions deploy create-course --project-ref <your-project-ref>

# Using npm script
npm run deploy

Staging Deployment

# Deploy to staging environment
supabase functions deploy --project-ref <your-staging-project-ref>

# Set up different environments
supabase link --project-ref <staging-project-ref>
supabase functions deploy

🤝 Contributing

  1. Follow TypeScript best practices
  2. Write comprehensive tests
  3. Update RLS policies as needed
  4. Document new functions and APIs
  5. Test locally before deployment
  6. Ensure proper error handling
  7. Follow RESTful API conventions

EdVerse Backend - Powering education with Supabase ⚡

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published