Skip to content

CapThunder19/SkillChain-SAH

Repository files navigation

🎓 AI Tutor with NFT Achievements

Solana Next.js TypeScript Anchor

A decentralized learning platform that combines AI-powered tutoring with blockchain-based achievement NFTs on Solana. Learn Web Development, Blockchain, AI/ML, Python, and Cybersecurity while earning verifiable on-chain credentials.

AI Tutor Platform

✨ Features

🤖 AI-Powered Learning

  • Gemini AI Integration - Intelligent tutoring with Google's latest Gemini 2.5 Flash model
  • AI Code Autograder - Real-time code evaluation and feedback via an integrated Monaco Editor
  • Context-Aware Responses - AI adapts to your learning progress and current lesson
  • Interactive Chat - Real-time Q&A with detailed explanations and examples
  • Personalized Guidance - Tailored learning experience based on your subject

⛓️ Blockchain Integration

  • Solana Smart Contracts - Secure on-chain profile and progress tracking
  • NFT Achievement System - Mint unique NFTs and compressed NFTs (cNFTs) for completed lessons
  • Token Rewards - Earn $LEARN SPL tokens automatically as you progress and master skills
  • Wallet Integration - Seamless connection with Phantom, Solflare, and other Solana wallets
  • Decentralized Credentials - Permanent, verifiable proof of learning achievements

🎓 Interactive Learning Paths

  • Visual Skill Tree - Branching, interactive progression paths that map out your optimal learning journey
  • Leaderboards - Track your progress and compete against other learners globally
  • Course Catalog - 7 distinct courses with 21 interactive lessons spanning from Web Dev to Cybersecurity

🎨 Modern UI/UX

  • Dark/Light Mode - Polished global toggling between themes with smart color variables
  • Responsive Design - Works seamlessly on desktop, tablet, and mobile browsers
  • Smooth Animations - Framer Motion utilized for fluid interactions and course card popups
  • Progress Tracking - Visual indicators and stats for course completion and balance

🚀 Quick Start

Prerequisites

Before you begin, ensure you have:

Installation

  1. Clone the repository
git clone <your-repo-url>
cd tutor_project
  1. Install dependencies
# Install root dependencies
npm install

# Install frontend dependencies
cd app
npm install
cd ..
  1. Configure Environment Variables

Create app/.env.local:

NEXT_PUBLIC_SOLANA_RPC_ENDPOINT=https://api.devnet.solana.com
GEMINI_API_KEY=your-gemini-api-key-here

Get your free Gemini API key from: https://aistudio.google.com/app/apikey

  1. Build the Smart Contract
# On Windows with WSL
wsl bash -lc "cd /mnt/d/code2/sah/tutor_project && anchor build"

# On Linux/Mac
anchor build
  1. Start Solana Test Validator
# On Windows with WSL
wsl bash -ilc "cd /mnt/d/code2/sah/tutor_project && solana-test-validator --reset"

# On Linux/Mac
solana-test-validator --reset

Keep this terminal running in the background.

  1. Deploy Smart Contract
# On Windows with WSL
wsl bash -lc "cd /mnt/d/code2/sah/tutor_project && anchor deploy"

# On Linux/Mac
anchor deploy
  1. Start the Frontend
cd app
npm run dev
  1. Open the App

Navigate to: http://localhost:3000

Quick Start Script (Windows)

For convenience on Windows, use the provided batch script:

start-dev.bat

This automatically starts both the validator and frontend.

📖 How to Use

1. Connect Your Wallet

  • Click the "Connect Wallet" button in the top right
  • Select your Solana wallet (Phantom, Solflare, etc.)
  • Approve the connection

2. Create Your Profile

  • Once connected, create your tutor profile
  • Your progress will be saved on-chain

3. Browse Courses

  • Filter by category: Web Development, Blockchain, AI & ML, etc.
  • View course cards with progress indicators
  • Click "Continue" to start or resume a course

4. Learn with AI

  • Read lesson content (documents, videos, or interactive)
  • Ask questions in the AI chat interface
  • Get personalized explanations and examples

5. Complete Lessons & Earn NFTs

  • After understanding a lesson, click "Complete Lesson & Mint Achievement NFT"
  • A unique NFT is minted and sent to your wallet
  • Your level increases and next lesson unlocks

6. Track Your Progress

  • View completed lessons in the sidebar
  • Check achievement NFTs earned
  • See your current level

🏗️ Project Structure

tutor_project/
├── programs/
│   └── tutor_project/
│       └── src/
│           └── lib.rs              # Solana smart contract (Anchor)
├── tests/
│   └── tutor_project.ts            # Smart contract tests
├── app/                            # Next.js frontend
│   ├── app/
│   │   ├── page.tsx                # Main entry point
│   │   ├── layout.tsx              # Root layout with providers
│   │   ├── globals.css             # Global styles
│   │   └── api/
│   │       └── chat/
│   │           └── route.ts        # Gemini AI API route
│   ├── components/
│   │   ├── WalletProvider.tsx      # Solana wallet integration
│   │   ├── TutorPage.tsx           # Main app component
│   │   ├── LessonViewer.tsx        # Lesson display component
│   │   ├── AIChat.tsx              # AI chat interface
│   │   ├── FloatingChatBot.tsx     # Floating chat widget
│   │   ├── ThemeToggle.tsx         # Dark/light mode toggle
│   │   └── Toaster.tsx             # Toast notifications
│   ├── lib/
│   │   ├── types.ts                # TypeScript type definitions
│   │   ├── constants.ts            # App constants & course data
│   │   ├── anchor-client.ts        # Solana program client
│   │   └── nft-minter.ts           # NFT minting utilities
│   └── public/                     # Static assets
├── Anchor.toml                     # Anchor configuration
├── Cargo.toml                      # Rust dependencies
├── package.json                    # Root package.json
├── start-dev.bat                   # Windows startup script
├── PROJECT_COMPLETE.md             # Project documentation
├── QUICKSTART.md                   # Quick start guide
└── README.md                       # This file

