Skip to content

nikhilxagr/Code-Mentor-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Header

CodeMentor AI Badge

πŸš€ AI-Powered LeetCode Problem Solver & Learning Companion

Master Data Structures & Algorithms with AI-Driven Insights

Node.js Express MongoDB Gemini AI JWT

Features β€’ Getting Started β€’ API Documentation β€’ Contributing


πŸ“– About The Project

CodeMentor AI is an intelligent coding assistant that revolutionizes how you learn and solve LeetCode problems. Powered by Google's Gemini AI, it provides:

  • 🎯 Comprehensive Problem Analysis - Deep dive into problem statements with AI-powered insights
  • 🧠 Intelligent Learning Path - Step-by-step guidance tailored to your learning style
  • ⚑ Optimized Solutions - Industry-standard code with best practices
  • πŸ“Š Performance Metrics - Detailed time and space complexity analysis
  • πŸŽ“ Interview Preparation - Real-world problem-solving techniques

Whether you're preparing for FAANG interviews, strengthening your DSA fundamentals, or exploring algorithmic thinking, CodeMentor AI is your ultimate learning companion!


✨ Features

πŸ€– AI-Powered Intelligence

  • Smart Problem Breakdown - Gemini AI analyzes and explains problems in simple terms
  • Multiple Approaches - Learn different solutions from brute force to optimal
  • Code Explanation - Line-by-line breakdown of the solution

πŸ“š Comprehensive Learning

  • Step-by-Step Guidance - Clear progression from problem understanding to implementation
  • Pattern Recognition - Identify common problem-solving patterns
  • Complexity Analysis - Detailed Big-O notation for time and space

πŸ” User Management

  • Secure Authentication - JWT-based login system
  • Problem History - Access previously solved problems

πŸ’Ύ Robust Backend

  • MongoDB Integration - Scalable data persistence
  • RESTful API - Clean and documented endpoints
  • Error Handling - Comprehensive error management

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Frontend (Coming Soon)                    β”‚
β”‚           React.js + Tailwind CSS + TypeScript               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚ REST API
                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Express.js Backend                        β”‚
β”‚                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Routes    │──▢│ Controllers  │──▢│  Middleware     β”‚   β”‚
β”‚  β”‚  Layer     β”‚   β”‚  (Business   β”‚   β”‚  (Auth/Logging) β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚   Logic)     β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜                          β”‚
β”‚                          β”‚                                  β”‚
β”‚                   β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”                          β”‚
β”‚                   β”‚    Models    β”‚                          β”‚
β”‚                   β”‚   (Schemas)  β”‚                          β”‚
β”‚                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚                            β”‚
           β–Ό                            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Gemini AI API      β”‚    β”‚   MongoDB Atlas/Local    β”‚
β”‚                      β”‚    β”‚                          β”‚
β”‚ β€’ Problem Analysis   β”‚    β”‚ β€’ User Authentication    β”‚
β”‚ β€’ Solution Generationβ”‚    β”‚ β€’ Problem Storage        β”‚
β”‚ β€’ Code Explanation   β”‚    β”‚ β€’ Progress Tracking      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Getting Started

Prerequisites

Ensure you have the following installed on your system:

Quick Start Guide

1️⃣ Clone the Repository

git clone https://github.com/nikhilxagr/Code-Mentor-AI.git
cd Code-Mentor-AI

2️⃣ Install Dependencies

cd backend
npm install

3️⃣ Environment Configuration

Create a .env file in the backend directory:

# Server Configuration
PORT=5000
NODE_ENV=development

# Database Configuration
MONGO_URI=mongodb://localhost:27017/codementor
# For MongoDB Atlas: mongodb+srv://<username>:<password>@cluster.mongodb.net/codementor

# Google Gemini AI
GEMINI_API_KEY=your_gemini_api_key_here

# JWT Authentication
JWT_SECRET=your_super_secret_jwt_key_here
JWT_EXPIRE=7d

# CORS Settings
CORS_ORIGIN=http://localhost:3000

4️⃣ Start MongoDB

Local MongoDB:

mongod

MongoDB Atlas:

  • Copy your connection string from Atlas dashboard
  • Update MONGO_URI in .env

5️⃣ Run the Development Server

npm start

For development with auto-reload:

npm run dev

Your server should now be running on http://localhost:5000 πŸš€


πŸ› οΈ Tech Stack

Backend Technologies

Technology Version Purpose
Node.js v14+ JavaScript runtime environment
Express.js v4.18+ Fast, unopinionated web framework
MongoDB v5.0+ NoSQL database for data persistence
Mongoose v7.0+ Elegant MongoDB object modeling
Google Gemini AI Latest Advanced AI for problem solving
bcryptjs v2.4+ Secure password hashing
jsonwebtoken v9.0+ JWT-based authentication
dotenv v16.0+ Environment variable management
cors v2.8+ Enable cross-origin requests

πŸ“‘ API Endpoints

🧠 Problem Solving Endpoints

Get AI Solution

POST /api/solve
Content-Type: application/json

{
  "problemNumber": 1
}

Response:

{
  "success": true,
  "problem": {
    "number": 1,
    "title": "Two Sum",
    "difficulty": "Easy"
  },
  "answer": {
    "explanation": "Detailed problem breakdown...",
    "approach": "Step-by-step solution approach...",
    "solution": "Code implementation with explanation...",
    "complexity": {
      "time": "O(n)",
      "space": "O(n)"
    }
  }
}

