Skip to main content
CodeDNA Logo

๐Ÿงฌ CodeDNA

Software Intelligence System โ€” A Genetic Analyzer for Code

Reverse-engineer any codebase into a DNA profile. Track genetic drift across releases, enforce architectural quality gates in CI/CD, and visualize system evolution.

PyPI version CI Python 3.11+ Version License: MIT


๐Ÿ“‘ Table of Contents


โœจ What is CodeDNA?

CodeDNA reverse-engineers any codebase and generates a comprehensive "DNA profile". It acts as an automated software architect, traversing tens of thousands of lines of code to distill exactly what a system does, how it is structured, where technical debt hides, and how it is mutating over time.

Dimension What It Reveals
๐Ÿ—๏ธ Architecture Pattern Monolith, MVC, Layered, Microservices, Plugin, Event-Driven
๐Ÿ“Š Language Distribution Files, lines, and percentage share per language (50+ languages supported)
๐Ÿ”— Dependency Graph Module topology, coupling density, circular dependency cycle detection
๐Ÿ› Code Smells & Hygiene God classes, runaway file length, bloated functions, Spaghetti Hub coupling
๐Ÿ”’ Security Posture Hardcoded secrets, AI API keys (OpenAI, Anthropic, HF), command & SQL injection
๐Ÿ‘ฅ Developer Genome Active contributors, bus factor risk, primary architects, collaboration
๐Ÿ“ˆ Evolution Timeline Commit growth velocity, churn hotspots, architecture shifts
๐Ÿงฌ Genetic Drift Similarity scoring and mutation delta between branches, commits, or forks

๐Ÿš€ Flagship Capabilities

1. โš™๏ธ Declarative Configuration (codedna.toml)

Configure CodeDNA directly within your repository using codedna.toml or pyproject.toml [tool.codedna]:

  • Path Exclusion Globs: Cleanly ignore test suites, build outputs, and minified bundles across all analyzers.
  • Secret Whitelisting: Suppress false positives for intentional test fixtures or mock keys.
  • Custom Smell Thresholds: Tailor file length, function lines, and method count thresholds to your project's standards.
  • Gate Policies: Specify default CI quality constraints without repeating CLI flags.
# codedna.toml
ignore_paths = ["tests/*", "docs/*", "build/*"]
whitelisted_secrets = ["PUBLIC_KEY", "MOCK_TOKEN"]

[gate]
min_health = "Fair"
max_critical_smells = 0
fail_on_secrets = true
fail_on_circular = false
max_drift = 20.0

[smells]
max_file_lines = 650
max_function_lines = 120
god_class_methods = 20

2. ๐Ÿ›ก๏ธ Architectural Drift Regression Gating (gate)

Block pull requests that introduce architectural regressions or degrade code quality:

  • Baseline vs. Target: Compare incoming PR branches against origin/main or pre-computed baseline JSON profiles.
  • Zero-Regression Policies: Fails immediately if codebase health degrades (e.g., Healthy โž” Critical), circular dependencies are introduced, or genetic drift exceeds allowable tolerance.
  • Exit Codes: Exits with 0 on clean gates, 1 on regression breach.
# Evaluate drift between main branch and current working tree
codedna gate origin/main .

# Evaluate drift between two DNA profiles with custom similarity requirements
codedna gate baseline_profile.json pr_profile.json --min-similarity 85.0

3. ๐Ÿงฌ Genetic Drift & Architecture Diff Engine (diff)

Compare two repositories, branches, or pre-generated DNA profiles to measure architectural drift and genetic similarity (0.0% to 100.0%):

  • Similarity Scoring: Multi-vector composite evaluation across language distributions, structural size, architectural patterns, dependency graph density, and health ratings.
  • Structural Deltas: Track added/removed modules, file volume shifts, and language composition changes.
  • Coupling & Cycle Shifts: Instant alerts if circular dependencies were introduced or resolved.
  • Inline Gating: Pass --fail-on-drift to turn diff into a regression gatekeeper.
