Skip to content

Aditya290605/learnAi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

18 Commits
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ LearnAI - AI-Powered Learning Platform

React Node.js TypeScript MongoDB JWT License

๐ŸŽฏ Personalized learning roadmaps powered by AI with secure authentication

Build your skills with interactive, visual learning journeys tailored to your goals


โœจ Features

Security
๐Ÿ” Secure Authentication
Complete JWT-based user system with password hashing
AI
๐Ÿค– AI-Powered Roadmaps
Personalized learning paths generated by AI
Progress
๐Ÿ“ˆ Progress Tracking
Visual progress indicators and milestone tracking
Interactive
๐ŸŽฏ Interactive Roadmaps
Visual learning journey with step dependencies
Responsive
๐Ÿ“ฑ Responsive Design
Works seamlessly on all devices
Security
๐Ÿ›ก๏ธ Security Features
Rate limiting, CORS, and input validation

๐Ÿ› ๏ธ Tech Stack

๐ŸŽจ Frontend

React 19          - Modern React with hooks and concurrent features
TypeScript        - Type-safe development experience
Vite             - Lightning-fast build tool and dev server
Tailwind CSS     - Utility-first CSS framework
Lucide React     - Beautiful, customizable icon library
React Flow       - Interactive node-based diagrams

โš™๏ธ Backend

Node.js          - JavaScript runtime environment
Express.js       - Fast, unopinionated web framework
MongoDB          - NoSQL document database
Mongoose         - Elegant MongoDB object modeling
JWT              - Secure token-based authentication
bcryptjs         - Advanced password hashing
express-validator - Server-side input validation
helmet           - Security middleware collection
cors             - Cross-origin resource sharing

๐Ÿ“ Project Structure

๐Ÿ“ฆ LearnAI/
โ”œโ”€โ”€ ๐ŸŽจ src/                    # Frontend React application
โ”‚   โ”œโ”€โ”€ ๐Ÿงฉ components/         # Reusable UI components
โ”‚   โ”‚   โ”œโ”€โ”€ ui/                # Base UI components (Button, Card, etc.)
โ”‚   โ”‚   โ”œโ”€โ”€ layout/            # Layout components (Header, Sidebar)
โ”‚   โ”‚   โ””โ”€โ”€ forms/             # Form components
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ pages/             # Page components and route handlers
โ”‚   โ”‚   โ”œโ”€โ”€ auth/              # Authentication pages
โ”‚   โ”‚   โ”œโ”€โ”€ dashboard/         # Dashboard and user pages
โ”‚   โ”‚   โ””โ”€โ”€ roadmap/           # Roadmap-related pages
โ”‚   โ”œโ”€โ”€ ๐Ÿ”ง utils/             # Utility functions
โ”‚   โ”‚   โ”œโ”€โ”€ auth.ts            # Authentication helpers
โ”‚   โ”‚   โ”œโ”€โ”€ api.ts             # API client configuration
โ”‚   โ”‚   โ””โ”€โ”€ constants.ts       # Application constants
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ types/             # TypeScript type definitions
โ”‚   โ””โ”€โ”€ ๐ŸŽญ mockData/          # Mock data for development
โ”œโ”€โ”€ ๐Ÿ–ฅ๏ธ backend/               # Backend Node.js application
โ”‚   โ”œโ”€โ”€ โš™๏ธ config/            # Configuration files
โ”‚   โ”‚   โ””โ”€โ”€ database.js        # MongoDB connection setup
โ”‚   โ”œโ”€โ”€ ๐ŸŽฎ controllers/       # Business logic controllers
โ”‚   โ”‚   โ”œโ”€โ”€ authController.js  # Authentication logic
โ”‚   โ”‚   โ”œโ”€โ”€ userController.js  # User management
โ”‚   โ”‚   โ””โ”€โ”€ roadmapController.js # Roadmap operations
โ”‚   โ”œโ”€โ”€ ๐Ÿ›ก๏ธ middleware/        # Express middleware
โ”‚   โ”‚   โ”œโ”€โ”€ auth.js            # JWT authentication middleware
โ”‚   โ”‚   โ”œโ”€โ”€ validation.js      # Input validation
โ”‚   โ”‚   โ””โ”€โ”€ rateLimiter.js     # Rate limiting
โ”‚   โ”œโ”€โ”€ ๐Ÿ“Š models/            # Database models
โ”‚   โ”‚   โ”œโ”€โ”€ User.js            # User model schema
โ”‚   โ”‚   โ”œโ”€โ”€ Roadmap.js         # Roadmap model schema
โ”‚   โ”‚   โ””โ”€โ”€ Progress.js        # Progress tracking schema
โ”‚   โ”œโ”€โ”€ ๐Ÿ›ฃ๏ธ routes/            # API route definitions
โ”‚   โ”‚   โ”œโ”€โ”€ auth.js            # Authentication routes
โ”‚   โ”‚   โ”œโ”€โ”€ users.js           # User management routes
โ”‚   โ”‚   โ””โ”€โ”€ roadmaps.js        # Roadmap routes
โ”‚   โ””โ”€โ”€ ๐Ÿ”ง utils/             # Backend utility functions
โ”œโ”€โ”€ ๐Ÿ“– docs/                   # Documentation files
โ”œโ”€โ”€ ๐Ÿงช tests/                  # Test files
โ””โ”€โ”€ ๐Ÿ“„ README.md

