narasimha01tm's picture
feat: deploy fixed and cleaned backend
1ba51fa
|
Raw History Blame Contribute Delete
5.18 kB
metadata
title: AI Learning Dashboard API
emoji: πŸŽ“
colorFrom: green
colorTo: blue
sdk: docker
app_port: 7860
pinned: false

AI Learning Dashboard - Backend API

A comprehensive RESTful API built with Express.js, TypeScript, and MongoDB for the AI Learning Dashboard.

πŸš€ Quick Start

Prerequisites

  • Node.js (v18 or higher)
  • MongoDB (running on localhost:27017)

Installation

  1. Navigate to the server directory:
cd server
  1. Install dependencies:
npm install
  1. Create a .env file (copy from .env.example):
# On Windows PowerShell
Copy-Item .env.example .env

# On Linux/Mac
cp .env.example .env
  1. Update the .env file with your configuration

  2. Start the development server:

npm run dev

The API will be available at http://localhost:5000

πŸ“š API Documentation

Base URL

http://localhost:5000/api

Authentication

All protected routes require a JWT token in the Authorization header:

Authorization: Bearer <token>

Endpoints

πŸ” Authentication

  • POST /auth/register - Register new user
  • POST /auth/login - Login user
  • GET /auth/me - Get current user (protected)

πŸ‘€ User Management

  • PUT /user/profile - Update user profile (protected)
  • PUT /user/settings - Update user settings (protected)

πŸ“Š Progress & Analytics

  • GET /progress - Get user progress (protected)
  • POST /progress/quiz - Submit quiz score (protected)
  • POST /progress/study-time - Log study time (protected)
  • GET /analytics/quiz-scores - Get quiz scores trend (protected)
  • GET /analytics/study-time - Get study time data (protected)
  • GET /analytics/improvement - Get improvement metrics (protected)
  • GET /analytics/summary - Get full analytics summary (protected)

πŸ›€οΈ Learning Path

  • GET /learning-path - Get user's learning path (protected)
  • PUT /learning-path/step/:stepId - Update step progress (protected)
  • POST /learning-path/generate - Generate new learning path (protected)

πŸ“š Resources

  • GET /resources - Get all resources (public)
  • GET /resources/:id - Get single resource (public)
  • GET /resources/user/recommended - Get AI-recommended resources (protected)
  • POST /resources - Create new resource (protected)

πŸ’¬ AI Assistant

  • POST /assistant/chat - Send message to AI (protected)
  • GET /assistant/history - Get chat history (protected)
  • DELETE /assistant/history - Clear chat history (protected)
  • GET /assistant/suggestions - Get suggested topics (protected)

🎯 Skill Gaps

  • GET /skill-gaps - Get user's skill gaps (protected)
  • POST /skill-gaps/assessment - Submit skill assessment (protected)
  • GET /skill-gaps/recommendations - Get recommendations (protected)

πŸ—οΈ Project Structure

server/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config/          # Configuration files
β”‚   β”œβ”€β”€ controllers/     # Request handlers
β”‚   β”œβ”€β”€ middleware/      # Custom middleware
β”‚   β”œβ”€β”€ models/          # MongoDB models
β”‚   β”œβ”€β”€ routes/          # API routes
β”‚   β”œβ”€β”€ types/           # TypeScript types
β”‚   └── server.ts        # Entry point
β”œβ”€β”€ package.json
└── tsconfig.json

πŸ”§ Available Scripts

  • npm run dev - Start development server with hot reload
  • npm run build - Build for production
  • npm start - Start production server

πŸ—„οΈ Database Models

  • User - User authentication and preferences
  • Progress - Learning progress tracking
  • LearningPath - Personalized learning paths
  • Resource - Learning materials
  • ChatMessage - AI assistant conversation history
  • SkillGap - Skill assessments and gaps

πŸ”‘ Environment Variables

PORT=5000
NODE_ENV=development
MONGODB_URI=mongodb://localhost:27017/ai-learning-dashboard
JWT_SECRET=your-secret-key
JWT_EXPIRE=7d
CORS_ORIGIN=http://localhost:3000

πŸ“ Example Usage

Register a new user

POST /api/auth/register
{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "password123"
}

Login

POST /api/auth/login
{
  "email": "john@example.com",
  "password": "password123"
}

Get Progress

GET /api/progress
Headers: {
  "Authorization": "Bearer <token>"
}

🎨 Frontend Integration

Use the API client in lib/api.ts:

import api from '@/lib/api';

// Login
const result = await api.login('user@example.com', 'password');

// Get progress
const progress = await api.getProgress();

// Get recommendations
const resources = await api.getRecommendedResources();

πŸ›‘οΈ Security Features

  • JWT-based authentication
  • Password hashing with bcrypt
  • CORS protection
  • Request validation
  • Error handling middleware

πŸ“¦ Dependencies

  • express - Web framework
  • mongoose - MongoDB ODM
  • jsonwebtoken - JWT authentication
  • bcryptjs - Password hashing
  • cors - CORS middleware
  • dotenv - Environment variables
  • joi - Validation

🀝 Contributing

  1. Create a feature branch
  2. Make your changes
  3. Test thoroughly
  4. Submit a pull request

πŸ“„ License

ISC