PromptBase
Upgrade
Close icon
General
Home
Marketplace
Create
Hire
Login
Chat
Sell
Explore

Prompt Details

Model
(gemini-3.1-pro)
Token size
432
Example input
[CONTEXT]: Internal reporting tool [GOAL]: Improve maintainability [STACK]: Python [STATE]: Duplicated logic and messy scripts [EXTRA]: “Incremental only.”
Example output
# **Refactoring Strategy: Internal Reporting Tool (Python)** ## **1\. Refactoring Context Summary** The target is an internal reporting tool built with Python. The current implementation suffers from "Script Fatigue"—a state where multiple, independent scripts contain highly duplicated logic (e.g., database connections, data formatting, and CSV exports). This redundancy makes updates risky and time-consuming, as a single change in business logic or data schema requires manual updates across several files. ## **2\. Core Refactoring Goal Clarification** **Primary Goal:** Improve maintainability by centralizing core logic and standardizing script structure. **Success Metric:** Reducing the "Change Surface Area"—the number of files that must be edited to implement a common feature or fix a bug—while ensuring 100% uptime for internal stakeholders. ## **3\. Refactoring Priorities** ### **A. Extract Shared Utilities (The "Utils" Migration)** * **Why it matters:** Currently, every script likely re-implements boilerplate like DB connection strings or logging configurations. * **Expected benefit:** Single point of failure/fix for infrastructure code. * **Risk level:** Low. * **Suggested effort level:** Small (Quick Win). ### **B. Standardize Data Transformation Logic** * **Why it matters:** Reporting often involves similar calculations (e.g., date ranges, currency conversion) copied across scripts. * **Expected benefit:** Consistency in report data; if a calculation logic changes, it updates everywhere. * **Risk level:** Medium (Requires validation of math/logic). * **Suggested effort level:** Medium. ### **C. Implementation of a Base "Report" Class** * **Why it matters:** The scripts likely follow a similar pattern: Fetch \-\> Transform \-\> Output. An abstract or base class can enforce this lifecycle. * **Expected benefit:** Dramatically reduces the lines of code in individual report files, making them easier to read. * **Risk level:** Medium. * **Suggested effort level:** Medium. ### **D. Parameterization and Configuration** * **Why it matters:** Values are likely hardcoded. Moving these to environment variables or config files decouples the code from the environment. * **Expected benefit:** Ability to run reports against different environments (Dev vs. Prod) without code changes. * **Risk level:** Low. * **Suggested effort level:** Small. ## **4\. Code Quality / Architecture Concerns** * **Tight Coupling:** The reporting logic is likely tied directly to specific database drivers. Introducing a simple Data Access Layer (DAL) would prevent a total breakdown if the database engine changes. * **Silent Failures:** Messy scripts often lack robust error handling. If one part of the script fails, it might output a partial (incorrect) report. ## **5\. Simplicity vs. Stability Trade-Offs** * **The "Over-Engineering" Trap:** We must avoid building a complex "Reporting Framework" that requires a PhD to use. We will favor simple Python modules and functions over complex inheritance hierarchies. * **Stability vs. Speed:** We will prioritize "Stability." Since this is an incremental refactor, we will keep old scripts running alongside new ones until the new versions are verified. ## **6\. Incremental Refactoring Plan** 1. **Phase 1 (Week 1):** Create a core/ directory. Move database connection and logging logic into core/db.py and core/logger.py. 2. **Phase 2 (Week 2):** Identify the most "duplicated" report. Refactor only that one to use the new core modules. 3. **Phase 3 (Week 3):** Extract shared business logic into a core/logic.py module. 4. **Phase 4 (Ongoing):** As new report requests come in, build them using the new architecture. Refactor old scripts only when they require a feature update. ## **7\. Testing, Validation, and Safety Considerations** * **Golden Master Testing:** Before refactoring a script, run the original and save the output (CSV/JSON/PDF). After refactoring, run the new version and use a diff tool to ensure the data is identical. * **Dry Runs:** Implement a \--dry-run flag that logs what the script *would* do without writing to the database or sending emails. ## **8\. Common Refactoring Pitfalls to Avoid** * **The "Big Bang" Migration:** Do not try to refactor all 20 scripts at once. You will break the tool for everyone. * **Improving Logic and Refactoring Simultaneously:** Do not try to "fix" a calculation bug while refactoring the code structure. Fix the bug first, then move the code. * **Ignoring the End User:** Ensure that the file names or output paths don't change unexpectedly, which might break downstream automations. ## **9\. Recommended Next-Step Path** 1. **Inventory:** List all current scripts and highlight the 5 most frequently used. 2. **First Extraction:** Create shared\_utils.py and move the single most duplicated function (likely the DB connection) into it. 3. **The Pilot:** Update the most critical report to import this shared function and verify its output.
♊️ Gemini

Code Refactoring Strategy Pro

Add to Cart
PromptBase Select
Get this prompt + 9 more with Select$14 first month, then $19/mo · Cancel anytime$14 first month · then $19/mo
View Select
Instant accessInstant access
Usage rightsCommercial use
Money-back guaranteeMoney‑back
By purchasing this prompt, you agree to our terms of service
GEMINI-3.1-PRO
Tested icon
Guide icon
4 examples icon
Free credits icon
Generate a structured code refactoring strategy with Gemini. Input high-level codebase context to receive a practical refactoring plan that identifies priorities, risks, cleanup paths, and sequencing options—without forcing full rewrites, overengineering, or language-specific assumptions unless provided. Built for clarity, maintainability, and realistic technical improvement.
...more
Added over 1 month ago
Report
Browse Marketplace