๐Ÿš€ Quick Start Guide

๐Ÿ“‹ Prerequisites

Requirement Version Download
Node.js 18.0+ Download
MongoDB 6.0+ Download or Atlas
Package Manager npm/yarn Included with Node.js

1๏ธโƒฃ Clone and Install

# Clone the repository
git clone https://github.com/yourusername/LearnAI.git
cd LearnAI

# Install frontend dependencies
npm install

# Install backend dependencies
cd backend
npm install
cd ..

2๏ธโƒฃ Environment Setup

๐Ÿ–ฅ๏ธ Backend Configuration

Create backend/.env:

cd backend
cp .env.example .env

Configure your environment variables:

# ๐Ÿ”ง Server Configuration
PORT=5000
NODE_ENV=development

# ๐Ÿ—„๏ธ MongoDB Configuration
MONGODB_URI=mongodb://localhost:27017/LearnAI
# For Atlas: mongodb+srv://username:[email protected]/LearnAI

# ๐Ÿ”‘ JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-min-32-chars-change-in-production
JWT_EXPIRES_IN=7d

# ๐ŸŒ CORS Configuration
FRONTEND_URL=http://localhost:5173

# ๐Ÿ›ก๏ธ Security Configuration
RATE_LIMIT_WINDOW_MS=900000    # 15 minutes
RATE_LIMIT_MAX_REQUESTS=100    # Max 100 requests per window

# ๐Ÿ“ง Email Configuration (Optional)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=[email protected]
SMTP_PASS=your-app-password

๐ŸŽจ Frontend Configuration

Create root .env:

# API Configuration
VITE_API_URL=http://localhost:5000/api

# Feature Flags
VITE_ENABLE_ANALYTICS=false
VITE_ENABLE_DEBUG=true

3๏ธโƒฃ Database Setup

๐Ÿ  Local MongoDB

# Install MongoDB locally
# macOS with Homebrew
brew install mongodb-community

# Start MongoDB service
brew services start mongodb-community

# Or start manually
mongod --config /usr/local/etc/mongod.conf

โ˜๏ธ MongoDB Atlas (Recommended for Production)

  1. ๐Ÿ“ Create a MongoDB Atlas account
  2. ๐Ÿ†• Create a new cluster
  3. ๐Ÿ‘ค Create a database user
  4. ๐ŸŒ Whitelist your IP address
  5. ๐Ÿ”— Get your connection string
  6. โœ๏ธ Update MONGODB_URI in your .env file

4๏ธโƒฃ Launch Application

Start Backend Server

cd backend
npm run dev

๐ŸŒ Backend runs on: http://localhost:5000

Start Frontend Server

# In a new terminal from root directory
npm run dev

๐ŸŒ Frontend runs on: http://localhost:5173

5๏ธโƒฃ Verify Setup