# Compare two local repositories
codedna diff ./repo-main ./repo-refactor

# Compare two saved DNA profile snapshots with inline drift gating
codedna diff reports/profile_v1.json reports/profile_v2.json --fail-on-drift

4. ๐Ÿ›ก๏ธ CI/CD Quality Gatekeeper & SARIF / PR Markdown (check)

Enforce architectural rules and security standards directly in your build and PR validation pipelines:

  • Policy Gates: Reject PRs that breach health ratings, introduce hardcoded secrets, or exceed smell thresholds.
  • Native SARIF v2.1.0: Generates OASIS SARIF output for GitHub Code Scanning tab annotations.
  • PR Review Markdown: Generates formatted markdown tables (--format markdown) ready to post as PR review comments.
# Validate local repo in CI
codedna check .

# Generate Markdown table for GitHub Actions PR comment
codedna check . --format markdown --output pr-comment.md

# Export SARIF for GitHub Code Scanning
codedna check . --format sarif --output codedna-results.sarif

5. ๐Ÿ”’ Enterprise Security & Shannon Entropy Scanner

Built-in zero-dependency scanning for high-risk vulnerabilities, high-entropy secrets, and cloud credentials:

  • Shannon Entropy Secret Hunter: Computes mathematical information density ($H(S) = -\sum p(c) \log_2 p(c)$) to surface unformatted API keys, hex secrets, and base64 private tokens without relying on brittle prefix guessing.
  • AI & Cloud API Tokens: Detects exposed keys for OpenAI (sk-...), Anthropic (sk-ant-...), Google Gemini (AIzaSy...), Cohere, Mistral, Perplexity, DeepSeek, Groq, Hugging Face (hf_...), Pinecone (pcsk_...), AWS, GitHub, Stripe, and Slack.
  • Database Connection URIs: Flags embedded passwords in database strings (postgres://, mysql://, mongodb://, redis://).
  • Insecure Deserialization & Injection: Catches dangerous pickle.loads(), yaml.unsafe_load(), subprocess.*(shell=True), and SQL f-strings.

6. ๐ŸŽฏ Interactive Executive Radar & HTML Dashboard

The generated HTML dashboard includes:

  • Pure SVG Radar Chart: Five-dimensional assessment (Health & Hygiene, Security Posture, Modularity & Coupling, Architecture Cohesion, Team Resilience) rendered with zero external CDN dependencies.
  • Interactive Risk Filter: Client-side instant filtering across code smells, god classes, and security warnings.
  • Print / PDF Ready: Fully styled @media print support for executive architecture reviews.

7. ๐Ÿ”Œ Model Context Protocol Gateway (mcp)

Expose CodeDNA as an official MCP (2024-11-05 Specification) JSON-RPC 2.0 server over stdio for AI coding assistants:

  • Seamlessly integrates with Claude Desktop, Cursor, Windsurf, and Antigravity.
  • Provides 7 standard tools: codedna_analyze, codedna_inspect_architecture, codedna_security_audit, codedna_complexity_metrics, codedna_dependency_graph, codedna_quality_gate, and codedna_drift_diff.
// claude_desktop_config.json
{
  "mcpServers": {
    "codedna": {
      "command": "codedna",
      "args": ["mcp"]
    }
  }
}

8. โš™๏ธ Cyclomatic & Cognitive Complexity Engine (complexity)

Comprehensive function-level structural analysis using Python AST and universal token streaming:

  • McCabe Cyclomatic Complexity ($CC$): Exact decision point counting (if, while, for, except, assert, boolean chains, comprehensions).
  • Cognitive Complexity: Standard Sonarsource nesting-penalized evaluation.
  • Maintainability Index ($MI$): Standard SEI maintainability scoring on a 0โ€“100 scale with letter grade rankings (A through F).

9. ๐Ÿ›ก๏ธ Executive Compliance Audit (audit)

Fast, terminal-native security and architectural compliance audit with colorized Rich tables and strict exit codes (0 for pass, 1 for policy breach).

10. ๐Ÿ“ฆ Software Bill of Materials Engine (sbom)

Generate industry-standard, audit-ready SBOM manifests conforming to federal and enterprise compliance mandates:

  • CycloneDX (v1.5 JSON): Complete component graphs, Package URLs (purl), and dependency relationships.
  • SPDX (v2.3 JSON): Open source package catalogs, licensing assertions, and document hashes.
  • Multi-Ecosystem Discovery: Parses Python (pyproject.toml, requirements.txt), Node.js (package.json, package-lock.json), Rust (Cargo.toml, Cargo.lock), and Go (go.mod).
# Generate CycloneDX SBOM
codedna sbom . --format cyclonedx --output sbom-cyclonedx.json

# Generate SPDX SBOM
codedna sbom . --format spdx --output sbom-spdx.json

11. ๐Ÿ”ง Intelligent Auto-Remediation Engine (fix / remediate)

Close the loop from diagnostic detection to resolution with deterministic code patches:

  • Bare Exceptions: Safely transforms broad except: to typed except Exception: handlers.
  • Secret Extraction: Refactors hardcoded API keys and tokens into os.getenv(...) variables.
  • Wildcard Resolution: Pins open-ended package.json "*" wildcards to safe semantic ranges (^1.0.0).
  • Unified Diffs & Dry-Runs: Preview patches before application or export unified patch files.
# Preview auto-remediation plan
codedna remediate . --dry-run

# Automatically patch safe findings on disk
codedna fix .

๐Ÿ—๏ธ Analysis Pipeline

CodeDNA executes a modular 10-stage analysis pipeline:

graph TD
    A[Repository / Git Input] --> B[Repo Cloner / Path Resolver]
    B --> C[Language Detector]
    C --> D[Structure Analyzer]
    D --> E[Dependency Mapper & Mermaid Graph]
    E --> F[Architecture Pattern Detector]
    F --> G[Code Smell & Hygiene Detector]
    G --> H[Security & Secret Scanner]
    H --> I[Developer & Bus Factor Analyzer]
    I --> J[Evolution & Git Churn Engine]
    J --> K[DNA Profile Synthesis]
    K --> L[Terminal Visualizer]
    K --> M[HTML Executive Dashboard]
    K --> N[CI Gatekeeper & SARIF]
    K --> O[Genetic Diff Engine]

๐Ÿ› ๏ธ Quick Start Guide

Installation

pip install codedna-analyzer

Or install via pipx or uv:

pipx install codedna-analyzer
# or
uv tool install codedna-analyzer

Verify installation:

codedna --version
# codedna, version 1.4.0

๐Ÿ’ป Comprehensive Usage

Project Scaffolding (init)

Scaffold a starter configuration file in your project:

codedna init .

Analyze a Codebase

# Analyze a public GitHub repository
codedna analyze https://github.com/user/project

# Analyze local directory and save all reports (HTML, JSON, Markdown)
codedna analyze . --output reports/

# Headless mode for automated environments
codedna analyze . --no-visualize --output reports/ --format json

Compare Codebases / Branches (diff)

# Terminal comparison
codedna diff ./release-1.0 ./release-2.0

# Generate Markdown diff report
codedna diff ./branch-a ./branch-b --format markdown --output diff-report.md

Gating Architectural Drift in CI (gate)

# Block PR if architecture degrades compared to baseline
codedna gate baseline_dna.json current_dna.json

# Fail if similarity drops below 90% or circular dependencies are added
codedna gate ./main-repo ./pr-repo --min-similarity 90.0

Enforce Quality Gates in CI (check)

# Standard CI check
codedna check .

# Fail on circular dependencies or critical smells
codedna check . --fail-on-circular --max-critical-smells 0

GitHub Actions Integration Examples

1. GitHub Code Scanning (SARIF)

name: Architecture & Security Gate
on: [pull_request]

jobs:
  codedna-gate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 100

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'

      - name: Install CodeDNA
        run: pip install codedna

      - name: Run CodeDNA Gatekeeper & SARIF Export
        run: codedna check . --format sarif --output codedna.sarif

      - name: Upload SARIF to GitHub Code Scanning
        if: always()
        uses: github/codeql-action/upload-sarif@v3
        with:
          sarif_file: codedna.sarif

2. Automated PR Review Comment

      - name: Generate PR Quality Table
        run: codedna check . --format markdown --output pr-summary.md

      - name: Comment PR
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const body = fs.readFileSync('pr-summary.md', 'utf8');
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: body
            });

