Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 35 additions & 23 deletions client/.next/trace

Large diffs are not rendered by default.

133 changes: 133 additions & 0 deletions client/DEPLOYMENT_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Deployment Guide & Issues Fixed

## 🎉 Issues Fixed

### 1. **Deployment Build Issue**
- ✅ **Fixed**: Missing dependencies installed (`npm install`)
- ✅ **Fixed**: Lightning icon replaced with Zap (Lightning doesn't exist in lucide-react)
- ✅ **Fixed**: Convex environment variable checks added to prevent build failures
- ✅ **Fixed**: Import path corrections for components
- ✅ **Fixed**: PDF-parse library made conditional to avoid missing test file errors

### 2. **Knowledge Nest File Upload Issue**
- ✅ **Fixed**: File upload now uses proper Convex `generateUploadUrl` function
- ✅ **Fixed**: Upload API route updated to work with Convex backend
- ✅ **Fixed**: File metadata properly stored in database
- ✅ **Fixed**: Download functionality implemented with proper access control

### 3. **Semester-Only Resource Sharing**
- ✅ **Fixed**: Resources now filtered by **Organization + Branch + Semester** combination
- ✅ **Fixed**: Removed `class_sec` field completely from entire codebase
- ✅ **Fixed**: Updated database schema to use semester-based filtering
- ✅ **Fixed**: Organization verification form now includes semester selection
- ✅ **Fixed**: UI updated to show semester instead of class information

## 🚀 Deployment Instructions

### Prerequisites
1. **Node.js** (v18 or higher)
2. **Convex Account** (https://convex.dev)
3. **Email Provider** (Gmail with App Password for OTP)
4. **Google AI API Key** (for AI features)

### Step 1: Environment Configuration
Create a `.env.local` file in the client directory:

```bash
# Convex Configuration - REQUIRED
NEXT_PUBLIC_CONVEX_URL=https://your-deployment.convex.cloud

# Email Configuration (Optional - for OTP functionality)
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-password

# Google AI Configuration (Optional - for AI features)
GOOGLE_AI_API_KEY=your-google-ai-key
```

### Step 2: Install Dependencies
```bash
cd client
npm install
```

### Step 3: Build the Project
```bash
npm run build
```

### Step 4: Deploy
Choose your deployment platform:

#### Vercel (Recommended)
```bash
npm install -g vercel
vercel --prod
```

#### Netlify
```bash
npm run build
# Upload the .next folder to Netlify
```

#### Traditional Hosting
```bash
npm run build
npm start
```

## 📋 Knowledge Nest Features

### Access Control
- **Organization-based**: Only users from the same organization can see shared files
- **Branch-based**: Users only see files from their specific branch (e.g., Computer Science)
- **Semester-based**: Files are filtered by semester (1st-8th semester)

### File Sharing
- Upload files with subject categorization
- Download files with proper access control
- Preview files before downloading
- Search and filter functionality

### Organization Verification
- Email OTP verification for @reva.edu.in domain
- Semester selection (1st-8th semester)
- Branch specification
- Organization name verification

## 🔧 Technical Improvements Made

### Database Schema Updates
- Removed `class_sec` field from `org` and `knowledge_nest` tables
- Added compound indexes for optimal querying
- Updated all Convex functions to use semester-based filtering

### Frontend Updates
- Simplified organization verification form
- Updated UI to show semester instead of class
- Improved file upload modal with auto-filled organization details
- Enhanced file display with semester-based filtering

### Backend Improvements
- Fixed Convex client initialization in API routes
- Added proper error handling for missing environment variables
- Implemented secure file access control
- Added comprehensive file validation

## 🚨 Important Notes

1. **Convex Deployment**: Make sure to deploy your Convex schema before deploying the frontend
2. **Environment Variables**: All API routes will show friendly error messages if environment variables are missing
3. **File Access**: Files are only accessible to users in the same organization, branch, and semester
4. **Build Success**: The project now builds successfully with no errors

## 🎯 Next Steps for Production

1. Set up your Convex deployment and get the deployment URL
2. Configure email settings for OTP functionality
3. Add Google AI API key for AI features
4. Deploy to your preferred hosting platform
5. Test file upload and download functionality

The deployment is now ready and all major issues have been resolved! 🚀
173 changes: 173 additions & 0 deletions client/PULL_REQUEST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# Pull Request: Fix Deployment Issues & Implement Semester-Based Resource Sharing

## 🎯 Overview
This PR fixes critical deployment issues and implements semester-based resource sharing for the Knowledge Nest feature as requested.

## 🐛 Issues Fixed

### 1. **Deployment Build Failures**
- **Issue**: Build failing due to missing dependencies and import errors
- **Fix**:
- Installed missing npm dependencies
- Fixed component import paths (`VoiceAnimationDemo`)
- Replaced non-existent `Lightning` icon with `Zap` from lucide-react
- Added conditional environment variable checks for Convex client initialization
- Made pdf-parse library import conditional to prevent missing test file errors

### 2. **Knowledge Nest File Upload Not Working**
- **Issue**: File upload functionality was incomplete and non-functional
- **Fix**:
- Implemented proper Convex `generateUploadUrl` integration
- Fixed file metadata storage in database
- Added proper error handling and validation
- Implemented secure download functionality with access control

### 3. **Incorrect Resource Sharing Scope**
- **Issue**: Resources were being filtered by organization + class + semester
- **Requirement**: Share resources only within same organization + branch + semester
- **Fix**: Completely removed `class_sec` field and implemented semester-only filtering

## 🚀 New Features

### Semester-Based Resource Sharing
- **Organization Verification**: Added semester selection (1st-8th semester) to verification form
- **Access Control**: Files now filtered by organization + branch + semester combination
- **UI Updates**: Dashboard shows semester instead of class information
- **Database Schema**: Updated to support semester-based filtering with optimized indexes

## 📝 Changes Made

### Backend Changes
- **Schema Updates**:
- Removed `class_sec` field from `org` and `knowledge_nest` tables
- Added compound indexes for optimal semester-based querying
- Added semester field to organization and file metadata

- **Convex Functions**:
- Updated `createOrUpdateOrg` to handle semester parameter
- Modified `getKnowledgeNestFiles` to filter by org + branch + semester
- Fixed all file access control functions
- Added proper error handling for missing environment variables

### Frontend Changes
- **Organization Verification Form**:
- Removed class/section input field
- Added semester dropdown with options (1st-8th semester)
- Updated validation to require semester selection

- **Knowledge Nest Dashboard**:
- Updated organization stats to show semester instead of class
- Modified file display to show semester information
- Updated file upload modal organization details

- **Components Updated**:
- `app/home/knowledge-nest/page.jsx`
- `components/FileUploadModal.jsx`
- `components/FileDisplayComponent.jsx`
- `components/KnowledgeNestFileSelector.jsx`

### Build & Deployment Fixes
- **Environment Setup**: Created `.env.local.example` with required variables
- **API Routes**: Added Convex client initialization checks
- **Import Fixes**: Corrected component import paths
- **Icon Fixes**: Replaced `Lightning` with `Zap` throughout codebase

## 🔧 Technical Improvements

### Database Optimization
```javascript
// Added optimized compound index
.index("by_org_branch_semester", ["organization_id", "branch", "semester"])
```

### Access Control Enhancement
- Files now only accessible to users with exact same:
- Organization ID
- Branch
- Semester

### Build Process
- ✅ Build now completes successfully with no errors
- ✅ All import errors resolved
- ✅ Environment variable issues fixed
- ✅ Icon compatibility issues resolved

## 🧪 Testing

### Build Testing
```bash
npm install
npm run build
# ✅ Build completes successfully
```

### Feature Testing
- ✅ Organization verification with semester selection
- ✅ File upload with proper metadata storage
- ✅ File download with access control
- ✅ Semester-based resource filtering

## 📋 Files Changed

### Core Files Modified
- `convex/schema.js` - Updated database schema
- `convex/org.js` - Added semester support
- `convex/knowledgeNest.js` - Implemented semester filtering
- `app/home/knowledge-nest/page.jsx` - Updated UI and form
- `components/FileUploadModal.jsx` - Removed class references
- `components/FileDisplayComponent.jsx` - Updated display logic
- `app/test/ultra-responsive/page.jsx` - Fixed Lightning icon usage

### API Routes Fixed
- `app/api/auth/get-user/route.js`
- `app/api/auth/verify-otp/route.js`
- `app/api/auth/send-otp/route.js`
- `app/api/org/send-otp/route.js`
- `app/api/download/route.js`
- `app/api/chat/route.js`

### New Files Added
- `.env.local.example` - Environment configuration template
- `DEPLOYMENT_GUIDE.md` - Comprehensive deployment instructions

## 🎯 Business Impact

### User Experience Improvements
- **Proper Resource Sharing**: Users now see files only from their semester cohort
- **Simplified Verification**: Removed unnecessary class field, focus on semester
- **Functional File Upload**: Knowledge Nest now works as intended
- **Successful Deployment**: Application can now be deployed without errors

### Security Enhancements
- **Stricter Access Control**: Files filtered by org + branch + semester
- **Environment Safety**: Graceful handling of missing configuration
- **Proper Validation**: Semester-based access validation

## 🚀 Deployment Ready

The application is now **deployment-ready** with:
- ✅ Successful build process
- ✅ Proper environment variable handling
- ✅ Functional file upload/download
- ✅ Semester-based resource sharing
- ✅ Comprehensive deployment documentation

## 🔄 Migration Notes

For existing deployments:
1. Update Convex schema to remove `class_sec` field
2. Set up environment variables as per `.env.local.example`
3. Users will need to re-verify with semester information

## 📚 Documentation

- Added comprehensive `DEPLOYMENT_GUIDE.md`
- Environment variable examples provided
- Step-by-step deployment instructions included

---

**Type**: 🐛 Bug Fix + ✨ Feature
**Priority**: 🔥 Critical (Deployment blocking)
**Breaking Changes**: ⚠️ Yes (Database schema changes)
**Ready for Review**: ✅ Yes
13 changes: 12 additions & 1 deletion client/app/api/auth/get-user/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@ import { NextResponse } from 'next/server';
import { ConvexHttpClient } from "convex/browser";
import { api } from "@/convex/_generated/api";

const convex = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL);
// Initialize Convex client only if URL is available
let convex = null;
if (process.env.NEXT_PUBLIC_CONVEX_URL) {
convex = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL);
}

export async function POST(request) {
try {
if (!convex) {
return NextResponse.json(
{ success: false, message: 'Convex not configured. Please set NEXT_PUBLIC_CONVEX_URL environment variable.' },
{ status: 500 }
);
}

const { email } = await request.json();

if (!email) {
Expand Down
22 changes: 17 additions & 5 deletions client/app/api/auth/send-otp/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import nodemailer from 'nodemailer';
import { ConvexHttpClient } from "convex/browser";
import { api } from "@/convex/_generated/api";

const convex = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL);
// Initialize Convex client only if URL is available
let convex = null;
if (process.env.NEXT_PUBLIC_CONVEX_URL) {
convex = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL);
}

export async function POST(request) {
try {
Expand Down Expand Up @@ -50,10 +54,18 @@ export async function POST(request) {
await transporter.sendMail(mailOptions);

// Store OTP in database
await convex.mutation(api.auth.storeOTP, {
email: email,
otp: otp,
});
if (convex) {
await convex.mutation(api.auth.storeOTP, {
email: email,
otp: otp,
});
} else {
console.error('Convex client not initialized. Cannot store OTP.');
return NextResponse.json(
{ success: false, message: 'Failed to store OTP due to missing Convex client' },
{ status: 500 }
);
}

return NextResponse.json({
success: true,
Expand Down
Loading