Full-stack application that analyzes code efficiency, generates optimization suggestions, and tracks CO₂ emissions impact. Supports single file analysis (paste or upload) and full project analysis via ZIP upload.
- Paste or Upload Code: Paste code directly or upload individual code files (.py, .java, .js, .jsx, .html, .css)
- Multi-Language Support: Python, Java, JavaScript, HTML, and CSS
- Complexity Analysis: Heuristic analysis of loops, conditionals, functions, duplicates, and code complexity
- AI-Powered Suggestions: Optional Ollama-powered DeepSeek suggestions (local
deepseek-coder:1.3b) with deterministic fallback - CO₂ Impact Tracking: Estimates energy consumption and CO₂ emissions before and after optimization
- CodeCarbon Integration: Real-time measurements of actual backend energy/CO₂ usage per analysis
- ZIP Upload: Upload entire project folders (up to 250 MB) as ZIP files
- Multi-File Analysis: Analyzes all supported files in the project
- Interconnection Detection: Automatically detects file dependencies and interconnections
- Python:
importandfrom ... importstatements - Java:
importstatements - JavaScript:
import,require(), dynamic imports - HTML:
<script src>and<link href>tags - CSS:
@importstatements
- Python:
- Aggregate Metrics: Project-wide statistics including total LOC, complexity, and languages used
- Optimization Suggestions: AI suggestions for top complexity files
- Impact Dashboard: Visual charts showing CO₂ saved and compile time improvements over time
- History Tracking: SQLite-based history log with recent analyses panel
- Real-time Updates: Dashboard refreshes automatically after each analysis
Code-Efficiency-Analyser/
├── backend/ # Flask API + analysis modules
│ ├── analysis/ # Code analysis modules
│ │ ├── complexity.py # Complexity heuristics
│ │ ├── co2.py # CO₂ estimation
│ │ ├── suggestions.py # AI suggestion engine
│ │ └── project_analyzer.py # Multi-file project analysis
│ ├── services/ # Backend services
│ │ ├── history_store.py # SQLite history storage
│ │ ├── tracking.py # CodeCarbon integration
│ │ └── ollama_client.py # Ollama API client
│ ├── app.py # Flask application
│ └── requirements.txt # Python dependencies
└── frontend/ # Static UI
├── index.html # Main analysis page
├── dashboard.html # Dashboard page
├── main.js # Analysis page logic
├── dashboard.js # Dashboard logic
└── styles.css # Styling (white/blue theme)
-
Create a virtual environment and install dependencies:
cd Code-Efficiency-Analyser/backend python3 -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install -r requirements.txt
-
Optional: Setup Ollama for AI suggestions
- Install Ollama
- Pull the DeepSeek model:
ollama pull deepseek-coder:1.3b
- The backend points to
http://127.0.0.1:11434by default - Override with
export OLLAMA_BASE_URL=http://host:portif needed - Note: The app works without Ollama using heuristic fallbacks
-
CodeCarbon Configuration
- CodeCarbon runs automatically in process
- Set
COUNTRY_ISO_CODEenvironment variable for region-specific factors - Otherwise, global defaults are used
-
Run the Flask API:
cd backend flask --app app run --port 5000 --debugOr directly:
python app.py
-
Open the application:
- Simply open
frontend/index.htmlin a web browser - Or serve via HTTP server:
cd frontend python3 -m http.server 8000 # Then open http://localhost:8000 in browser
- Simply open
-
Update backend URL (if needed):
- Edit
BACKEND_URLinfrontend/main.jsif API runs on different host/port - Default:
http://localhost:5000
- Edit
Analyze a single code snippet.
Request:
{
"code": "string",
"language": "python" | "java" | "javascript" | "html" | "css"
}Response:
{
"analysis": {
"before": { /* complexity metrics */ },
"after": { /* optimized metrics */ },
"delta": { /* differences */ }
},
"co2": {
"before": {"energy_kwh": 0.0, "co2_kg": 0.0},
"after": {"energy_kwh": 0.0, "co2_kg": 0.0},
"energy_saved_kwh": 0.0
},
"session_emissions": {"energy_kwh": 0.0, "co2_kg": 0.0, "duration_s": 0.0},
"suggestion": {
"summary": "Optimization summary",
"confidence": "high/medium/low",
"analysis_insights": [ /* array of insights */ ],
"ai_model_used": "deepseek-coder:1.3b" | null,
"used_fallback": false,
"alternative_code": "optimized code"
},
"alternative_code": "string",
"history": [ /* recent analyses */ ]
}Analyze an entire project from a ZIP file.
Request: multipart/form-data with file field (ZIP archive, max 250 MB)
Response:
{
"project_analysis": {
"files": { /* file path -> analysis data */ },
"interconnections": [ /* dependency graph */ ],
"summary": {
"total_files": 10,
"total_lines_of_code": 1500,
"total_complexity": 45.2,
"languages": ["python", "javascript"],
"interconnection_count": 8
}
},
"co2": { /* aggregate CO₂ impact */ },
"session_emissions": { /* measured emissions */ },
"suggestions": [ /* top file suggestions */ ]
}Returns the 25 most recent analyses from SQLite log.
Returns aggregated dashboard statistics for visualization.
Health check endpoint.
- SQLite Database:
backend/data/history.db - Automatically created on first run
- Stores all analysis results, metrics, and emissions data
- Backend: Flask (Python)
- Frontend: Vanilla HTML/CSS/JavaScript (no build step)
- Database: SQLite
- Energy Tracking: CodeCarbon
- AI Suggestions: Ollama (optional, with heuristic fallback)
- Visualization: Chart.js (dashboard only)
The application uses a clean white background with blue accents:
- Background: Pure white (#ffffff)
- Primary Text: Dark gray (#1e2937)
- Accents: Blue shades (#2563eb, #3b82f6)
- Borders: Light gray (#cbd5e1, #e2e8f0)
- Cards: Light gray background (#f8fafc)
- Support for more languages (TypeScript, C++, Go, etc.)
- AST-based code optimization
- Real-time collaboration features
- Export analysis reports (PDF/JSON)
- Integration with CI/CD pipelines
- Advanced dependency visualization