A web application that uses AI to explain code snippets in simple, understandable terms.
Code Explainer AI helps developers understand any code by providing detailed, structured explanations. Simply paste your code, select the programming language, and get an instant AI-powered breakdown.
- Multi-language Support: JavaScript, Python, Java, TypeScript, C++, Go, and more
- Instant Explanations: Get detailed code breakdowns in seconds
- Copy to Clipboard: Easily save and share explanations
- Persistent Input: Code remains in the textarea for easy editing
- Clean UI: Simple, professional interface with gradient design
- React - UI framework
- Vite - Build tool and dev server
- TailwindCSS - Styling
- React Markdown - Renders formatted explanations
- Node.js with Express - Server framework
- Groq API - AI model provider (Llama 3.3 70B)
- Security: Helmet, CORS, Rate Limiting
Code-Explainer/
├── frontend/ # React frontend
│ ├── src/
│ │ ├── components/
│ │ │ ├── forms/
│ │ │ │ └── CodeExplainForm.jsx
│ │ │ ├── CodeExplaination.jsx
│ │ │ ├── CodeEntry.jsx
│ │ │ ├── Header.jsx
│ │ │ └── Error.jsx
│ │ ├── actions/
│ │ │ └── index.js
│ │ └── App.jsx
│ └── package.json
│
└── server/ # Express backend
├── server.js
├── .env
└── package.json
- Node.js (v16 or higher)
- npm or yarn
- Groq API key (free from https://console.groq.com)
-
Clone the repository
git clone <repository-url> cd Code-Explainer
-
Setup Backend
cd server npm install
-
Configure Environment Variables
Create a
.env
file in theserver
directory:GROQ_API_KEY=your_groq_api_key_here PORT=3001 FRONTEND_URL=http://localhost:5173
-
Setup Frontend
cd ../frontend npm install
-
Configure Frontend Environment
Create a
.env
file in thefrontend
directory:VITE_API_BASE_URL=http://localhost:3001/api
cd server
npm run dev
Server runs on: http://localhost:3001
cd frontend
npm run dev
Frontend runs on: http://localhost:5173
- User Input: User pastes code and selects programming language
- API Request: Frontend sends code to backend API endpoint
- AI Processing: Backend calls Groq API with Llama 3.3 70B model
- Response: AI generates structured explanation with:
- Overview
- Key Components
- How It Works
- Important Concepts
- Considerations
- Display: Frontend renders explanation in readable format
- Copy Feature: Users can copy explanation to clipboard
Request Body:
{
"code": "function add(a, b) { return a + b; }",
"language": "javascript"
}
Response:
{
"explanation": "Detailed AI explanation...",
"language": "javascript",
"model": "llama-3.3-70b-versatile"
}
Error Response:
{
"error": "Error message",
"details": "Error details"
}
CodeExplainForm.jsx
- Main form component
- Handles user input (code & language)
- Manages form state with React hooks
- Preserves code after submission
CodeExplaination.jsx
- Displays AI-generated explanations
- Includes copy-to-clipboard functionality
- Renders markdown formatting
actions/index.js
- Handles API communication
- Sends code to backend
- Manages success/error states
server.js
- Express server setup
- API endpoint configuration
- Groq API integration
- Security middleware (CORS, Helmet, Rate Limiting)
- Helmet: Sets security HTTP headers
- CORS: Configured for specific frontend origin
- Rate Limiting: 100 requests per 15 minutes per IP
- Input Validation: Checks for required fields
- Error Handling: Catches and sanitizes errors
{
"react": "^18.x",
"react-dom": "^18.x",
"react-markdown": "^9.x",
"remark-gfm": "^4.x"
}
{
"express": "^5.x",
"groq-sdk": "latest",
"dotenv": "^17.x",
"cors": "^2.x",
"helmet": "^8.x",
"express-rate-limit": "^8.x"
}
curl -X POST http://localhost:3001/api/explain-code \
-H "Content-Type: application/json" \
-d '{"code":"function add(a, b) { return a + b; }","language":"javascript"}'
Invoke-RestMethod -Uri "http://localhost:3001/api/explain-code" `
-Method POST `
-Body '{"code":"function add(a, b) { return a + b; }","language":"javascript"}' `
-ContentType "application/json"
1. Server won't start
- Check if port 3001 is already in use
- Verify GROQ_API_KEY is set in
.env
- Run
npm install
in server directory
2. Frontend can't connect to backend
- Ensure backend server is running
- Check VITE_API_BASE_URL in frontend
.env
- Verify CORS settings in server
3. API returns 503 error
- Groq API may be temporarily overloaded
- Wait a few seconds and try again
- Check API key validity at console.groq.com
MIT License