๐Ÿงฌ Example Output

Genetic Drift & Mutation Diff

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ ๐Ÿงฌ Architecture Diff โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                                                                             โ”‚
โ”‚  ๐Ÿงฌ CodeDNA Genetic Drift & Mutation Diff                                   โ”‚
โ”‚  Baseline (A): ./v1.1.0                                                     โ”‚
โ”‚  Target   (B): ./v1.2.0                                                     โ”‚
โ”‚                                                                             โ”‚
โ”‚  Genetic Similarity: 96.5% โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘                             โ”‚
โ”‚  Mutation Verdict:   Quality & Hygiene Improvement                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

                      ๐Ÿ“Š Architectural & Structural Drift                      
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Dimension        โ”‚ Baseline (A) โ”‚ Target (B)   โ”‚ Drift / Delta              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Architecture     โ”‚ Monolith     โ”‚ Monolith     โ”‚ Unchanged                  โ”‚
โ”‚ Health Score     โ”‚ Fair         โ”‚ Healthy      โ”‚ Improved (crit: 0, warn: 0)โ”‚
โ”‚ Files Count      โ”‚ -            โ”‚ -            โ”‚ +6 files                   โ”‚
โ”‚ Circular Deps    โ”‚ None โœ…      โ”‚ None โœ…      โ”‚ Clean                      โ”‚
โ”‚ Bus Factor       โ”‚ -            โ”‚ -            โ”‚ +1                         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿค Contributing

  • ๐Ÿ› Bug reports & ideas: Open an issue on GitHub.
  • ๐Ÿš€ Feature additions: PRs welcome! Ensure all tests pass with pytest and code matches ruff check.

