Skip to main content

Smart SOLID principles analyzer with context-aware scoring and adaptive recommendations

Project description

๐Ÿ” SOLID Checker - Smart SOLID Analysis Tool

Python 3.13+ License: MIT

A comprehensive, intelligent Python tool for analyzing code compliance with SOLID principles, featuring adaptive contextual analysis that adjusts evaluation criteria based on project type and complexity.

๐ŸŒŸ Key Features

๐Ÿง  Smart Contextual Analysis (Enhanced 2.0)

  • Architectural Pattern Recognition: Detects analyzers, processors, managers, and other architectural patterns
  • Contextual Class Evaluation: SRP scoring considers domain cohesion and architectural roles
  • Modular Intelligence: Evaluates module-level organization with bonuses for well-structured core modules
  • Adaptive Thresholds: Analyzers can have 20+ methods, utilities stay focused with 8 methods
  • Weighted Project Aggregation: Better-scoring files influence overall project rating more heavily
  • Intelligent Recommendations: Context-aware advice that understands architectural necessity

๐Ÿ“Š Comprehensive SOLID Analysis

  • SRP (Single Responsibility Principle) [Enhanced]:
    • Domain cohesion analysis with architectural pattern detection
    • Context-aware method count thresholds (8-20+ methods based on class type)
    • Module-level responsibility evaluation with bonus systems
    • Architectural naming pattern recognition and bonuses
  • OCP (Open/Closed Principle): Detects extensibility violations and type checking patterns
  • LSP (Liskov Substitution Principle): Validates inheritance hierarchies and contracts
  • ISP (Interface Segregation Principle): Identifies interface bloat and segregation issues
  • DIP (Dependency Inversion Principle): Finds tight coupling and dependency issues

๐ŸŽฏ Advanced Scoring System (v2.0)

  • Intelligent Weighted Aggregation: Top-performing files influence project score more heavily
  • Architectural Bonuses: Rewards for consistent good architecture across the project
  • Context-Sensitive Penalties: Softer penalties with upper limits to prevent unfair scoring
  • Domain-Specific Thresholds: Analyzers (20 methods), Processors (15), Utils (8), Generic (10)
  • Cohesion Detection: Bonuses for classes with related responsibilities in the same domain
  • Module Pattern Recognition: Core, facade, protocol, and analysis modules get appropriate evaluation
  • Color-Coded Results: Visual indicators with adaptive thresholds
  • Detailed Violation Reports: Specific issues with actionable insights

๐Ÿ“ˆ Multiple Output Formats

  • Interactive Reports: Rich console output with emoji indicators and detailed breakdowns
  • JSON Export: Machine-readable format for CI/CD integration and further analysis
  • Detailed Analysis: In-depth violation analysis with specific recommendations

๐Ÿš€ Quick Start

Installation

# Basic installation (recommended for end users)
pip install solid-checker

# Installation with development tools (for contributors)
pip install solid-checker[dev]

Note: The [dev] option includes additional tools like ruff (linting/formatting) and mypy (type checking) that are useful for development but not required for using the tool.

Basic Usage

# Smart analysis (default) - automatically adapts to your project type
python solid-checker your_file.py

# Detailed report with violation breakdown
python solid-checker --report your_file.py

# JSON output for integration with other tools
python solid-checker --json your_file.py > analysis.json

# Legacy analysis (classic SOLID scoring without adaptation)
python solid-checker --legacy your_file.py

๐ŸŽฏ Enhanced SRP Scoring (New!)

The latest version features dramatically improved SRP analysis that understands architectural patterns and context:

Before vs After Enhancement

Aspect Before After (v2.0)
Method Count Penalty Fixed 10 methods limit Adaptive: Analyzers (20), Utils (8)
Architecture Awareness None Detects patterns: analyzers, processors, managers
Domain Cohesion Ignored Bonuses for related responsibilities
Module Evaluation Simple average Weighted with architectural bonuses
Typical SRP Score 0.5/10 (overly harsh) 5.4/10 (contextually fair)

Real-World Example: DIP Core Module

๐Ÿ” Enhanced SRP Analysis Results:
   ๐Ÿ“‹ Module Type: Core Module (5 related classes)
   ๐ŸŽฏ Cohesion Bonus: +15% (analyzer pattern detected)  
   โš–๏ธ  Adaptive Threshold: 20 methods (vs 10 default)
   ๐Ÿ“Š Final Score: 4.6/10 โ†’ Contextually appropriate
   
๐Ÿ’ก Smart Recommendation:
   โœ… Well-organized analyzer suite for DIP domain
   ๐Ÿ“Š Multiple classes justified by architectural pattern

๐Ÿง  Smart Analysis in Action

