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

  • Automatic Project Type Detection: Identifies whether your code is a simple script, utility module, library, or large application
  • Adaptive Scoring: Adjusts SOLID principle weights based on project characteristics
  • Context-Aware Thresholds: Different quality expectations for different project types
  • Intelligent Recommendations: Tailored advice that prevents over-engineering simple code while demanding excellence from libraries

๐Ÿ“Š Comprehensive SOLID Analysis

  • SRP (Single Responsibility Principle): Analyzes class responsibilities and method focus
  • 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

  • Weighted Scoring: Different emphasis on principles based on project needs
  • Complexity Analysis: Evaluates project size, class count, and architectural complexity
  • 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

pip install colid-checker

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

๐Ÿง  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/
โ”œโ”€โ”€ __main__.py               # Main entry point
โ”œโ”€โ”€ solid_scorer.py           # Main smart analysis engine
โ”œโ”€โ”€ srp/                      # Single Responsibility Principle analyzer
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ core.py              # Core SRP analysis logic
โ”‚   โ”œโ”€โ”€ 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

ProjectComplexityAnalyzer

Analyzes project characteristics to determine appropriate SOLID standards:

  • Lines of code counting
  • Class and method analysis
  • Inheritance depth calculation
  • External dependency tracking

AdaptiveWeightCalculator

Calculates context-aware weights and thresholds:

  • Project type-based weight adjustment
  • Quality threshold adaptation
  • Complex project stricter requirements

ContextualRecommendationGenerator

Generates smart, targeted recommendations:

  • Project type-specific advice
  • Context-appropriate violation analysis
  • Prevents over-engineering warnings

SOLIDScorer

Enhanced scorer with adaptive capabilities:

  • Smart recommendation generation
  • Contextual summary creation
  • Weighted scoring with project awareness

๐Ÿ“ˆ 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

๐Ÿ“œ 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.0.tar.gz (50.1 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.0-py3-none-any.whl (55.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for solid_checker-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9a5401ecfd9a7514e119cbc2225441fe65812607bfe57300a1e6ed50bbc81ec2
MD5 9bdee2db3875bd31a94c6a7f193b42d9
BLAKE2b-256 dc70e8f9eb63a1e1948ad89e4e5c50ec25ca8130600a0d6fa4ae584d0d961d0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for solid_checker-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad680ab5c8c68a2e28664c08d11e04a13b6ecb82bf51c4f476d48a894b23cdf7
MD5 3e8e60fcc032c4f053b8ca0f0c9f1297
BLAKE2b-256 4816485fe88d224aef48c7a799b7b049ec407090ccf18f882028e40b21997b36

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