NgoIt is an advanced learning platform that uses AI to help students create flashcards, quizzes, smart notes, and summarize content for better study experiences.
- AI-Generated Flashcards: Convert notes into study cards automatically
- Interactive Quizzes: Create and take quizzes to test knowledge
- Smart Notes: AI-enhanced note-taking experience
- Text Summarization: Extract key points from long texts
- Spaced Repetition: Optimized learning schedule for better retention
- Progressive Web App: Works offline and can be installed on devices
- Responsive Design: Works on all device sizes
- Profile Pictures: Upload and manage user avatars
- Frontend: React, Next.js, TypeScript, TailwindCSS, Shadcn/UI
- Backend: Next.js API Routes
- Database: Supabase (PostgreSQL)
- Authentication: Supabase Auth
- Storage: Supabase Storage
- AI Services: Hugging Face Inference API
- Payments: Stripe
- Node.js 18+
- npm or yarn
- Supabase account
- Stripe account (for payment processing)
- Hugging Face API token (for AI features)
- Clone the repository
- Create a
.envfile in the root directory based on.env.example - Fill in all the required environment variables:
# Supabase Configuration
NEXT_PUBLIC_SUPABASE_URL=https://your-supabase-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-supabase-anon-key
SUPABASE_SERVICE_KEY=your-supabase-service-key
# App URL Configuration
NEXT_PUBLIC_URL=http://localhost:3000
# Stripe Configuration
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key
STRIPE_WEBHOOK_SECRET=whsec_your_stripe_webhook_secret
# Hugging Face API Configuration
HF_API_TOKEN=your-huggingface-api-token# Install dependencies
npm install
# Run the development server
npm run devOpen http://localhost:3000 with your browser to see the result.
- Set up the required tables in Supabase by importing the schema or running migrations.
- Configure the Row Level Security (RLS) policies to secure your data.
The app requires two Supabase Storage buckets for handling images:
profile-pictures: For user profile imagesmaterial-images: For quiz and test material images
You can set up these buckets using one of these methods:
Option 1: Manually through the Supabase dashboard:
- Go to your Supabase project dashboard
- Navigate to Storage in the left sidebar
- Click "Create a new bucket" and create the two buckets with the exact names:
profile-picturesmaterial-images
- Set both buckets to private access
Option 2: Using our setup script:
# Run the setup script (requires your Supabase credentials in .env)
node setup_supabase.jsOption 3: Using SQL in the Supabase SQL Editor:
-- Create the required buckets
INSERT INTO storage.buckets (id, name, public)
VALUES ('profile-pictures', 'profile-pictures', false)
ON CONFLICT (id) DO NOTHING;
INSERT INTO storage.buckets (id, name, public)
VALUES ('material-images', 'material-images', false)
ON CONFLICT (id) DO NOTHING;Apply the following RLS policies to secure your storage buckets:
-- Profile pictures bucket policies
CREATE POLICY "Users can upload their own profile pictures"
ON storage.objects
FOR INSERT
TO authenticated
WITH CHECK (bucket_id = 'profile-pictures' AND (storage.foldername(name))[1] = auth.uid()::text);
CREATE POLICY "Users can view their own profile pictures"
ON storage.objects
FOR SELECT
TO authenticated
USING (bucket_id = 'profile-pictures' AND (storage.foldername(name))[1] = auth.uid()::text);
CREATE POLICY "Users can update their own profile pictures"
ON storage.objects
FOR UPDATE
TO authenticated
USING (bucket_id = 'profile-pictures' AND (storage.foldername(name))[1] = auth.uid()::text);
CREATE POLICY "Users can delete their own profile pictures"
ON storage.objects
FOR DELETE
TO authenticated
USING (bucket_id = 'profile-pictures' AND (storage.foldername(name))[1] = auth.uid()::text);
-- Material images bucket policies
CREATE POLICY "Users can upload their own material images"
ON storage.objects
FOR INSERT
TO authenticated
WITH CHECK (bucket_id = 'material-images' AND (storage.foldername(name))[1] = auth.uid()::text);
CREATE POLICY "Users can view their own material images"
ON storage.objects
FOR SELECT
TO authenticated
USING (bucket_id = 'material-images' AND (storage.foldername(name))[1] = auth.uid()::text);
CREATE POLICY "Users can update their own material images"
ON storage.objects
FOR UPDATE
TO authenticated
USING (bucket_id = 'material-images' AND (storage.foldername(name))[1] = auth.uid()::text);
CREATE POLICY "Users can delete their own material images"
ON storage.objects
FOR DELETE
TO authenticated
USING (bucket_id = 'material-images' AND (storage.foldername(name))[1] = auth.uid()::text);The app requires these SQL functions for user profile management:
-- Function to update user profile
CREATE OR REPLACE FUNCTION public.update_profile(
name text,
avatar_url text
) RETURNS json
LANGUAGE plpgsql SECURITY DEFINER
AS $$
DECLARE
user_id uuid;
result json;
BEGIN
-- Get the user ID from the request
user_id := auth.uid();
-- Check if the user exists
IF user_id IS NULL THEN
RETURN json_build_object('success', false, 'error', 'Not authenticated');
END IF;
-- Update the user profile
UPDATE public.profiles
SET
name = COALESCE(update_profile.name, name),
avatar_url = COALESCE(update_profile.avatar_url, avatar_url),
updated_at = now()
WHERE id = user_id;
-- Return the updated profile
SELECT json_build_object(
'success', true,
'profile', json_build_object(
'id', p.id,
'name', p.name,
'avatar_url', p.avatar_url,
'updated_at', p.updated_at
)
) INTO result
FROM public.profiles p
WHERE p.id = user_id;
RETURN result;
END;
$$;
-- Function to update user metadata
CREATE OR REPLACE FUNCTION public.update_profile_metadata(
metadata jsonb
) RETURNS json
LANGUAGE plpgsql SECURITY DEFINER
AS $$
DECLARE
user_id uuid;
current_metadata jsonb;
result json;
BEGIN
-- Get the user ID from the request
user_id := auth.uid();
-- Check if the user exists
IF user_id IS NULL THEN
RETURN json_build_object('success', false, 'error', 'Not authenticated');
END IF;
-- Get current metadata
SELECT raw_user_meta_data INTO current_metadata
FROM auth.users
WHERE id = user_id;
-- Update the user metadata
UPDATE auth.users
SET raw_user_meta_data =
CASE
WHEN current_metadata IS NULL THEN update_profile_metadata.metadata
ELSE current_metadata || update_profile_metadata.metadata
END
WHERE id = user_id;
-- Return success
RETURN json_build_object('success', true);
END;
$$;# Create a production build
npm run build
# Start the production server
npm startThis app is optimized for deployment on platforms like:
- Vercel: Set up all environment variables in the Vercel dashboard
- Netlify: Configure environment variables and build settings
- AWS Amplify: Connect repository and configure build settings
- Set up Stripe webhook endpoints for handling subscription events
- Configure proper CORS settings to secure API endpoints
- Ensure database connection pooling is properly configured for production
- Enable proper caching strategies for best performance
- Ensure Supabase Storage buckets are properly configured with RLS policies
- Content Security Policy (CSP) headers
- Cross-Origin Resource Sharing (CORS) protection
- Secure HTTP headers
- Supabase Row Level Security (RLS) policies
- API route authentication protection
- Error boundaries for crash prevention
- Sanitized user inputs
- Secure environment variable handling
- Storage bucket access controls
This app supports Progressive Web App features:
- Offline functionality
- Add to home screen
- Push notifications (if enabled)
- Background sync for offline data
"Bucket not found" error when uploading images:
- Ensure you have created the required storage buckets in Supabase
- Run the setup script:
node setup_supabase.js - Check that your Supabase environment variables are correct
- Verify that the bucket names match exactly:
profile-picturesandmaterial-images - Check if you have sufficient permissions to access the buckets
Profile image doesn't upload properly:
- If you're using data URL fallback mode (indicated by a yellow icon on the image), create the proper Supabase storage buckets
- For large images, try using a smaller image (under 5MB)
- Check browser console for specific error messages
- Verify that your Supabase RLS policies are correctly configured
Data URL fallback mode:
- The app automatically falls back to storing small profile images as data URLs in user metadata when:
- The required storage buckets don't exist
- The user doesn't have permission to access the buckets
- There's an error uploading to Supabase storage
- This fallback has a 200KB size limit for images
- You'll see a yellow indicator on images stored this way
- For production use, properly configure Supabase storage buckets
Testing Supabase Storage: You can run our test script to verify your storage configuration:
node test-storage.js