An intelligent code review platform powered by Google Gemini AI with real-time streaming capabilities and comprehensive analytics.
CodeCritic AI is a sophisticated backend service that provides AI-powered code reviews with a humorous and constructive approach. Built with modern technologies, it offers both traditional API responses and real-time streaming capabilities, complete with comprehensive logging and analytics.
- Google Gemini 2.0 Flash integration for advanced code review
- Humorous & Professional Reviews - Combines constructive feedback with witty commentary
- Multi-language Support - Automatic detection of JavaScript, Python, Java, C/C++, PHP, Rust, Go
- Comprehensive Analysis - Code quality, performance, security, maintainability, best practices
- Server-Sent Events (SSE) for real-time response delivery
- Chunk-based Streaming with progress tracking
- Live Demo Interface at
/streaming-demo.html - Graceful Error Handling during streaming
- Complete Interaction Storage - User code, AI responses, metadata
- User Analytics - IP tracking, session management, response times
- Performance Indexing - Optimized queries for analytics
- Automatic Language Detection and categorization
- Comprehensive Request Tracking with unique request IDs
- Color-coded Console Logging with multiple severity levels
- File-based Log Storage (app.log, error.log, warn.log)
- Performance Monitoring with response time tracking
- Database Operation Logging with success/failure tracking
- Usage Statistics - Total interactions, unique users, daily metrics
- Language Analytics - Programming language usage patterns
- IP-based Tracking - User interaction history
- Paginated Data Retrieval with filtering options
src/
βββ π config/
β βββ database.js # MongoDB connection & configuration
βββ π controllers/
β βββ ai.controller.js # Standard AI analysis endpoints
β βββ ai.streaming.controller.js # Real-time streaming endpoints
β βββ admin.controller.js # Analytics & admin endpoints
βββ π middleware/
β βββ logging.js # Request logging & error handling
βββ π models/
β βββ CodeInteraction.js # MongoDB schema for interactions
βββ π routes/
β βββ ai.routes.js # Standard API routes
β βββ ai.streaming.routes.js # Streaming API routes
β βββ admin.routes.js # Admin/analytics routes
βββ π services/
β βββ ai.service.js # Core AI integration service
β βββ ai.streaming.service.js # Streaming AI service
βββ π utils/
β βββ logger.js # Centralized logging utility
βββ app.js # Express application setup
POST /ai/get-response
Content-Type: application/json
{
"prompt": "function add(a, b) { return a + b; }",
"sessionId": "optional-session-id"
}Response:
{
"success": true,
"response": "π₯ Well, well, well... This function is so basic...",
"sessionId": "session_abc123",
"timestamp": "2025-09-14T10:30:00.000Z",
"requestId": "req_xyz789"
}POST /ai/stream
Content-Type: application/json
{
"prompt": "function add(a, b) { return a + b; }",
"sessionId": "optional-session-id"
}Server-Sent Events Response:
data: {"type":"connected","sessionId":"session_abc123","timestamp":1726311000000}
data: {"type":"chunk","data":"π₯ Well, well, well...","timestamp":1726311001000}
data: {"type":"chunk","data":" This function is so basic...","timestamp":1726311002000}
data: {"type":"complete","data":{"sessionId":"session_abc123","responseTime":2000,"totalLength":850,"saved":true},"timestamp":1726311003000}
data: [DONE]
GET /admin/statsResponse:
{
"success": true,
"stats": {
"totalInteractions": 1250,
"uniqueUsers": 387,
"todayInteractions": 45,
"languageStats": [
{"_id": "javascript", "count": 520},
{"_id": "python", "count": 380},
{"_id": "java", "count": 210}
],
"averageResponseTime": 1340
},
"requestId": "req_stats_123",
"timestamp": "2025-09-14T10:30:00.000Z"
}GET /admin/interactions?page=1&limit=10GET /admin/interactions/ip/192.168.1.100?page=1&limit=5GET /- Welcome message & health checkGET /streaming-demo.html- Interactive streaming demo
- Node.js v16 or higher
- MongoDB (local or cloud)
- Google Gemini API key
git clone https://github.com/aditya-Kumar421/codeCriticAI.git
cd codeCriticAI
npm installCreate a .env file:
# Google Gemini API Configuration
GOOGLE_GEMINI_KEY=your_gemini_api_key_here
# MongoDB Configuration
MONGODB_URI=mongodb://localhost:27017/codecritic
# For MongoDB Atlas:
# MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/codecritic
# Server Configuration
PORT=8000
NODE_ENV=development# Production
npm start
# Development (with nodemon)
npm run devThe server will start on http://localhost:8000
{
_id: ObjectId,
userCode: String, // Original code submitted
aiResponse: String, // Complete AI analysis
userIP: String, // Client IP address
userAgent: String, // Browser/client information
timestamp: Date, // Interaction timestamp
responseTime: Number, // AI response time (ms)
codeLanguage: String, // Detected programming language
sessionId: String, // Session identifier
createdAt: Date, // Auto-generated
updatedAt: Date // Auto-generated
}{ userIP: 1, timestamp: -1 }- IP-based queries{ timestamp: -1 }- Time-based sorting
// Standard API call
async function analyzeCode(code) {
const response = await fetch('http://localhost:8000/ai/get-response', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt: code })
});
return await response.json();
}
// Streaming API call
async function streamCodeAnalysis(code) {
const response = await fetch('http://localhost:8000/ai/stream', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt: code })
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const lines = chunk.split('\n');
for (const line of lines) {
if (line.startsWith('data: ')) {
const data = line.slice(6);
if (data === '[DONE]') return;
try {
const parsed = JSON.parse(data);
handleStreamChunk(parsed);
} catch (e) {
console.error('Parse error:', e);
}
}
}
}
}
function handleStreamChunk(chunk) {
switch (chunk.type) {
case 'connected':
console.log('π Connected to stream');
break;
case 'chunk':
process.stdout.write(chunk.data);
break;
case 'complete':
console.log('\nβ
Analysis complete');
break;
case 'error':
console.error('β Error:', chunk.data.error);
break;
}
}import requests
import json
def analyze_code(code):
response = requests.post(
'http://localhost:8000/ai/get-response',
json={'prompt': code}
)
return response.json()
# Usage
result = analyze_code('def hello(): print("Hello World")')
print(result['response'])# Standard analysis
curl -X POST http://localhost:8000/ai/get-response \
-H "Content-Type: application/json" \
-d '{"prompt": "function test() { console.log(\"hello\"); }"}'
# Get statistics
curl http://localhost:8000/admin/stats
# Get recent interactions
curl "http://localhost:8000/admin/interactions?page=1&limit=5"- π΄ ERROR - API failures, database errors, AI service issues
- π‘ WARN - Invalid requests, non-critical failures
- π΅ INFO - Request/response cycles, database operations
- π£ DEBUG - Detailed operation steps, streaming chunks
- π’ SUCCESS - Successful completions, connections
src/logs/
βββ app.log # All application logs
βββ error.log # Error-only logs
βββ warn.log # Warning-only logs
{
"timestamp": "2025-09-14T10:30:00.000Z",
"level": "INFO",
"message": "Request completed for POST /ai/get-response",
"meta": {
"method": "POST",
"endpoint": "POST /ai/get-response",
"ip": "192.168.1.100",
"statusCode": 200,
"duration": "1250ms",
"sessionId": "session_abc123",
"requestId": "req_xyz789"
},
"pid": 12345
}| Variable | Default | Description |
|---|---|---|
PORT |
8000 |
Server port |
NODE_ENV |
development |
Environment mode |
MONGODB_URI |
mongodb://localhost:27017/codecritic |
Database connection |
GOOGLE_GEMINI_KEY |
(required) | Google Gemini API key |
- Model:
gemini-2.0-flash - System Instruction: Senior code reviewer with humor
- Response Length: 700-900 words
- Review Structure: Roast β Suggestions β Appreciation β Encouragement
- Standard API: ~1-3 seconds
- Streaming API: First chunk in ~500ms
- Database Operations: <100ms (with indexes)
- Analytics Queries: ~200-500ms
- Concurrent Requests: 100+ (depending on AI API limits)
- Database Connections: Pooled connections via Mongoose
- Memory Usage: ~50-100MB base, +10MB per concurrent request
- Rate Limiting: Implement based on Google Gemini API quotas
- Load Balancing: Stateless design supports horizontal scaling
- Database Sharding: Consider for high-volume deployments
- Caching: Implement Redis for frequent queries
- IP Anonymization options available
- Request Validation with input sanitization
- Error Message Sanitization in production
- API Key Security - never logged or exposed
- Admin Endpoints - Ready for authentication middleware
- CORS Configuration - Configurable origins
- Rate Limiting - Ready for implementation
- Request Logging - Full audit trail
The application includes vercel.json for easy Vercel deployment:
# Install Vercel CLI
npm i -g vercel
# Deploy
vercel --prodFROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 8000
CMD ["npm", "start"]# Using PM2
npm install -g pm2
pm2 start server.js --name "codecritic-ai"
pm2 startup
pm2 saveVisit the live demo at: http://localhost:8000/streaming-demo.html
# Health check
curl http://localhost:8000/
# Test AI endpoint
curl -X POST http://localhost:8000/ai/get-response \
-H "Content-Type: application/json" \
-d '{"prompt": "console.log(\"test\");"}'
# Test streaming endpoint
curl -X POST http://localhost:8000/ai/stream \
-H "Content-Type: application/json" \
-d '{"prompt": "console.log(\"test\");"}'- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow the existing code structure
- Add comprehensive logging for new features
- Update documentation for API changes
- Test both streaming and standard endpoints
This project is licensed under the ISC License - see the LICENSE file for details.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: aditya.kumar421@example.com
- Google Gemini AI for powerful language model capabilities
- MongoDB for flexible document storage
- Express.js community for robust web framework
- Open Source Community for inspiration and tools
Made with β€οΈ by Aditya Kumar
Transform your code reviews from mundane to memorable with CodeCritic AI! π