🧪 Testing

Run Smart Contract Tests

# On Windows with WSL
wsl bash -lc "cd /mnt/d/code2/sah/tutor_project && anchor test"

# On Linux/Mac
anchor test

All 4 tests should pass:

  • ✅ Initialize tutor profile
  • ✅ Update progress
  • ✅ Prevent duplicate profiles
  • ✅ Fetch tutor profile

🔧 Technology Stack

Frontend

  • Next.js 15 - React framework with App Router
  • React 19 - Latest React features
  • TypeScript - Type-safe development
  • Tailwind CSS - Utility-first styling
  • Framer Motion - Smooth animations
  • Sonner - Toast notifications

Blockchain

  • Solana - High-performance blockchain
  • Anchor - Solana development framework
  • Metaplex - NFT minting standard
  • @solana/web3.js - Solana JavaScript SDK
  • @solana/wallet-adapter - Wallet integration

AI

  • Google Gemini 2.5 Flash - Latest AI model
  • @google/generative-ai - Gemini SDK

Development Tools

  • Rust - Smart contract language
  • Cargo - Rust package manager
  • WSL - Windows Subsystem for Linux (Windows only)

🎯 Smart Contract Details

Program ID

DC5BMrRcTAQEk2N8B6eYzxDyuCWXjLVqP3MJEg8F2fgu

Instructions

create_tutor

Creates a new tutor profile (one per wallet)

  • Accounts: user, tutor_profile, system_program
  • Args: subject (String)
  • Creates: PDA-based profile with initial level 1

update_progress

Updates user's learning progress

  • Accounts: user, tutor_profile
  • Args: new_level (u8), milestone_hash ([u8; 32])
  • Updates: Level and milestone tracking

Account Structure

pub struct TutorProfile {
    pub owner: Pubkey,          // Wallet address
    pub subject: String,        // Learning subject
    pub level: u8,              // Current level
    pub created_at: i64,        // Timestamp
    pub last_milestone: [u8; 32] // Latest achievement hash
}

🌐 API Routes

POST /api/chat

AI chat endpoint for tutoring interactions

Request Body:

{
  "messages": [
    { "role": "user", "content": "Explain smart contracts" }
  ],
  "subject": "Blockchain Fundamentals",
  "currentLesson": {
    "id": 4,
    "title": "Introduction to Blockchain"
  }
}

Response:

{
  "message": "Smart contracts are self-executing programs..."
}

🐛 Troubleshooting

Dev Server Won't Start

# Kill existing Node processes
Get-Process -Name node -ErrorAction SilentlyContinue | Stop-Process -Force

# Restart
cd app
npm run dev

Gemini API Errors

  • Verify your API key in app/.env.local
  • Check if key is valid at https://aistudio.google.com/app/apikey
  • Ensure you're using gemini-2.5-flash model
  • Check browser console for detailed error logs

Wallet Connection Issues

  • Make sure wallet extension is installed
  • Check if wallet is set to Devnet
  • Try disconnecting and reconnecting
  • Clear browser cache

Smart Contract Deployment Fails

# Reset test validator
solana-test-validator --reset

# Rebuild and deploy
anchor build
anchor deploy

NFT Minting Fails

  • Ensure wallet has SOL for transaction fees
  • Airdrop SOL: solana airdrop 2 (on devnet)
  • Check if Metaplex program is available
  • Verify connection to Solana network

Build Errors (Module Not Found)

If you get "Module not found" errors related to tutor_project.json:

  1. Make sure IDL is synced:
cd app
./sync-idl.bat  # Windows
./sync-idl.sh   # Linux/Mac
  1. Verify IDL file exists:

    • Check that app/lib/idl/tutor_project.json exists
    • If missing, rebuild contracts: anchor build
    • Then sync IDL again
  2. Clear Next.js cache:

cd app
rm -rf .next
npm run build

📝 Environment Variables

Variable Description Required Default
NEXT_PUBLIC_SOLANA_RPC_ENDPOINT Solana RPC URL Yes https://api.devnet.solana.com
GEMINI_API_KEY Google Gemini API key Yes -

🚢 Deployment

Frontend (Vercel)

  1. Push code to GitHub
  2. Import project in Vercel (select the app directory as root)
  3. Add environment variables:
    • NEXT_PUBLIC_SOLANA_RPC_ENDPOINT
    • GEMINI_API_KEY
  4. Deploy

Note: The IDL file is already included in app/lib/idl/. If you redeploy the smart contract, sync the new IDL:

cd app
./sync-idl.bat  # Windows
./sync-idl.sh   # Linux/Mac

Smart Contract (Mainnet)

  1. Change Anchor.toml cluster to mainnet-beta
  2. Build: anchor build
  3. Deploy: anchor deploy --provider.cluster mainnet
  4. Copy new program ID from deployment
  5. Update app/lib/constants.ts with new PROGRAM_ID
  6. Sync new IDL: Run cd app && ./sync-idl.bat (Windows) or ./sync-idl.sh (Linux/Mac)
  7. Commit and push changes

🤝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

📄 License

This project is licensed under the MIT License.

🙏 Acknowledgments

  • Solana - High-performance blockchain platform
  • Anchor - Solana development framework
  • Google Gemini - AI capabilities
  • Metaplex - NFT standards
  • Next.js - React framework

📞 Support

For issues or questions:


Built with ❤️ using Solana, Next.js, and AI

Learn, Earn, and Own Your Achievements on the Blockchain 🎓⚡🏆

Releases

No releases published

Packages

 
 
 

Contributors

Languages