Software has DNA too. Decode it with CodeDNA.

Metadata

Release files for codedna-analyzer 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for codedna-analyzer 1.4.0
File Size Uploaded Provenance Actions
codedna_analyzer-1.4.0.tar.gz 112.9 kB Without provenance Details for codedna_analyzer-1.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for codedna-analyzer 1.4.0
File Interpreter ABI Platform Actions
codedna_analyzer-1.4.0-py3-none-any.whl Python 3 none any Details for codedna_analyzer-1.4.0-py3-none-any.whl

Total release size: 199.4 kB

Release files / codedna_analyzer-1.4.0.tar.gz

Download URL codedna_analyzer-1.4.0.tar.gz
Size 112.9 kB
Tags Source
SHA-256 checksum
How to use checksums
165f04be12c159219ddea67e161023280da4d0887bc5d85ddd6af4fe8ccdd5c8
BLAKE2b-256 checksum
How to use checksums
3171adc546066d9ee3d9cc7d4276c64cfb764ba60a18c1840b59683a68449ae2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.0

Release files / codedna_analyzer-1.4.0-py3-none-any.whl

Download URL codedna_analyzer-1.4.0-py3-none-any.whl
Size 86.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09d266e6d2a4925a0ad8c6b6fab788624f2ec344b7b206ea4cdbd64451ae3213
BLAKE2b-256 checksum
How to use checksums
5ee0b2cb6a2457098ac94092f6d55413a099bf5f729478fe621c12834ff88374
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.0

Security for codedna-analyzer 1.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page