Service URL Status
๐ŸŽจ Frontend http://localhost:5173 Should show login page
๐Ÿ–ฅ๏ธ Backend Health http://localhost:5000/health Should return {"status":"OK"}
๐Ÿ—„๏ธ Database MongoDB Compass Connect with your URI

๐Ÿ”Œ API Documentation

๐Ÿ” Authentication Endpoints

POST /api/auth/signup - Register new user

Request Body:

{
  "name": "John Doe",
  "email": "[email protected]",
  "password": "SecurePassword123!"
}

Response:

{
  "success": true,
  "message": "User created successfully",
  "data": {
    "user": {
      "id": "user_id",
      "name": "John Doe",
      "email": "[email protected]"
    },
    "token": "jwt_token_here"
  }
}
POST /api/auth/signin - Login user

Request Body:

{
  "email": "[email protected]",
  "password": "SecurePassword123!"
}

Response:

{
  "success": true,
  "message": "Login successful",
  "data": {
    "user": {
      "id": "user_id",
      "name": "John Doe",
      "email": "[email protected]"
    },
    "token": "jwt_token_here"
  }
}
GET /api/auth/me - Get current user

Headers:

Authorization: Bearer jwt_token_here

Response:

{
  "success": true,
  "data": {
    "user": {
      "id": "user_id",
      "name": "John Doe",
      "email": "[email protected]",
      "createdAt": "2024-01-01T00:00:00.000Z"
    }
  }
}

๐ŸŽฏ Roadmap Endpoints

GET /api/roadmaps - Get user's roadmaps

Headers:

Authorization: Bearer jwt_token_here

Response:

{
  "success": true,
  "data": {
    "roadmaps": [
      {
        "id": "roadmap_id",
        "title": "Full Stack Development",
        "description": "Complete web development roadmap",
        "progress": 45,
        "totalSteps": 12,
        "completedSteps": 5
      }
    ]
  }
}

๐Ÿ›ก๏ธ Security Features

Security Layer Implementation Protection Against
๐Ÿ” Password Security bcrypt with salt rounds Rainbow table attacks
๐ŸŽซ JWT Authentication Secure token-based auth Session hijacking
๐Ÿšฆ Rate Limiting Express rate limiter Brute force attacks
๐ŸŒ CORS Protection Configured origins Cross-origin attacks
โœ… Input Validation express-validator Injection attacks
๐Ÿ›ก๏ธ HTTP Security Helmet middleware Various web vulnerabilities

๐Ÿงช Development

๐Ÿ“œ Available Scripts

Frontend Commands

npm run dev          # ๐Ÿš€ Start development server
npm run build        # ๐Ÿ—๏ธ Build for production
npm run preview      # ๐Ÿ‘€ Preview production build
npm run lint         # ๐Ÿ” Run ESLint
npm run type-check   # ๐Ÿ“ Run TypeScript checks

Backend Commands

npm run dev          # ๐Ÿ”„ Start with nodemon (hot reload)
npm start            # ๐Ÿƒ Start production server
npm run test         # ๐Ÿงช Run tests
npm run seed         # ๐ŸŒฑ Seed database with sample data

๐Ÿ—๏ธ Development Workflow

  1. ๐Ÿ”„ Hot Reloading: Both frontend and backend support hot reloading
  2. ๐ŸŽจ Code Formatting: Prettier configuration included
  3. ๐Ÿ” Linting: ESLint rules for consistent code style
  4. ๐Ÿ“ TypeScript: Full type safety on frontend
  5. ๐Ÿงช Testing: Jest setup for unit and integration tests

๐Ÿ—‚๏ธ Code Organization

๐Ÿ“ฆ Architecture Pattern: Feature-based modules
โ”œโ”€โ”€ ๐Ÿงฉ Components: Reusable UI building blocks
โ”œโ”€โ”€ ๐Ÿ“„ Pages: Route-level components
โ”œโ”€โ”€ ๐ŸŽฎ Controllers: Business logic handlers
โ”œโ”€โ”€ ๐Ÿ“Š Models: Data structure definitions
โ”œโ”€โ”€ ๐Ÿ›ก๏ธ Middleware: Request/response interceptors
โ”œโ”€โ”€ ๐Ÿ”ง Utils: Helper functions and utilities

