What is CodePulse?

CodePulse is a static analysis tool for Python source code. It parses your code into an Abstract Syntax Tree (AST) and computes a range of quality metrics without ever executing the code.

Metrics Computed

⚙ Cyclomatic Complexity

Measures the number of linearly independent paths through your code. Higher complexity means more test cases needed. We count branches from if, for, while, except, with, and/or, assert, and comprehensions.

📊 Halstead Metrics

Quantifies code using operators and operands. We compute Volume (size of implementation), Difficulty (how hard to understand), Effort (mental effort to develop), estimated Bugs, and estimated Development Time.

📈 Maintainability Index

A composite score (0-100) based on Halstead Volume, cyclomatic complexity, and lines of code. Uses the Microsoft variant: MI = max(0, (171 - 5.2*ln(V) - 0.23*G - 16.2*ln(LOC)) * 100/171)

👃 Code Smell Detection

Identifies common anti-patterns: long functions (>50 lines), too many parameters (>5), deep nesting (>4 levels), high function complexity (>10), missing docstrings, unused imports, magic numbers, god classes (>15 methods), and duplicate code blocks.

Grading Scale

A Excellent maintainability, low complexity
B Good quality, moderate complexity
C Acceptable but could be improved
D Poor quality, consider refactoring
F Very poor, syntax errors or major issues

REST API

GET /api/health Service health check
POST /api/analyze Analyze Python code (JSON body: {"code": "...", "filename": "..."})
GET /api/analyses List recent analyses (query: ?limit=20)
GET /api/analyses/<id> Get single analysis with full details
DELETE /api/analyses/<id> Delete an analysis record
GET /api/stats Aggregate statistics and grade distribution
GET /api/sample Get sample code snippet

Tech Stack

Python 3.11 Flask 3.0 SQLAlchemy 2.0 SQLite Pydantic 2.5 Chart.js CodeMirror pytest Docker GitHub Actions