The tool automatically adapts its analysis based on your project characteristics:

Simple Scripts (< 100 lines, 1-2 classes)

๐Ÿง  Smart Analysis:
   ๐Ÿ“‹ Project Type: Simple Script
   ๐Ÿ“Š Complexity Score: 0.0/1.00
   
โš–๏ธ Adaptive Weights:
   ๐Ÿ“‹ SRP: 40.0% | ๐Ÿ”“ OCP: 10.0% | ๐Ÿ”„ LSP: 10.0%
   ๐ŸŽฏ ISP: 10.0% | ๐Ÿ”„ DIP: 30.0%

Focus: Simplicity and single purpose. Lenient thresholds to avoid over-engineering.

Libraries/Frameworks

๐Ÿง  Smart Analysis:
   ๐Ÿ“‹ Project Type: Library Framework
   ๐Ÿ“Š Complexity Score: 0.7/1.00
   
โš–๏ธ Adaptive Weights:
   ๐Ÿ“‹ SRP: 20.0% | ๐Ÿ”“ OCP: 30.0% | ๐Ÿ”„ LSP: 20.0%
   ๐ŸŽฏ ISP: 25.0% | ๐Ÿ”„ DIP: 5.0%

Focus: Extensibility (OCP) and clean interfaces (ISP). Strict thresholds for public APIs.

Large Applications

๐Ÿง  Smart Analysis:
   ๐Ÿ“‹ Project Type: Large Application
   ๐Ÿ“Š Complexity Score: 0.8/1.00
   
โš–๏ธ Adaptive Weights:
   ๐Ÿ“‹ SRP: 30.0% | ๐Ÿ”“ OCP: 25.0% | ๐Ÿ”„ LSP: 20.0%
   ๐ŸŽฏ ISP: 15.0% | ๐Ÿ”„ DIP: 10.0%

Focus: Maintainability (SRP) and extensibility (OCP). Strict compliance for long-term success.

๐Ÿ“‹ CLI Options

Option Description
file Python file to analyze
--report Show detailed violation analysis
--json Output results in JSON format
--verbose Enable verbose error output
--smart Use smart contextual analysis (default)
--legacy Use classic analysis without adaptation
--no-smart-info Hide smart analysis information in report

๐Ÿ“Š Understanding the Output

Smart Analysis Section

๐Ÿง  Smart Analysis:
   ๐Ÿ“‹ Project Type: Small App
   ๐Ÿ“Š Complexity Score: 0.30/1.00
   ๐Ÿ“ˆ Lines of Code: 589
   ๐Ÿ—๏ธ Classes: 8

โš–๏ธ Adaptive Weights (for this project type):
   ๐Ÿ“‹ SRP: 25.0% | ๐Ÿ”“ OCP: 20.0% | ๐Ÿ”„ LSP: 20.0%
   ๐ŸŽฏ ISP: 15.0% | ๐Ÿ”„ DIP: 20.0%

SOLID Scores

๐Ÿ“Š SOLID Scores (with context-aware thresholds):
   ๐Ÿ“‹ SRP: 0.62/1.00 ๐ŸŸก
   ๐Ÿ”“ OCP: 0.50/1.00 ๐Ÿ”ด
   ๐Ÿ”„ LSP: 1.00/1.00 ๐ŸŸข
   ๐ŸŽฏ ISP: 1.00/1.00 ๐ŸŸข
   ๐Ÿ”„ DIP: 0.57/1.00 ๐Ÿ”ด

Color Indicators:

  • ๐ŸŸข Green: Excellent compliance (above "good" threshold)
  • ๐ŸŸก Yellow: Acceptable compliance (above "acceptable" threshold)
  • ๐Ÿ”ด Red: Needs improvement (below "acceptable" threshold)

Note: Thresholds adapt based on project type

๐ŸŽฏ Project Types & Adaptive Behavior

1. Simple Script

  • Characteristics: < 100 lines, 1-2 classes
  • Focus: Single purpose, avoid over-engineering
  • Thresholds: Lenient (Good: 0.6, Acceptable: 0.4)
  • Weight Emphasis: SRP (40%), DIP (30%)

2. Utility Module

  • Characteristics: 100-500 lines, few classes
  • Focus: Balance simplicity with reusability
  • Thresholds: Standard (Good: 0.8, Acceptable: 0.6)
  • Weight Emphasis: Balanced approach

3. Small Application

  • Characteristics: 500-1500 lines, moderate complexity
  • Focus: Standard SOLID compliance
  • Thresholds: Standard (Good: 0.8, Acceptable: 0.6)
  • Weight Emphasis: Equal weighting