πŸ“Š Utility Endpoints

Health Check

GET /api/health

Response:

{
  "status": "success",
  "message": "CodeMentor AI is running!",
  "timestamp": "2024-01-15T10:30:00Z"
}

πŸ—‚οΈ Project Structure

Code-Mentor-AI/
β”‚
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”œβ”€β”€ db.js                      # MongoDB connection configuration
β”‚   β”‚   └── gemini.js                  # Gemini AI initialization
β”‚   β”‚
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ auth.controller.js         # Authentication logic
β”‚   β”‚   └── solve.controller.js        # Problem solving logic
β”‚   β”‚
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”œβ”€β”€ auth.middleware.js         # JWT verification
β”‚   β”‚   └── error.middleware.js        # Error handling
β”‚   β”‚
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ User.model.js              # User schema
β”‚   β”‚   └── Problem.model.js           # Problem schema
β”‚   β”‚
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ auth.routes.js             # Authentication routes
β”‚   β”‚   └── solve.routes.js            # Problem solving routes
β”‚   β”‚
β”‚   β”œβ”€β”€ .env                           # Environment variables (gitignored)
β”‚   β”œβ”€β”€ .env.example                   # Example environment file
β”‚   β”œβ”€β”€ .gitignore                     # Git ignore rules
β”‚   β”œβ”€β”€ server.js                      # Entry point
β”‚   β”œβ”€β”€ package.json                   # Dependencies
β”‚   └── package-lock.json              # Dependency lock file
β”‚
β”œβ”€β”€ frontend/                          # (Coming Soon)
β”‚   └── README.md
β”‚
β”œβ”€β”€ .gitignore                         # Root git ignore
β”œβ”€β”€ LICENSE                            # MIT License
└── README.md                          # This file

🎯 How It Works

Problem Solving Flow

1. User Submits Problem Number
   ↓
2. Problem Validation
   ↓
3. Gemini AI Processing
   β”œβ”€β”€ Problem Analysis
   β”œβ”€β”€ Solution Generation
   β”œβ”€β”€ Code Optimization
   └── Complexity Calculation
   ↓
4. Response Formatting
   ↓
5. Return to User

πŸ”§ Configuration

Environment Variables

Variable Description Default Required
PORT Server port 5000 No
MONGO_URI MongoDB connection string - Yes
GEMINI_API_KEY Google Gemini API key - Yes
JWT_SECRET Secret for JWT signing - Yes
JWT_EXPIRE JWT token expiration 7d No
NODE_ENV Environment mode development No
CORS_ORIGIN Allowed CORS origins * No

πŸ› Troubleshooting

Common Issues

MongoDB Connection Error

Error: MongoNetworkError: failed to connect to server

Solution:

  • Check if MongoDB is running: mongod --version
  • Verify MONGO_URI in .env
  • Ensure IP whitelist in MongoDB Atlas

Gemini API Error

Error: Invalid API key

Solution:

Port Already in Use

Error: listen EADDRINUSE: address already in use :::5000

Solution:

# Find and kill the process
lsof -ti:5000 | xargs kill -9

🀝 Contributing

Contributions make the open-source community thrive! We welcome contributions of all kinds.

How to Contribute

  1. Fork the Project

    git clone https://github.com/nikhilxagr/Code-Mentor-AI.git
  2. Create Feature Branch

    git checkout -b feature/AmazingFeature
  3. Make Changes

    • Write clean, documented code
    • Follow existing code style
  4. Commit Changes

    git commit -m 'Add: Amazing new feature'
  5. Push to Branch

    git push origin feature/AmazingFeature
  6. Open Pull Request


πŸ“‹ Roadmap

  • Backend API with Express.js
  • MongoDB Integration
  • Gemini AI Integration
  • User Authentication System
  • Frontend Development (React.js)
  • User Dashboard
  • Progress Tracking
  • Problem Recommendation System

πŸ“œ License

Distributed under the MIT License. See LICENSE for more information.


πŸ‘¨β€πŸ’» Authors & Contributors

Project Collaborators

Nikhil Agrawal
Nikhil Agrawal

Full Stack Developer
GitHub
Gaurav Kumar Yadav
Gaurav Kumar Yadav

Full Stack Developer
GitHub

πŸ™ Acknowledgments

Special thanks to:

  • Google Gemini AI - For powerful AI capabilities
  • LeetCode - For the amazing problem database
  • MongoDB - For robust database solutions
  • Express.js - For the excellent web framework
  • Open Source Community - For continuous inspiration

πŸ“ž Support

Need help? We're here for you!


🌟 Show Your Support

If CodeMentor AI helped you ace your interviews or improve your coding skills, give it a ⭐️!


πŸ“Š Project Stats

GitHub stars GitHub forks GitHub contributors GitHub issues GitHub license


Made with πŸ’œ by Nikhil Agrawal & Gaurav Kumar Yadav

Happy Coding! πŸš€

Built with Love Powered by Coffee

Footer


"The only way to learn a new programming language is by writing programs in it." - Dennis Ritchie

About

CodeMentor AI is a full-stack AI-powered platform that helps developers understand and solve DSA problems by generating clear approaches, optimized solutions, and analyzing code for time and space complexity using AI.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors