QDP

QDP

QDP quality

QDP

Definition

QDP (Quality Debt Points) is the Prismatic Platform's quantitative metric for tracking code quality debt. Each quality violation -- a missing typespec, an unsafe map access, a length() > 0 anti-pattern, a missing @impl annotation, a compilation warning, a Credo violation -- counts as one or more QDP depending on severity. The metric provides a single numeric score representing the total accumulated quality debt in the codebase, making quality debt visible, measurable, and actionable. Unlike vague qualitative assessments ("the code needs some cleanup"), QDP provides a precise, reproducible number that can be tracked over time, compared across sessions, and used as a gate condition for continuous integration pipelines.

QDP is modeled after financial technical debt: each violation represents a "loan" taken from code quality that must eventually be "repaid." Unlike financial debt, quality debt compounds silently and non-linearly -- a missing typespec today means a type error tomorrow, a missing @impl annotation means a callback regression next week, an unsafe map access means a production crash next month. The compounding nature means that 100 QDP is not merely twice as bad as 50 QDP; the interaction effects between violations create emergent failure modes that are worse than the sum of individual issues. A missing typespec on a function that uses unsafe map access creates a double-blind spot where neither static analysis nor runtime safety can protect against errors. QDP quantifies this accumulated risk as a single number, enabling data-driven quality management, trend analysis, and enforcement.

The Prismatic Platform's current QDP count is 0, representing complete elimination of all tracked quality debt categories across all 115 umbrella applications and approximately 2.8 million lines of code. This achievement was accomplished through the systematic application of CASCADE patterns, which eliminated 905 QDP in a structured, measurable campaign spanning four phases. The zero-QDP state is now enforced through pre-commit hooks, CI/CD gates, and the Quality Floor Guardian -- making it structurally impossible to introduce new quality debt without explicit acknowledgment and immediate remediation.

QDP Scoring Methodology

Each quality domain contributes QDP according to violation severity and potential impact on production reliability:

SeverityQDP per ViolationExamplesRationale
Critical (P0)5 QDPUnsafe map access in production path, memory leak pattern, missing error handling on external callsCan cause production crashes or data loss
High (P1)3 QDPMissing typespec on public function, compilation warning, missing regression testBlocks static analysis or hides defects
Medium (P2)2 QDPMissing @impl annotation, Credo complexity violation, DateTime precision issueReduces maintainability or correctness
Low (P3)1 QDPStyle violation, minor Credo issue, TODO without context, guard function missingReduces readability or creates minor risk

The scoring is additive within a domain but multiplicative across related domains. When a function has both a missing typespec (3 QDP) and unsafe map access (5 QDP), the effective debt is higher than 8 QDP because Dialyzer cannot protect the unsafe access without the typespec. This interaction effect is captured through the Quality Floor Guardian's composite scoring algorithm.

Quality Domains (All at 0 Violations)

The 13 quality domains tracked by QDP cover the complete spectrum of code quality, from type safety through runtime behavior to documentation:

DomainWhat It TracksDetection MethodQDP ImpactViolations
DialyzerType system violationsStatic analysis (Dialyzer PLT)Critical/High0
CredoCode style and complexityCredo analyzer (--strict)Medium/Low0
CompilationCompiler warnings--warnings-as-errorsHigh0
DateTime PrecisionIncorrect time handlingPattern detectionMedium0
Guard FunctionsMissing or incorrect guardsAST analysisMedium0
@impl CoverageMissing implementation annotationsModule analysis (709 checked)Medium0
Memory SafetyPotential memory leaksPattern detectionCritical0
PerformanceO(n) where O(1) is possiblePattern detection (90-250x speedup potential)High0
Regression PreventionMissing regression testsTest coverage analysisHigh0
Timing PatternsProcess.sleep anti-patternsAST pattern matchingMedium0
TODO ManagementOutstanding TODOs/FIXMEsComment scanningLow0
Typespec CoverageMissing @spec annotationsModule introspectionHigh0
Unsafe Map Accessmap.key instead of Map.getAST pattern matchingCritical0

The 905 QDP Elimination Campaign

The elimination of 905 QDP represents one of the platform's signature quality achievements. The campaign used CASCADE patterns -- systematic, category-by-category elimination with verification at each stage. Each phase targeted specific violation categories, measured progress quantitatively, and verified that fixes did not introduce regressions:

CASCADE PatternQDP EliminatedDescription
Type Mismatch~200 QDPResolved Dialyzer warnings across all apps, added missing typespecs
Dead Code~150 QDPRemoved unreachable code, unused functions, and orphaned modules
Empty Check~180 QDPReplaced length() > 0 with Enum.any?/1 and pattern matching
Timer Replacement~75 QDPReplaced Process.sleep with proper timer patterns and GenServer timeouts
Nuclear Cache~100 QDPFixed stale cache patterns in _build directory causing phantom warnings
Other Patterns~200 QDPTypespec additions, @impl annotations, guard fixes, map access safety
QDP Timeline:
905 QDP ----[CASCADE Phase 1]----> 600 QDP   (Type Mismatch + Dead Code)
600 QDP ----[CASCADE Phase 2]----> 300 QDP   (Empty Check + Timer Replacement)
300 QDP ----[CASCADE Phase 3]----> 100 QDP   (Nuclear Cache + Typespecs)
100 QDP ----[CASCADE Phase 4]---->  25 QDP   (@impl + Guards + Memory Safety)
 25 QDP ----[Final Sprint]------->   0 QDP   (COMPLETE ELIMINATION)

Each phase followed a strict protocol: identify all violations in the target category, create regression tests for the most critical ones, apply fixes, verify zero regressions, and update Quality DNA with the new baseline. The Nuclear Cache phase was particularly noteworthy -- approximately 100 QDP were phantom violations caused by stale compilation artifacts in the _build directory. The fix was the "nuclear cache" command: rm -rf _build/dev/lib/prismatic_claude/ebin && rm -rf priv/plts/dialyzer.plt, which forced a clean rebuild and revealed the true violation count.

Enforcement Infrastructure

QDP is enforced at multiple levels, creating a defense-in-depth strategy that makes quality regression effectively impossible:

Enforcement LayerMechanismTriggerBypass Allowed
Pre-commit hooks.githooks/pre-commit-quality-protection (11 phases)Every git commitNever
CI/CD pipelinemix quality.gates in GitLab CIEvery merge requestNever
Quality Floor Guardianprismatic_safety/quality_floor_guardian.exContinuous monitoringNever
Session protocolsQDP quota per Claude sessionEvery development sessionNever
Autohealmix autoheal.cycleAutomatic on regression detectionN/A (auto)
Autoevolvemix autoevolve.megaSession end protocolN/A (auto)

Quality Gate Check Implementation

defmodule Mix.Tasks.Quality.Gates do
  @moduledoc """
  Comprehensive quality gate check that validates all 13 quality domains.
  Returns non-zero exit code on any violation, blocking CI/CD pipelines.
  """

  use Mix.Task

  @spec run(list(String.t())) :: :ok | no_return()
  def run(args) do
    fast_mode = "--fast" in args

    results = [
      {:compilation, check_compilation()},
      {:dialyzer, check_dialyzer(fast_mode)},
      {:credo, check_credo()},
      {:typespecs, check_typespecs()},
      {:impl_coverage, check_impl_coverage()},
      {:memory_safety, check_memory_safety()},
      {:unsafe_map_access, check_unsafe_map_access()},
      {:timing_patterns, check_timing_patterns()},
      {:todo_management, check_todo_management()},
      {:datetime_precision, check_datetime_precision()},
      {:guard_functions, check_guard_functions()},
      {:performance, check_performance()},
      {:regression_prevention, check_regression_prevention()}
    ]

    qdp = calculate_qdp(results)

    case qdp do
      0 ->
        Mix.shell().info("QDP: 0 - all quality gates passed")
        :ok

      total ->
        Mix.shell().error("QDP: #{total} violations detected")
        report_violations(results)
        Mix.raise("Quality gates failed with #{total} QDP")
    end
  end

  defp calculate_qdp(results) do
    Enum.reduce(results, 0, fn {domain, count}, acc ->
      acc + count * severity_weight(domain)
    end)
  end

  defp severity_weight(:unsafe_map_access), do: 5
  defp severity_weight(:memory_safety), do: 5
  defp severity_weight(:dialyzer), do: 3
  defp severity_weight(:compilation), do: 3
  defp severity_weight(:typespecs), do: 3
  defp severity_weight(:regression_prevention), do: 3
  defp severity_weight(:impl_coverage), do: 2
  defp severity_weight(:credo), do: 2
  defp severity_weight(:datetime_precision), do: 2
  defp severity_weight(:guard_functions), do: 2
  defp severity_weight(:timing_patterns), do: 2
  defp severity_weight(:performance), do: 3
  defp severity_weight(:todo_management), do: 1

  defp report_violations(results) do
    results
    |> Enum.filter(fn {_domain, count} -> count > 0 end)
    |> Enum.each(fn {domain, count} ->
      Mix.shell().error("  #{domain}: #{count} violations (#{count * severity_weight(domain)} QDP)")
    end)
  end
end

Forbidden Patterns Enforcement

Beyond the 13 quality domains, the platform enforces a comprehensive set of forbidden patterns that prevent quality debt from being introduced in the first place:

defmodule Mix.Tasks.Quality.ForbiddenPatterns do
  @moduledoc """
  Scans the codebase for forbidden patterns that indicate quality debt,
  placeholder code, or incomplete implementations.
  """

  @forbidden_categories %{
    mocks: ~r/Mox\.defmock/,
    stubs: ~r/raise\s+"not implemented"|raise\s+:not_implemented/,
    placeholders: ~r/#\s*(PLACEHOLDER|STUB|MOCK|FIXME|HACK|WORKAROUND|XXX)/,
    naive: ~r/#\s*(naive|temporary|quick and dirty)/i,
    todos: ~r/#\s*TODO(?!\([a-zA-Z]+\))/
  }

  @spec run(list(String.t())) :: :ok | no_return()
  def run(args) do
    count_only = "--count-only" in args
    category_filter = extract_category(args)

    violations =
      scan_codebase()
      |> filter_whitelisted()
      |> filter_category(category_filter)

    total = length(violations)

    if count_only do
      Mix.shell().info("#{total}")
    else
      report_violations(violations)
    end

    if total > 0 do
      Mix.raise("#{total} forbidden patterns detected")
    end

    :ok
  end
end
CategoryScopeSeverityPatternsQDP Impact
Mockslib/BLOCKMox.defmock in production code5 QDP
Stubslib/BLOCKraise "not implemented"5 QDP
PlaceholdersallBLOCK# PLACEHOLDER, # STUB, # FIXME, # HACK3 QDP
Naivelib/BLOCK# naive, # temporary, # quick and dirty3 QDP
Localhostlib/WARN"http://localhost..." in non-config1 QDP
Test Skipstest/WARN@tag :skip without issue reference1 QDP

QDP and the NO MERCY Doctrine

QDP enforcement is a core expression of the NO MERCY, NO DOUBTS doctrine. The doctrine demands zero tolerance for quality violations, and QDP provides the quantitative enforcement mechanism:

Doctrine PrincipleQDP Expression
Zero ToleranceQDP must be 0; any non-zero QDP blocks commits
Complete ExecutionAll 13 domains checked; no partial quality assessment
Quality FirstQuality gates run before any merge is allowed
No ExcusesQDP violations must be fixed immediately, not deferred
100% Test CoverageMissing tests count as QDP in the regression prevention domain
Zero StubsPlaceholder code counts as QDP through forbidden patterns
Production-ReadyEvery commit must maintain 0 QDP state
Mandatory Regression TestsEvery bug fix must include tests that count against QDP

Quality DNA Integration

QDP state is persisted across sessions through the Quality DNA system, which stores quality metric snapshots in JSON format at .claude/quality-dna/current-state.json in each application directory:

{
  "quality_score": 100,
  "qdp_total": 0,
  "qdp_history": [
    {"session": 1, "qdp": 905, "date": "2025-11-01"},
    {"session": 15, "qdp": 600, "date": "2025-12-01"},
    {"session": 28, "qdp": 300, "date": "2025-12-15"},
    {"session": 35, "qdp": 100, "date": "2026-01-05"},
    {"session": 38, "qdp": 25, "date": "2026-01-15"},
    {"session": 42, "qdp": 0, "date": "2026-01-31"}
  ],
  "domains": {
    "dialyzer": {"violations": 0, "trend": "stable", "weight": 3},
    "credo": {"violations": 0, "trend": "stable", "weight": 2},
    "compilation": {"violations": 0, "trend": "stable", "weight": 3},
    "typespecs": {"violations": 0, "trend": "stable", "weight": 3},
    "impl_coverage": {"violations": 0, "trend": "stable", "weight": 2},
    "memory_safety": {"violations": 0, "trend": "stable", "weight": 5},
    "unsafe_map_access": {"violations": 0, "trend": "stable", "weight": 5},
    "timing_patterns": {"violations": 0, "trend": "stable", "weight": 2},
    "todo_management": {"violations": 0, "trend": "stable", "weight": 1},
    "datetime_precision": {"violations": 0, "trend": "stable", "weight": 2},
    "guard_functions": {"violations": 0, "trend": "stable", "weight": 2},
    "performance": {"violations": 0, "trend": "stable", "weight": 3},
    "regression_prevention": {"violations": 0, "trend": "stable", "weight": 3}
  },
  "last_updated": "2026-02-14T10:30:00Z",
  "session_count": 42,
  "apps_tracked": 115
}

