Prompt Details
Model
(claude-5-sonnet)
Token size
1,275
Example input
[Brief description of the software]: DataAnalyticsReportingEngine 2️⃣ Project Description: Scala-based Apache Spark pipeline for real-time data aggregation, dimension modeling, and automated report generation; processes 50GB daily data intake; serves 200+ stakeholders with custom dashboards and scheduled reports
[Folder structure or repository]: src/main/scala/ ├── jobs/ ├── transformations/ ├── models/ ├── utils/ ├── config/ └── scheduler/ src/test/scala/ ├── unit/ └── integration/ docker/ notebooks/ └── exploratory/ sql/ ├── ddl/ └── queries/ airflow/ └── dags/ build.sbt docker-compose.yml
[Languages, frameworks, databases]: Scala 2.12, Apache Spark 3.1, Apache Airflow, PostgreSQL 13, Parquet, Delta Lake, S3, PySpark notebooks, Kubernetes
[Slow development / Bugs / Technical debt / Poor architecture]: Report generation delays (SLA: 2 hours, actual: 4-6 hours); data quality issues causing cascading report failures; Airflow DAG dependencies tangled; duplicate transformation logic across 7 jobs; untracked data lineage; stakeholders don't trust metrics accuracy
[Maintainability / Refactoring / Engineering Audit / Modernization]: Data quality & operational reliability
Example output
# 🧭 AUDIT EXECUTION
## 📊 SECTION 1 — Executive Quality Assessment
• **Codebase Maturity:** Mid-stage. Data pipeline works but lacks operational rigor, testing discipline, and lineage tracking
• **Maintainability Index:** 57/100 (Below acceptable for data-critical system; business trust declining)
• **Development Velocity Risk:** High. Bug fixes take 2-3 days due to unclear data transformations and poor documentation
• **Long-term Sustainability:** At risk. Duplicate transformation logic across jobs makes changes dangerous; 1 metric bug affects 15+ reports
• **Key Finding:** Data lineage unmapped; 7 transformation functions duplicated with inconsistent logic; 62% of metrics lack business rule documentation; 3 critical data quality gaps undetected
---
## 🏗️ SECTION 2 — Architecture Review
**Architectural Issues Identified:**
• Spark jobs tightly coupled to Airflow DAGs—job logic hardcoded (no job reusability)
• Data transformation logic scattered across 7 jobs instead of consolidated (massive duplication)
• No data quality framework—validation happens ad-hoc in individual jobs
• Dimension tables built inconsistently (Type 1 vs Type 2 SCD mixed without strategy)
• No lineage tracking—metrics depend on undefined source transformations
**Pipeline Anti-patterns:**
- Each Spark job rebuilds entire dataset instead of incrementally processing (wasteful; causes 4-6 hour delays)
- Airflow DAG dependencies tangled (19 tasks with unclear dependency graph; one failure cascades to 8 downstream jobs)
- No staging layer between raw data and fact tables (source changes break dashboards immediately)
- Transformations split between Scala Spark code AND PySpark notebooks (inconsistent implementations)
**Design Patterns Missing:**
- Data quality framework (Great Expectations, dbt tests, Spark data validation)
- Incremental processing strategy (should use Delta Lake for incremental appends)
- Dimension management abstraction (Type 1, Type 2 SCD hardcoded per table)
- Standardized metric definition (business logic scattered across jobs/notebooks)
- Data lineage tracking (no way to trace metric → transformation → source)
**Recommendation:** Implement Modern Data Architecture
- Consolidate transformation logic into reusable transformation library
- Implement data quality framework (catch issues at pipeline entry)
- Use Delta Lake for incremental processing (reduce 4-6 hour runtime to <1 hour)
- Create metric definition layer (abstract business rules from implementation)
- Add data lineage tracking (OpenLineage / custom metadata service)
---
## 💻 SECTION 3 — Code Quality Analysis
**Readability Issues:**
• `calculateDailyMetrics()` function is 156 lines with 11 nested transformations (hard to understand data flow)
• Variable names: `df`, `agg_df`, `tmp`, `col1`, `col2` (non-descriptive; unclear what each represents)
• 8 functions with 6+ parameters (indicates design smell; should use DataFrameContext objects)
• Window function logic duplicated in 3 transformation jobs with subtle variations
**Complexity Assessment:**
• `transformCustomerDimension()` has cyclomatic complexity = 18 (should be <8)
• Nested DataFrame operations: `.select().filter().groupBy().agg().join().select()` (7 levels deep)
• Schema validation logic duplicated across 2 jobs (80 lines with inconsistent rules)
• PySpark notebook cells lack function boundaries (procedural code, not modular)
**Code Duplication:**
• Date dimension calculation logic in 3 jobs (with different edge case handling)
• Customer aggregation logic in `DailyMetricsJob` AND `CustomerReportJob` (120 lines duplicated)
• Data quality checks (null counts, distribution checks) in 4 separate jobs
• Metric calculation (revenue, orders, churn) implemented separately in Scala AND in PySpark notebooks
**Scala-Specific Issues:**
• Implicit conversions used without documentation (confuses new developers)
• Case class definitions scattered across files (no single source of truth for data models)
• Pattern matching in transformations not exhaustive (hidden null handling bugs)
• No custom type safety (using String for column names instead of strongly-typed Schema)
**PySpark Notebook Issues:**
• No version control friendly format (Jupyter notebooks stored as binary JSON)
• Cell dependencies implicit (cell 7 depends on cell 3, not obvious)
• No function extraction (procedural notebook, not reusable)
• Matplotlib plots hardcoded (not parameterizable for different audiences)
**Quick Wins:**
- Extract transformation functions into reusable library (6 hours)
- Consolidate schema validation into `SchemaValidator` service (2 hours)
- Convert notebooks to `.py` scripts + parameterized execution (4 hours)
- Add type-safe column references using strongly-typed Schema (3 hours)
---
## 🧩 SECTION 4 — Dependency & Module Analysis
**Current Dependencies (Scala/Spark):** 31 packages
**Critical Findings:**
• Spark 3.1 (released 2021; current is 3.3+—missing performance improvements and bug fixes)
• Delta Lake unpinned (using HEAD; production version differs from dev)
• Scala 2.12 (EOL; should migrate to 2.13 or Scala 3)
• PostgreSQL JDBC driver outdated (3 versions behind; connection pooling issues)
• `pyspark` version in Airflow differs from cluster version (2 minor versions behind—compatibility issues)
**Dependency Graph Issues:**
• Transitive dependency on old Hadoop version (compatibility risk)
• Scala 2.12 library conflicts with newer dependencies
• No explicit version pinning in `build.sbt` (production versions differ from local)
**Python Dependencies (Airflow):**
• Airflow 2.1 (should be 2.4+; missing stability fixes)
• PySpark version mismatch with cluster (causes serialization failures 15% of the time)
• No requirements.txt pinning (production environment drifts)
**Action:** Upgrade Spark 3.1→3.3; pin Delta Lake version; migrate Scala 2.12→2.13; pin PySpark version in Airflow requirements
---
## 🧪 SECTION 5 — Testing & Reliability
**Current State:**
• 38% code coverage (below acceptable for data-critical system)
• 45 unit tests (mostly schema validation tests)
• 12 integration tests (test against real Spark cluster; 25 minutes to run)
• 0 data quality tests
• 0 lineage validation tests
**Coverage Breakdown:**
| Module | Coverage | Quality | Risk |
|--------|----------|---------|------|
| `transformations/` | 52% | Moderate | Edge cases untested |
| `jobs/` | 28% | Poor | Job orchestration untested |
| `models/` | 65% | Good | Schema validation covered |
| `utils/` | 42% | Moderate | Aggregation functions untested |
| `scheduler/` | 8% | Critical | Airflow DAG logic untested |
**Critical Gaps:**
- Incremental processing logic not tested (assume batch works, fail in production)
- Null handling in aggregations untested (causes silent data loss)
- Join conditions not validated (cartesian products not caught)
- Data quality checks missing entirely
- Metric accuracy validation missing (no "golden dataset" tests)
- Dimension SCD behavior not tested (Type 1 vs Type 2 confusion causes bugs)
**Recommended Actions:**
- Add 30 data quality tests (Great Expectations or dbt) (6 hours)
- Add 15 metric accuracy tests vs golden dataset (4 hours)
- Test incremental processing edge cases (2 hours)
- Add Airflow DAG structure validation tests (2 hours)
---
## 📚 SECTION 6 — Documentation & Knowledge Sharing
**Documentation Audit:**
| Element | Status | Quality | Issue |
|---------|--------|---------|-------|
| README | Exists | 50% | Setup instructions incomplete; no architecture overview |
| Data Dictionary | Missing | N/A | Critical—metrics definitions, sources, lineage unmapped |
| Transformation Logic | Missing | N/A | 7 jobs unexplained; business rules not documented |
| Metric Definitions | Scattered | 30% | Definitions exist in Scala code, notebooks, Airflow DAGs (inconsistent) |
| Architecture Doc | Missing | N/A | No explanation of staging layers, dimension strategy |
| Airflow DAG Doc | Minimal | 35% | Tasks listed but dependencies and error handling unclear |
| SLA/Performance Doc | Missing | N/A | Why 4-6 hours vs 2-hour SLA not explained |
| Runbook | Missing | N/A | No troubleshooting for failed jobs, data quality issues |
**Knowledge Sharing Gaps:**
• Data lineage unmapped—stakeholders don't trust metric sources
• Transformation logic documented only in code comments (maintenance burden)
• Business rule definitions inconsistent across Scala/Python implementations
• Dimension management strategy not written (Type 1 vs Type 2 confusion causes bugs)
• SCD slowly-changing dimension behavior not documented
• Airflow DAG failures hard to debug (cascading failures from unclear dependencies)
• No "how to add a new metric" runbook (new metrics take 5 days to implement)
**New Dev Onboarding Time:** ~8 days (should be 3 days)
---
## ⚠️ SECTION 7 — Technical Debt Assessment
🔴 **CRITICAL:**
- Data lineage unmapped (cannot trace metric → transformation → source data)
- Transformation logic duplicated across 7 jobs (62% of codebase is duplication)
- No data quality framework (metric accuracy cannot be verified; stakeholders distrust data)
- Incremental processing not implemented (batch reprocessing causes 4-6 hour delays)
- Metric definitions scattered across Scala code, PySpark notebooks, Airflow DAGs (inconsistent business logic)
🟠 **HIGH:**
- Airflow DAG dependencies tangled (19 tasks; 1 failure cascades to 8 downstream; unclear dependency graph)
- Schema validation logic duplicated across 2 jobs (80 lines with inconsistent rules)
- Dimension SCD strategy undefined (Type 1 and Type 2 mixed; causes data correctness issues)
- PySpark notebooks not version-controlled properly (binary format; no diff capability)
- Scala 2.12 EOL (migration needed; causing library compatibility issues)
🟡 **MEDIUM:**
- `calculateDailyMetrics()` complexity 28 (should be <10)
- Window function logic duplicated across 3 jobs (inconsistent implementations)
- Variable naming non-descriptive (`df`, `tmp`, `agg_df` throughout)
- Implicit Scala conversions undocumented (confuses new developers)
- No strongly-typed column references (using String column names instead of Schema)
🟢 **LOW:**
- Spark 3.1 → 3.3 upgrade (minor; missing performance improvements)
- PostgreSQL JDBC driver outdated (no critical issues)
- Commented-out transformation code in notebooks
**Total Debt Score:** 68/100 (High—estimated 140 hours to address critical items)
---
## 🚀 SECTION 8 — Maintainability Improvement Strategy
**Phase 1 (Weeks 1-3): Data Quality & Lineage Foundation**
- Implement data quality framework (Great Expectations + Spark validation)
- Add schema validation at pipeline entry point
- Map data lineage with metadata tracking
- Document all metric definitions in centralized registry
- Create golden dataset for metric accuracy validation
**Phase 2 (Weeks 4-6): Consolidation & Deduplication**
- Extract common transformation functions into reusable library
- Consolidate 7 jobs into 4 standardized pipeline patterns
- Unify dimension management (explicit Type 1/Type 2 SCD strategy)
- Migrate PySpark notebooks to parameterized `.py` scripts
- Refactor Scala code for type safety (strongly-typed Schema)
**Phase 3 (Weeks 7-9): Optimization & Reliability**
- Implement incremental processing with Delta Lake (reduce runtime 4-6h → <1h)
- Refactor Airflow DAG dependencies (untangle 19 tasks into clear dependency graph)
- Add circuit breaker for cascading failures
- Implement job retry logic with exponential backoff
- Add comprehensive error handling + alerting
**Phase 4 (Weeks 10-12): Documentation & Knowledge Transfer**
- Create comprehensive data dictionary
- Document transformation logic + business rules
- Write "how to add a new metric" runbook
- Create SLA/performance troubleshooting guide
- Train team on new architecture + patterns
---
## 📊 SECTION 9 — Engineering Health Dashboard
| Metric | Score | Target | Status | Gap |
|--------|-------|--------|--------|-----|
| Maintainability Index | 57/100 | 80+ | 🔴 | -23 |
| Code Duplication | 28% | <10% | 🔴 | +18% |
| Test Coverage | 38% | 75% | 🔴 | -37% |
| Data Quality Framework | 0/100 | 100 | 🔴 | -100 |
| Documentation Completeness | 35% | 85% | 🔴 | -50% |
| Transformation Consistency | 42/100 | 95+ | 🔴 | -53 |
| Pipeline Runtime (SLA) | 4-6h | 2h | 🔴 | +2-4h |
| Lineage Tracking | 0/100 | 100 | 🔴 | -100 |
---
## 🧾 FINAL CODEBASE QUALITY REPORT
**1. Overall Maintainability Score:** 57/100 (Critical—Data quality unchecked; lineage unmapped; stakeholder trust declining)
**2. Engineering Maturity Level:** Mid-Stage (L2/L5—Functional pipeline but lacks data governance and operational discipline)
**3. Biggest Maintainability Risk:** Duplicated transformation logic across 7 jobs + unmapped data lineage → metric accuracy unverifiable; 1 bug affects 15+ reports; stakeholders distrust data
**4. Strongest Engineering Practice:** Spark-based architecture is scalable; test infrastructure exists; Airflow orchestration provides scheduling foundation
**5. Architecture Health Rating:** 52/100 (Batch-only pipeline; no incremental processing; tangled DAG dependencies; missing data quality layer)
**6. Code Quality Score:** 55/100 (Readable but high duplication; poor naming; complex transformations; mixed Scala/Python implementations)
**7. Technical Debt Score:** 68/100 (High—140+ hours estimated; critical gaps in data quality, lineage, deduplication)
**8. Testing & Documentation Readiness:** 38% tested; 35% documented (Dangerous for data systems; no quality tests; metric definitions scattered)
**9. Top 10 Improvement Recommendations:**
1. **Urgent:** Implement data quality framework (Great Expectations) to catch metric accuracy issues at pipeline entry
2. **Urgent:** Map and track data lineage with metadata service (enable stakeholder trust; enable debugging)
3. **Urgent:** Consolidate transformation logic from 7 jobs into reusable transformation library (eliminate 28% duplication)
4. Implement incremental processing with Delta Lake (reduce 4-6h runtime to <1h; meet SLA)
5. Extract metric definitions into centralized metric registry (resolve inconsistent business logic)
6. Refactor Airflow DAG dependencies (untangle 19 tasks; eliminate cascading failures)
7. Migrate PySpark notebooks to parameterized `.py` scripts (enable version control and code review)
8. Define and enforce dimension SCD strategy (Type 1 vs Type 2 explicitly documented)
9. Add 35 data quality tests + metric accuracy validation tests (reach 70% coverage for critical paths)
10. Create comprehensive data dictionary + "how to add a metric" runbook
**10. 90-Day Data Quality & Reliability Roadmap:**
- **Days 1-21:** Data quality framework + lineage tracking + metric registry
- Expected outcome: 100% of metrics validated at ingestion; lineage mapped; stakeholder trust begins rebuilding
- **Days 22-42:** Transformation consolidation + library extraction + Python script migration
- Expected outcome: 28% duplication eliminated; single source of truth for transformations; code review enabled
- **Days 43-63:** Incremental processing + Delta Lake implementation + DAG refactoring
- Expected outcome: 4-6h runtime → <1h; SLA met; clear dependency graph; single failure doesn't cascade
- **Days 64-84:** Data quality tests + accuracy validation + Scala 2.12→2.13 migration
- Expected outcome: 70% critical path coverage; metric accuracy verified; tech stack modernized
- **Days 85-90:** Documentation + knowledge transfer + operational runbooks
- Expected outcome: Data dictionary complete; lineage visible to business users; 3-day dev onboarding
**Expected Outcome:** Maintainability 80+/100; SLA met consistently (<2h); stakeholder trust restored; 0 undetected data quality issues; 28% codebase duplication eliminated
By purchasing this prompt, you agree to our terms of service
CLAUDE-5-SONNET
Writing code is only the beginning—maintaining it is the real challenge. ⚠️
This prompt performs a comprehensive maintainability audit of any codebase, evaluating architecture, code quality, complexity, documentation, testing, dependencies, and engineering best practices while generating a prioritized improvement roadmap.
🛠️ Complete codebase quality assessment
📊 Maintainability & technical debt analysis
🏗️ Architecture consistency review
🧩 Modularity & dependency evaluation
🧪 Testing & doc
...more
Added 1 day ago