๐Ÿš€ Deployment Guide

โ˜๏ธ Backend Deployment Options

Platform Complexity Free Tier Guide
๐Ÿš‚ Railway Easy โœ… Yes Deploy
โ–ฒ Vercel Easy โœ… Yes Deploy
๐ŸŸฃ Heroku Medium โŒ No Deploy
๐ŸŒŠ DigitalOcean Medium ๐Ÿ’ฐ Credit Deploy

๐ŸŽจ Frontend Deployment

# Build the application
npm run build

# Deploy options:
# 1. Vercel: vercel --prod
# 2. Netlify: ntl deploy --prod --dir=dist
# 3. GitHub Pages: npm run deploy

๐Ÿ”ง Environment Variables for Production

# Production Backend (.env)
NODE_ENV=production
MONGODB_URI=your_production_mongodb_uri
JWT_SECRET=your_super_secure_production_secret
FRONTEND_URL=https://your-domain.com

# Production Frontend (.env.production)
VITE_API_URL=https://your-api-domain.com/api
VITE_ENABLE_ANALYTICS=true

๐Ÿค Contributing

We welcome contributions! Please follow these steps:

๐Ÿš€ Quick Contribution Guide

  1. ๐Ÿด Fork the repository
  2. ๐ŸŒฟ Create a feature branch: git checkout -b feature/amazing-feature
  3. โœจ Make your changes with proper commit messages
  4. ๐Ÿงช Add tests if applicable
  5. ๐Ÿ“ Update documentation if needed
  6. ๐Ÿ”„ Submit a pull request

๐Ÿ“ Code Style Guidelines

  • โœ… Follow existing code patterns
  • ๐Ÿ“ Use TypeScript for new frontend code
  • ๐Ÿงช Add tests for new features
  • ๐Ÿ“– Update documentation
  • ๐Ÿท๏ธ Use conventional commit messages

๐Ÿท๏ธ Commit Message Format

type(scope): description

feat(auth): add password reset functionality
fix(ui): resolve mobile navigation issue
docs(api): update endpoint documentation

๐Ÿ“Š Performance & Monitoring

๐ŸŽฏ Performance Features

  • โšก Code Splitting: Automatic route-based splitting
  • ๐Ÿ—œ๏ธ Asset Optimization: Vite's built-in optimizations
  • ๐Ÿ’พ Caching: Strategic API response caching
  • ๐Ÿ“ฑ Lazy Loading: Components loaded on demand

๐Ÿ“ˆ Monitoring Setup

// Performance monitoring (optional)
import { getCLS, getFID, getFCP, getLCP, getTTFB } from 'web-vitals';

getCLS(console.log);
getFID(console.log);
getFCP(console.log);
getLCP(console.log);
getTTFB(console.log);

๐Ÿ› Troubleshooting

โŒ Common Issues & Solutions

MongoDB Connection Error

# Check if MongoDB is running
brew services list | grep mongodb
# Restart if needed
brew services restart mongodb-community

Port Already in Use

# Find process using port 5000
lsof -i :5000
# Kill the process
kill -9 PID

JWT Token Issues

  • Verify JWT_SECRET is set and consistent
  • Check token expiration settings
  • Ensure proper token storage on frontend

CORS Errors

  • Verify FRONTEND_URL matches your development URL
  • Check browser network tab for preflight requests
  • Ensure credentials are included in requests

๐Ÿ“š Additional Resources

Resource Link Description
๐Ÿ“– Documentation View Docs Comprehensive API and feature docs
๐ŸŽจ Design System Design Guide UI components and guidelines
๐Ÿงช API Testing Postman Collection Ready-to-use API tests
๐ŸŽฏ Roadmap Project Roadmap Upcoming features and timeline

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Made with โค๏ธ by Aditya

โญ Star this project โ€ข ๐Ÿ› Report Bug โ€ข ๐Ÿ’ก Request Feature


๐Ÿš€ Ready to build amazing learning experiences? Let's get started!

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published