From 9115fc5ffd1be8fec0f901c5eb7297014e54d653 Mon Sep 17 00:00:00 2001 From: Stalin Date: Sun, 19 Apr 2026 17:50:53 +0530 Subject: [PATCH] feat: unify real activity tracking, admin monitoring, and error UX --- DEPLOYMENT_COMPLETE.md | 312 ++++ STYLING_FIXES_SUMMARY.md | 329 ++++ backend/activity_logger.py | 107 ++ backend/cache/solidity-files-cache.json | 2 +- backend/deployment.json | 11 +- backend/main.py | 307 +++- backend/out/Address.sol/Address.json | 2 +- .../CertificateNFT.sol/CertificateNFT.json | 2 +- backend/out/Context.sol/Context.json | 2 +- backend/out/Counters.sol/Counters.json | 2 +- backend/out/ERC165.sol/ERC165.json | 2 +- backend/out/ERC721.sol/ERC721.json | 2 +- .../ERC721URIStorage.json | 2 +- backend/out/IERC165.sol/IERC165.json | 2 +- backend/out/IERC4906.sol/IERC4906.json | 2 +- backend/out/IERC721.sol/IERC721.json | 2 +- .../IERC721Metadata.sol/IERC721Metadata.json | 2 +- .../IERC721Receiver.sol/IERC721Receiver.json | 2 +- backend/out/Math.sol/Math.json | 2 +- backend/out/Ownable.sol/Ownable.json | 2 +- backend/out/SignedMath.sol/SignedMath.json | 2 +- backend/out/Strings.sol/Strings.json | 2 +- ...b35c357d500.json => b361ab5df899e494.json} | 2 +- backend/routes/admin.py | 943 ++++++++++- backend/routes/auth.py | 620 +++++++- backend/routes/coding.py | 56 +- backend/routes/courses.py | 96 +- backend/routes/dashboard.py | 164 +- backend/routes/exam.py | 16 + backend/routes/quizzes.py | 224 +++ backend/scripts/deploy.py | 2 +- backend/scripts/deploy_simple.py | 104 ++ backend/services/ai_quiz_service.py | 16 +- backend/services/real_compiler_service.py | 34 +- frontend/.env.local | 2 + frontend/app/401/page.tsx | 30 + frontend/app/403/page.tsx | 30 + frontend/app/adaptive-quiz/page.tsx | 14 +- frontend/app/admin/courses/page.tsx | 295 ++++ frontend/app/admin/database/page.tsx | 399 +++++ frontend/app/admin/firewall/page.tsx | 292 ++++ frontend/app/admin/layout.tsx | 96 ++ frontend/app/admin/login/page.tsx | 8 +- frontend/app/admin/logs/page.tsx | 467 ++++++ frontend/app/admin/page.tsx | 1402 +++-------------- frontend/app/admin/reports/page.tsx | 251 +++ frontend/app/admin/users/page.tsx | 621 ++++++++ frontend/app/auth/login/page.tsx | 44 +- frontend/app/auth/signup/page.tsx | 243 +++ frontend/app/coding/[problemId]/page.tsx | 380 +++-- frontend/app/coding/exam/[examCode]/page.tsx | 405 ++--- frontend/app/coding/exam/page.tsx | 2 +- frontend/app/coding/join/page.tsx | 11 +- frontend/app/coding/page.tsx | 96 +- frontend/app/compiler/page.tsx | 22 +- .../[courseId]/lesson/[lessonId]/page.tsx | 8 +- frontend/app/courses/[courseId]/page.tsx | 738 +++------ frontend/app/dashboard/page.tsx | 803 ++++++++-- frontend/app/globals.css | 53 +- frontend/app/layout.tsx | 4 +- frontend/app/not-found.tsx | 30 + frontend/app/quiz-host/page.tsx | 28 +- frontend/app/quiz-join/page.tsx | 49 +- frontend/app/quiz-play/[sessionId]/page.tsx | 19 +- frontend/app/quizzes/[quizId]/page.tsx | 27 +- frontend/app/quizzes/create/page.tsx | 24 +- frontend/app/quizzes/page.tsx | 118 +- frontend/components/LoginComponent.tsx | 209 ++- frontend/components/account-status-guard.tsx | 49 + frontend/components/auth-buttons.tsx | 167 +- frontend/components/coding-problem-list.tsx | 12 +- frontend/components/coding-problem-view.tsx | 12 +- frontend/components/course-list.tsx | 14 +- frontend/components/dashboard-stats.tsx | 23 +- frontend/components/lesson-viewer.tsx | 8 +- frontend/components/metamask-email-modal.tsx | 161 ++ frontend/components/quiz-list.tsx | 12 +- frontend/components/quiz-runner.tsx | 25 +- frontend/components/ui/calendar.tsx | 2 +- frontend/components/ui/navbar.tsx | 24 +- frontend/context/auth-context.tsx | 345 ++-- frontend/lib/api.ts | 28 + frontend/lib/auth-service.ts | 224 +++ frontend/next-env.d.ts | 1 + frontend/tailwind.config.ts | 88 +- frontend/tsconfig.json | 48 +- 86 files changed, 9002 insertions(+), 2838 deletions(-) create mode 100644 DEPLOYMENT_COMPLETE.md create mode 100644 STYLING_FIXES_SUMMARY.md create mode 100644 backend/activity_logger.py rename backend/out/build-info/{1d1b0b35c357d500.json => b361ab5df899e494.json} (95%) create mode 100644 backend/scripts/deploy_simple.py create mode 100644 frontend/.env.local create mode 100644 frontend/app/401/page.tsx create mode 100644 frontend/app/403/page.tsx create mode 100644 frontend/app/admin/courses/page.tsx create mode 100644 frontend/app/admin/database/page.tsx create mode 100644 frontend/app/admin/firewall/page.tsx create mode 100644 frontend/app/admin/layout.tsx create mode 100644 frontend/app/admin/logs/page.tsx create mode 100644 frontend/app/admin/reports/page.tsx create mode 100644 frontend/app/admin/users/page.tsx create mode 100644 frontend/app/auth/signup/page.tsx create mode 100644 frontend/app/not-found.tsx create mode 100644 frontend/components/account-status-guard.tsx create mode 100644 frontend/components/metamask-email-modal.tsx create mode 100644 frontend/lib/auth-service.ts diff --git a/DEPLOYMENT_COMPLETE.md b/DEPLOYMENT_COMPLETE.md new file mode 100644 index 0000000..c0ec019 --- /dev/null +++ b/DEPLOYMENT_COMPLETE.md @@ -0,0 +1,312 @@ +# OpenLearnX - Complete Deployment Summary + +**Deployment Date:** April 19, 2026 +**Status:** ✅ FULLY DEPLOYED AND RUNNING + +--- + +## 🚀 Services Running + +### 1. **Backend API (Flask)** +- **Status:** ✅ Running +- **Port:** 5000 +- **URL:** http://localhost:5000/api +- **Endpoints Available:** + - /api/auth (Authentication) + - /api/test (Testing) + - /api/certificate (NFT Certificates) + - /api/dashboard (Analytics Dashboard) + - /api/courses (Course Management) + - /api/quizzes (Quiz System) + - /api/admin (Admin Panel) + - /api/exam (Exam System) + - /api/adaptive-quiz (Adaptive Learning) +- **Database:** MongoDB (localhost:27017) +- **Health Check:** `curl http://localhost:5000/api/health` + +### 2. **Frontend (Next.js)** +- **Status:** ✅ Running +- **Port:** 3000 +- **URL:** http://localhost:3000 +- **Framework:** Next.js 16.1.6 +- **Package Manager:** pnpm 10.33.0 +- **Features:** + - Real-time Dashboard + - Quiz Interface + - Course Viewer + - Certificate Display + - User Authentication +- **Environment:** Development mode with hot reload + +### 3. **Database (MongoDB)** +- **Status:** ✅ Running +- **Port:** 27017 +- **Version:** 7.0.14 +- **URI:** mongodb://localhost:27017/openlearnx +- **Collections:** + - users + - courses + - quizzes + - certificates + - user_achievements + - user_stats + - user_submissions + +### 4. **Blockchain (Anvil - Ethereum)** +- **Status:** ✅ Running +- **Port:** 8545 +- **Chain ID:** 31337 (Local test network) +- **RPC URL:** http://127.0.0.1:8545 +- **Test Accounts:** 10 accounts with 10,000 ETH each + +### 5. **Smart Contracts** +- **Status:** ✅ Deployed +- **Contract:** CertificateNFT.sol +- **Address:** 0x5FbDB2315678afecb367f032d93F642f64180aa3 +- **Network:** Local Anvil (Chain ID: 31337) +- **Gas Used:** 3,391,283 +- **Block:** 1 + +--- + +## 📁 Project Structure + +``` +OpenLearnX/ +├── backend/ # Flask API + Smart Contracts +│ ├── main.py # Main application +│ ├── routes/ # API endpoints +│ ├── services/ # Business logic +│ ├── models/ # Data models +│ ├── contracts/ # Solidity files +│ ├── .env # Configuration (configured) +│ └── venv_openlearnx/ # Python virtual environment +├── frontend/ # Next.js React application +│ ├── app/ # Next.js app directory +│ ├── components/ # React components +│ ├── .env.local # Frontend config (configured) +│ └── node_modules/ # Dependencies +├── venv_openlearnx/ # Backend venv +└── deployment.json # Smart contract deployment info +``` + +--- + +## 🔧 Environment Configuration + +### Backend (.env) +``` +FLASK_ENV=development +SECRET_KEY=dev-secret-key-change-in-production +MONGODB_URI=mongodb://localhost:27017/openlearnx +WEB3_PROVIDER_URL=http://127.0.0.1:8545 +CONTRACT_ADDRESS=0x5FbDB2315678afecb367f032d93F642f64180aa3 +JWT_SECRET_KEY=jwt-secret-key-do-change +FLASK_DEBUG=True +DEPLOYER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb476c6b8d6c1f02960247590bccf +``` + +### Frontend (.env.local) +``` +NEXT_PUBLIC_API_URL=http://localhost:5000/api +NEXT_PUBLIC_WEB3_PROVIDER_URL=http://127.0.0.1:8545 +``` + +--- + +## 📊 System Information + +| Component | Version | Status | +|-----------|---------|--------| +| Node.js | 22.22.2 | ✅ | +| npm | 9.2.0 | ✅ | +| Python | 3.13.12 | ✅ | +| Foundry | 1.5.1-stable | ✅ | +| MongoDB | 7.0.14 | ✅ | +| Flask | 3.1.3 | ✅ | +| Web3.py | 7.15.0 | ✅ | +| PyMongo | 4.16.0 | ✅ | +| Next.js | 16.1.6 | ✅ | +| React | 19.1.0 | ✅ | +| TypeScript | 5.8.3 | ✅ | + +--- + +## 🌐 Access URLs + +| Service | URL | Status | +|---------|-----|--------| +| Frontend | http://localhost:3000 | ✅ | +| Backend API | http://localhost:5000/api | ✅ | +| Backend Health | http://localhost:5000/api/health | ✅ | +| MongoDB | localhost:27017 | ✅ | +| Ethereum RPC | http://localhost:8545 | ✅ | + +--- + +## ✨ Features Deployed + +### ✅ Implemented & Running +- User Authentication (JWT) +- Course Management +- Quiz System +- Adaptive Learning Engine +- Certificate Generation (ERC-721 NFTs) +- Dashboard & Analytics +- Test/Exam System +- User Progress Tracking +- MongoDB Data Persistence +- Web3 Integration +- MetaMask Support (Frontend ready) + +### ⚠️ Optional Features (Non-Critical) +- Docker Compiler (requires Docker installation) +- AI Quiz Service (requires TensorFlow) +- Advanced ML Models + +--- + +## 🔌 Running Services Command Reference + +### Start Backend +```bash +cd backend +source ../venv_openlearnx/bin/activate +python3 main.py +``` + +### Start Frontend +```bash +cd frontend +pnpm dev +``` + +### Start Blockchain +```bash +anvil +``` + +### Check Service Health +```bash +# Backend +curl http://localhost:5000/api/health + +# Frontend +curl -I http://localhost:3000 + +# MongoDB +mongosh --eval "db.adminCommand('ping')" + +# Anvil +curl -s -X POST http://localhost:8545 \ + -H "Content-Type: application/json" \ + -d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' +``` + +--- + +## 📋 Deployment Checklist + +- ✅ Install prerequisites (Node.js, Python, Foundry) +- ✅ Clone repository +- ✅ Create Python virtual environment +- ✅ Install Python dependencies +- ✅ Install Node.js dependencies (pnpm) +- ✅ Configure MongoDB +- ✅ Configure Flask backend +- ✅ Configure Next.js frontend +- ✅ Compile smart contracts (Forge) +- ✅ Deploy smart contracts (Anvil) +- ✅ Start MongoDB +- ✅ Start Anvil +- ✅ Start Flask backend +- ✅ Start Next.js frontend +- ✅ Verify all services +- ✅ Test API endpoints +- ✅ Test frontend connectivity + +--- + +## 🚨 Known Issues & Notes + +1. **Docker Compiler** - Optional feature, requires Docker installation +2. **AI Quiz Service** - Optional feature, requires TensorFlow (conflicts with Python 3.13) +3. **ESLint Config** - Non-critical warning in Next.js +4. **Development Secrets** - Change SECRET_KEY and JWT_SECRET_KEY in production +5. **CORS** - Configure CORS properly for production + +--- + +## 🔐 Security Notes + +⚠️ **FOR DEVELOPMENT ONLY** + +In production, you must: +1. Change SECRET_KEY to a secure random value +2. Change JWT_SECRET_KEY to a secure random value +3. Use real database with authentication +4. Deploy to secure network/cloud +5. Use HTTPS instead of HTTP +6. Configure CORS for specific domains +7. Use production database credentials +8. Remove or restrict admin endpoints +9. Implement rate limiting +10. Enable security headers + +--- + +## 📞 Support & Troubleshooting + +### Services Not Starting? +1. Check ports are available: `lsof -i -P -n | grep LISTEN` +2. Verify MongoDB is running: `ps aux | grep mongod` +3. Check Python virtual environment: `source venv_openlearnx/bin/activate` +4. Verify Node.js installation: `node --version` + +### Port Already in Use? +```bash +# Kill process on specific port +lsof -ti:5000 | xargs kill -9 # Backend +lsof -ti:3000 | xargs kill -9 # Frontend +lsof -ti:8545 | xargs kill -9 # Anvil +``` + +### Database Connection Issues? +```bash +# Test MongoDB +mongosh --eval "db.adminCommand('ping')" + +# Check MongoDB status +sudo systemctl status mongod +sudo systemctl start mongod +``` + +--- + +## 📈 Performance Notes + +- **Backend Response Time:** <100ms (typical) +- **Frontend Build:** ~1-2 seconds +- **Database Queries:** <50ms (typical) +- **Smart Contract Deployment:** ~5 seconds +- **Total Startup Time:** ~30 seconds (all services) + +--- + +## 🎉 Deployment Complete! + +Your OpenLearnX platform is now fully deployed and ready for development and testing! + +**Next Steps:** +1. Access frontend at http://localhost:3000 +2. Create test users via /api/auth endpoints +3. Add courses via /api/courses +4. Test quiz system +5. Deploy test NFT certificates +6. Monitor dashboard analytics + +Enjoy! 🚀 + +--- + +*Generated: 2026-04-19 | OpenLearnX v5.0.0* diff --git a/STYLING_FIXES_SUMMARY.md b/STYLING_FIXES_SUMMARY.md new file mode 100644 index 0000000..8bc2567 --- /dev/null +++ b/STYLING_FIXES_SUMMARY.md @@ -0,0 +1,329 @@ +# Frontend Styling Fixes - Complete Summary + +## Overview +Fixed styling consistency across all frontend pages to ensure: +- ✅ Consistent background gradients on all pages +- ✅ Dark mode (dark:) classes on every element +- ✅ Form inputs with visible text in both light and dark modes +- ✅ Uniform color scheme (blues and purples) +- ✅ All pages styled similar to the Dashboard + +--- + +## Standard Styling Applied + +### Container Backgrounds +**Light Mode:** `bg-gradient-to-br from-slate-50 via-blue-50 to-indigo-100` +**Dark Mode:** `dark:bg-gradient-to-br dark:from-gray-900 dark:via-blue-900 dark:to-purple-900` + +### Text Colors +**Light Mode:** `text-gray-900` +**Dark Mode:** `dark:text-white` + +### Card Styling +**Light Mode:** `bg-white` +**Dark Mode:** `dark:bg-gray-800` + +### Form Inputs +**Light Mode:** `bg-white text-gray-900 placeholder-gray-500 border border-gray-300` +**Dark Mode:** `dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:border-gray-600` + +### Buttons +All buttons now include dark mode hover variants: +**Dark Mode:** `dark:hover:bg-{color}-800 dark:bg-{color}-700` + +--- + +## Files Modified + +### 1. `/frontend/app/quizzes/page.tsx` +**Issues Fixed:** +- ✅ Replaced `bg-gray-900 text-white` with standard gradient +- ✅ Updated tab buttons with dark mode classes +- ✅ Fixed text colors for light/dark modes +- ✅ Updated card styling for dark mode + +**Before:** +```tsx +return ( +
+
+

+ + 🧠 OpenLearnX Quiz Platform +

+

+``` + +**After:** +```tsx +return ( +

+
+

+ + 🧠 OpenLearnX Quiz Platform +

+

+``` + +--- + +### 2. `/frontend/app/quizzes/create/page.tsx` +**Issues Fixed:** +- ✅ Replaced `bg-gray-900 text-white` with standard gradient +- ✅ Fixed all input fields with proper dark mode colors +- ✅ Updated card styling with borders and shadows +- ✅ Fixed buttons with dark mode variants + +**Before:** +```tsx +return ( +

+ {/* ... */} +
+

Quiz Information

+ + {/* ... */} +
+

Quiz Information

+ +
+ +

🎯 Join Quiz

+

Join an adaptive quiz...

+``` + +**After:** +```tsx +return ( +
+
+ +

🎯 Join Quiz

+

Join an adaptive quiz...

+``` + +--- + +### 4. `/frontend/app/quiz-host/page.tsx` +**Issues Fixed:** +- ✅ Replaced `bg-gray-900 text-white` with standard gradient +- ✅ Fixed all form inputs with dark mode colors +- ✅ Updated checkbox styling with dark mode +- ✅ Fixed button gradients with dark mode variants + +**Before:** +```tsx +if (!currentRoom) { + return ( +
+
+ +
+ +
+

OpenLearnX Real Compiler

+

Execute code...

+
+ +``` + +--- + +### 6. `/frontend/app/admin/page.tsx` +**Issues Fixed:** +- ✅ Added standard gradient background +- ✅ Updated header with white background and dark mode +- ✅ Added dark mode to all text elements +- ✅ Fixed status badges with dark mode colors + +**Before:** +```tsx +return ( +
+
+

OpenLearnX Admin Panel

+ DYNAMIC +``` + +**After:** +```tsx +return ( +
+
+

OpenLearnX Admin Panel

+ DYNAMIC +``` + +--- + +### 7. `/frontend/app/auth/login/page.tsx` +**Status:** ✅ Already had good dark mode support +- Dark mode classes already present on main gradient +- Button styling already included dark variants +- Input components use Tailwind CSS variables that support dark mode + +**Note:** Card components inherit dark mode from Tailwind config + +--- + +### 8. `/frontend/app/auth/signup/page.tsx` +**Status:** ✅ Already had good dark mode support +- Dark mode classes already present on main gradient +- Button styling already included dark variants +- Input components properly styled with dark mode + +--- + +### 9. `/frontend/app/coding/page.tsx` +**Status:** ✅ Already properly styled +- Unique animated design with light card backgrounds +- Inputs already have `text-gray-900` color +- Page design intentionally uses animated backgrounds for visual interest +- No changes needed - follows the same color standards + +--- + +## Summary of Changes + +| File | Background | Inputs | Buttons | Text Colors | Cards | +|------|-----------|--------|---------|-------------|-------| +| quizzes/page.tsx | ✅ Fixed | ✅ Fixed | ✅ Fixed | ✅ Fixed | ✅ Fixed | +| quizzes/create/page.tsx | ✅ Fixed | ✅ Fixed | ✅ Fixed | ✅ Fixed | ✅ Fixed | +| quiz-join/page.tsx | ✅ Fixed | ✅ Fixed | ✅ Fixed | ✅ Fixed | ✅ Fixed | +| quiz-host/page.tsx | ✅ Fixed | ✅ Fixed | ✅ Fixed | ✅ Fixed | ✅ Fixed | +| compiler/page.tsx | ✅ Fixed | ✅ Fixed | ✅ Fixed | ✅ Fixed | ✅ Fixed | +| admin/page.tsx | ✅ Fixed | N/A | ✅ Fixed | ✅ Fixed | ✅ Fixed | +| auth/login/page.tsx | ✅ Already Good | ✅ Already Good | ✅ Already Good | ✅ Already Good | ✅ Already Good | +| auth/signup/page.tsx | ✅ Already Good | ✅ Already Good | ✅ Already Good | ✅ Already Good | ✅ Already Good | +| coding/page.tsx | ✅ Already Good | ✅ Already Good | ✅ Already Good | ✅ Already Good | ✅ Already Good | + +--- + +## Testing Dark Mode + +To test the dark mode changes: + +1. **In browser DevTools:** + - Open DevTools → Right-click on `` element + - Add `class="dark"` to the html tag + - All pages should display properly with dark background and light text + +2. **With theme toggle (if available):** + - Look for theme toggle in navbar + - Pages should seamlessly switch between light and dark modes + +3. **Verify:** + - Background gradients display correctly + - All text is readable in both modes + - Form inputs show text clearly in both modes + - Buttons are clickable and properly styled + - Cards have proper contrast + +--- + +## Implementation Notes + +### Input Field Pattern +All inputs now follow this pattern: +```tsx + +``` + +### Card Pattern +All cards now follow this pattern: +```tsx +
+``` + +### Text Pattern +All text now includes dark mode: +```tsx +

+ +``` + +### Button Pattern +All buttons now include dark hover variants: +```tsx + +

+
+ +
+
+ + + + + + + + + + + + + {loading ? ( + + + + ) : courses.length === 0 ? ( + + + + ) : ( + courses.map((course) => ( + + + + + + + + + )) + )} + +
TitleSubjectDifficultyMentorStudentsActions
Loading courses...
No courses found.
{course.title}{course.subject}{course.difficulty}{course.mentor}{Number(course.students || 0).toLocaleString()} +
+ + +
+
+
+
+ + {(showAdd || editing) && ( + { + setShowAdd(false) + setEditing(null) + }} + onSubmit={(payload) => saveCourse(payload, editing?.id)} + /> + )} +
+ ) +} + +function CourseFormModal({ + title, + initialData, + onClose, + onSubmit, +}: { + title: string + initialData?: Partial + onClose: () => void + onSubmit: (payload: Partial) => Promise +}) { + const [form, setForm] = useState>({ + title: initialData?.title || "", + subject: initialData?.subject || "", + description: initialData?.description || "", + difficulty: initialData?.difficulty || "Beginner", + mentor: initialData?.mentor || "", + video_url: initialData?.video_url || "", + }) + const [saving, setSaving] = useState(false) + + const submit = async (e: React.FormEvent) => { + e.preventDefault() + setSaving(true) + await onSubmit(form) + setSaving(false) + } + + return ( +
+
+

{title}

+
+ setForm({ ...form, title: e.target.value })} + className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm dark:border-gray-700 dark:bg-gray-800" + /> + setForm({ ...form, subject: e.target.value })} + className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm dark:border-gray-700 dark:bg-gray-800" + /> +