The Quality DNA enables cross-session analysis: trend detection (is a domain degrading over sessions?), velocity tracking (how fast are QDP being eliminated?), and regression alerting (did a session introduce new QDP after a period of zero?). This historical dimension transforms QDP from a point-in-time measurement into a quality trajectory.

Quality Floor Guardian

The Quality Floor Guardian is an autonomous monitoring system that detects quality regression and triggers remediation:

defmodule PrismaticSafety.QualityFloorGuardian do
  @moduledoc """
  Autonomous quality monitoring that detects score degradation
  and triggers automatic evolution before issues impact the platform.
  Enforcement levels: OPTIMAL (100-99%), WARNING (98-99%),
  CRITICAL (95-98%), EMERGENCY (<95%).
  """

  use GenServer

  @enforcement_levels %{
    optimal: {99, 100},
    warning: {98, 99},
    critical: {95, 98},
    emergency: {0, 95}
  }

  @spec current_score() :: {:ok, non_neg_integer()} | {:error, term()}
  def current_score do
    GenServer.call(__MODULE__, :current_score)
  end

  @spec enforcement_level() :: :optimal | :warning | :critical | :emergency
  def enforcement_level do
    GenServer.call(__MODULE__, :enforcement_level)
  end
end
Score RangeLevelAction
100-99%OPTIMALMonitor only, log status
98-99%WARNINGAlert, investigate cause
95-98%CRITICALAuto-evolution trigger, block non-critical changes
< 95%EMERGENCYBlock all commits, escalate to supreme review

Comparison with Industry Approaches

ApproachScopeEnforcementGranularityZero-Tolerance
QDP (Prismatic)13 quality domains, all codePre-commit + CI + GuardianPer-violation scoring with severity weightsYes
SonarQubeCode smells, bugs, vulnerabilitiesCI integration, quality gatesIssue severity (blocker/critical/major/minor)Configurable
Code ClimateMaintainability, test coverageGitHub integrationGPA-style scoring (A-F)No
CoverallsTest coverage onlyCI integrationCoverage percentage per fileConfigurable
Technical Debt RatioEstimated time to fix all issuesAdvisory onlyTime-based estimateNo
ESLint/PrettierStyle and syntaxPre-commit hooksPer-rule severityConfigurable

QDP differs from these approaches in three fundamental ways. First, its enforcement model is not advisory -- it is a hard gate that blocks code from reaching the repository when violations exist. Second, it spans multiple analysis dimensions simultaneously (type safety, runtime behavior, documentation, performance, memory safety) rather than focusing on a single concern. Third, it integrates with autonomous remediation systems (autoheal, autoevolve) that can fix certain categories of QDP automatically without human intervention. This is the practical expression of the NO MERCY doctrine.

  • CASCADE - Systematic methodology that eliminated 905 QDP
  • Clean Run - Zero-warning compilation as a QDP enforcement mechanism
  • Autoheal - Automatic healing triggered by QDP regression
  • Autoevolve - Platform evolution driven by QDP trend analysis
  • Dialyzer - Static analysis tool detecting type-level QDP violations
  • Typespec - Type specifications whose absence contributes to QDP
  • Code Coverage - Test coverage metrics contributing to QDP assessment
  • Property-Based Testing - Testing approach that reduces QDP through exhaustive verification
  • Metrics - QDP as a quantitative metric in the observability stack
  • Trinity Gate - Verification system ensuring quality claim integrity
  • Observability - Infrastructure providing visibility into QDP trends

See Also


Connect & Contribute

Created by Tomáš Korcak (korczis) | Open Source under GHL