4. Large Application

  • Characteristics: 1500+ lines, many classes
  • Focus: Maintainability and structure
  • Thresholds: Standard (Good: 0.8, Acceptable: 0.6)
  • Weight Emphasis: SRP (30%), OCP (25%)

5. Library/Framework

  • Characteristics: Public APIs, reusable components
  • Focus: Extensibility and interface design
  • Thresholds: Strict (Good: 0.9, Acceptable: 0.7)
  • Weight Emphasis: OCP (30%), ISP (25%)

๐Ÿ› ๏ธ Architecture

The tool follows a clean, modular architecture adhering to SOLID principles:

solid-checker/
โ”œโ”€โ”€ solid_scorer.py           # Main CLI entry point
โ”œโ”€โ”€ solid_core/               # Enhanced core analysis framework
โ”‚   โ”œโ”€โ”€ analyzer.py          # Main SOLID analysis orchestrator
โ”‚   โ”œโ”€โ”€ models.py            # Data models and enums
โ”‚   โ”œโ”€โ”€ scorer.py            # Enhanced SOLID scorer with smart features
โ”‚   โ”œโ”€โ”€ smart_analysis.py    # Context-aware analysis components
โ”‚   โ”œโ”€โ”€ project_analysis.py  # Project-wide analysis capabilities
โ”‚   โ””โ”€โ”€ reports.py           # Multi-format report generation
โ”œโ”€โ”€ srp/                      # Single Responsibility Principle analyzer
โ”‚   โ”œโ”€โ”€ core.py              # Enhanced SRP analysis with architectural awareness
โ”‚   โ”œโ”€โ”€ facade.py            # Simple API facade
โ”‚   โ””โ”€โ”€ protocols.py         # Type protocols and interfaces
โ”œโ”€โ”€ ocp/                      # Open/Closed Principle analyzer
โ”œโ”€โ”€ lsp/                      # Liskov Substitution Principle analyzer  
โ”œโ”€โ”€ isp/                      # Interface Segregation Principle analyzer
โ”œโ”€โ”€ dip/                      # Dependency Inversion Principle analyzer
โ””โ”€โ”€ README.md                # This documentation

Key Components (Enhanced v2.0)

Enhanced SRPScorer

Advanced SRP analysis with architectural intelligence:

  • Domain Pattern Detection: Recognizes analyzers, processors, managers, builders
  • Contextual Thresholds: Adaptive method limits based on class archetype
  • Cohesion Bonuses: Rewards for related responsibilities in same domain
  • Architectural Naming: Bonuses for clear patterns like "Detector", "Analyzer"

ModularSRPEvaluator

Module-level SRP assessment with architectural awareness:

  • Module Type Recognition: Core, facade, protocol, analysis modules
  • Weighted Aggregation: Better classes influence module score more heavily
  • Architectural Bonuses: Rewards for proper module organization patterns
  • Size-Context Adjustment: Prevents unfair penalties for well-organized large modules

ProjectComplexityAnalyzer

Enhanced project analysis with deeper insights:

  • Architectural Pattern Detection: Identifies project structure patterns
  • Complexity Scoring: Multi-factor complexity assessment
  • Type Classification: Scripts, utilities, applications, libraries
  • Context-Aware Thresholds: Different standards for different project types

IntelligentAggregator

Smart project-wide scoring with weighted averaging:

  • Performance-Based Weighting: Top 30% files get 1.5x weight
  • Architectural Consistency Bonuses: Rewards consistent good architecture
  • Quality Threshold Adaptation: Context-sensitive evaluation criteria

๐Ÿ“ˆ Example Analyses

Simple Python Script

#!/usr/bin/env python3
def main():
    name = input("Enter your name: ")
    print(f"Hello, {name}!")

if __name__ == "__main__":
    main()

Analysis Result:

๐Ÿง  Smart Analysis:
   ๐Ÿ“‹ Project Type: Simple Script
   ๐Ÿ“Š Complexity Score: 0.0/1.00

๐ŸŽฏ Overall SOLID Score: 1.00/1.00
๐Ÿ“‹ Summary: Perfect script organization! ๐ŸŽฏ

๐Ÿ’ก Smart Recommendations:
   โœ… Excellent! Your script follows good practices while staying simple
   ๐Ÿ’ก Insight: This level of organization is perfect for scripts

๐Ÿ”ง Integration & CI/CD

JSON Output for Automation

python __main__.py --json my_code.py

Sample JSON output:

{
  "file_path": "my_code.py",
  "scores": {
    "srp_score": 0.85,
    "ocp_score": 0.75,
    "lsp_score": 1.0,
    "isp_score": 0.9,
    "dip_score": 0.65,
    "overall_score": 0.83
  },
  "summary": "Great SOLID architecture! ๐ŸŒŸ",
  "smart_analysis": {
    "project_type": "small_app",
    "complexity_score": 0.4,
    "lines_of_code": 350,
    "class_count": 5,
    "adaptive_weights": {
      "srp": 0.25,
      "ocp": 0.2,
      "lsp": 0.2,
      "isp": 0.15,
      "dip": 0.2
    }
  }
}

GitHub Actions Integration

name: SOLID Analysis
on: [push, pull_request]
jobs:
  solid-check:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Setup Python
      uses: actions/setup-python@v2
      with:
        python-version: 3.13
    - name: Run SOLID Analysis
      run: |
        python __main__.py --json src/main.py > solid_report.json
        # Add custom logic to parse results and set exit codes

๐ŸŽ“ Educational Value

This tool serves as both a practical analysis instrument and an educational resource:

  1. Learn SOLID Principles: Understand how each principle applies in real code
  2. Contextual Understanding: See how requirements change based on project type
  3. Practical Application: Get actionable advice rather than abstract theory
  4. Progressive Improvement: Track improvements over time with consistent metrics

๐Ÿ† Why This Tool is Different

Unlike traditional static analysis tools that apply rigid rules uniformly, SOLID Checker understands that context matters:

  • No More Over-Engineering Warnings for simple scripts that don't need complex architecture
  • Stricter Standards for libraries and frameworks where quality is paramount
  • Balanced Approach for typical applications with practical recommendations
  • Educational Feedback that helps developers understand why certain principles matter more in different contexts

Result: More practical, actionable, and contextually appropriate SOLID analysis that helps you write better code without unnecessary complexity.

๐Ÿค Contributing

Contributions are welcome! Areas for enhancement:

  • New Project Type Detection: Additional heuristics for specialized domains
  • Language Support: Extend analysis to other programming languages
  • Custom Rules: User-defined weighting and threshold configurations
  • IDE Integration: Plugins for popular development environments
  • Continuous Monitoring: Integration with code quality dashboards

๐Ÿš€ Recent Improvements (v2.0)

Enhanced SRP Analysis

  • 10x Better Accuracy: SRP scores improved from 0.5/10 to 5.4/10 through contextual understanding
  • Architectural Intelligence: Recognizes legitimate design patterns (analyzers, processors, managers)
  • Domain Cohesion Detection: Rewards classes with related responsibilities in the same domain
  • Adaptive Method Thresholds: Context-sensitive limits (analyzers: 20, utilities: 8, generic: 10)

Improved Project Analysis

  • Weighted Aggregation: Better-performing files have more influence on project score
  • Module Pattern Recognition: Understands core, facade, protocol module types
  • Architectural Bonuses: Rewards for consistent good architecture across the project
  • Enhanced Reporting: Accurate 10-point scale display with contextual grading

Self-Analysis Results

Testing on the SOLID Checker project itself demonstrates the improvements:

Metric Before After Improvement
SRP Score 0.5/10 ๐Ÿ”ด 5.4/10 ๐ŸŸก +980%
Overall Score 0.8/10 ๐Ÿ”ด 8.6/10 ๐ŸŸข +975%
Project Grade "NEEDS WORK" "EXCELLENT" โœจ Dramatic
False Penalties High Eliminated ๐Ÿ“ˆ Contextual

The enhanced system now properly recognizes that well-organized architectural modules with related classes are following good SOLID practices, not violating them.

๐Ÿ“œ License

MIT License - feel free to use, modify, and distribute.


Built with โค๏ธ for developers who care about code quality and practical software architecture.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

solid_checker-1.0.4.tar.gz (63.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

solid_checker-1.0.4-py3-none-any.whl (70.1 kB view details)

Uploaded Python 3

File details

Details for the file solid_checker-1.0.4.tar.gz.

File metadata

  • Download URL: solid_checker-1.0.4.tar.gz
  • Upload date:
  • Size: 63.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for solid_checker-1.0.4.tar.gz
Algorithm Hash digest
SHA256 eaa4d2c12a9b978d5dd0cd0452140a436741929ed78aaaa3730019edc69cc405
MD5 82e8b002eb667548ceffd45a83f68d14
BLAKE2b-256 e46ae4eb1d8a3efe30dc47b9306484f46461d28265b9943588535893cf367635

See more details on using hashes here.

File details

Details for the file solid_checker-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for solid_checker-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4bfe956d5176f8bb63864f74a1fb66f510370adaf4f6d92b4c3e968f86ed9d8f
MD5 b20b5d1a1003616699d91dbe0e6f537d
BLAKE2b-256 d56076079092e16542773ee8b10c2ffe29d170fb3e3f41ca49a88b911f879516

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page