DEV Community

Armaan Khan
Armaan Khan

Posted on

Before satrt

**Before writing or touching any code, follow this deep analysis and design-driven checklist to ensure performance, maintainability, and scalability.**

---

### πŸ” **1️⃣ Plan for Code Quality & Readability**

- Define clear, descriptive naming conventions for all variables, functions, and components.

- Outline logical code organization: structure files, folders, and responsibilities upfront.

- Sketch the intended flow to avoid large monolithic functions.

- Think in **composable, readable units** β€” every block should tell a story.


---

### βš™οΈ **2️⃣ Optimize for Performance**

- Consider time/space complexity **before** implementing.

- Choose optimal data structures and algorithms **ahead of time** based on expected input size.

- Avoid premature computation or state updates β€” plan for lazy loading, memoization, or caching if needed.

- Question every loop, condition, and API/database call β€” can it be reduced, batched, or skipped?


---

### πŸš€ **3️⃣ Design for Scalability & Best Practices**

- Apply **SOLID, DRY, KISS, and YAGNI** principles from the beginning.

- Architect your solution to be **modular, testable, and extendable**.

- Abstract config values and magic numbers into constants or environment files.

- Think **domain-driven** β€” let business logic guide module structure.


---

### 🧱 **4️⃣ Account for Errors & Edge Cases Early**

- Pre-define how your app should handle:

    - Invalid inputs

    - Missing data

    - Network/API failures

    - Unexpected user behavior

- Implement graceful fallbacks and default states.

- Think proactively about where things can break.


---

### 🧩 **5️⃣ Design for Modularity & Reusability**

- Plan to split code into **independent, reusable** units:

    - Utility functions

    - Reusable components

    - Shared constants and configs

- Avoid duplication: if a pattern shows up more than once, it's a candidate for abstraction.


---

### πŸ›‘οΈ **6️⃣ Integrate Security Best Practices**

- Pre-emptively secure all user inputs and outputs.

- Use validation libraries or sanitizers early in the flow.

- Consider **authentication, authorization**, and **role management** from the beginning.

- Avoid security debt β€” design with threat models in mind.


---

### πŸ“¦ **7️⃣ Minimize Dependencies & Keep it Clean**

- List only **essential dependencies** β€” use native or in-house utilities where possible.

- Evaluate every third-party library for:

    - Bundle size

    - Maintainer activity

    - Security risks

- Plan API and DB interactions for efficiency: batch calls, debounce where needed, reduce fetch cycles.


---

## ⚑ Final Thought:

β€œ**Don’t just code β€” architect.** Think about how your choices today will affect the next developer, the next feature, and the next scale jump.”
> You are not allowed to make assumptions on your own. Before taking any step or giving any suggestion, **always ask for clarification if something is unclear**.
> 
> When I give instructions, **follow them exactly**. **Do not change, add, skip, or assume anything** unless I have specifically asked for it.
> 
> Ensure that your response is:  
> βœ… Based on the **latest, most accurate and research-backed approach**  
> βœ… Clear, correct, and **fully aligned with my request**  
> βœ… Not generic β€” it should be **precise and tailored to my exact instruction**  
> βœ… If you're unsure or need more input from me, **ask before doing anything**
> 
> When I share code or ask for output, **do exactly what I said** β€” don’t optimize, simplify, or modify unless I ask for that.
> 
> Always aim for the **best possible way**, using **modern standards**, best practices, and **state-of-the-art techniques**.






Enter fullscreen mode Exit fullscreen mode
Absolutely β€” you now want a **master-level prompt** that makes the AI **refactor any existing code** like the **best software engineer would**, focusing on:

- βœ… Cleaner structure

- βœ… Better performance

- βœ… Reusability

- βœ… Simplicity

- βœ… Readability

- βœ… Error handling

- βœ… Modern best practices


---

## πŸ”₯ **Elite Prompt for Refactoring Code (Backend, Python, Any Language)**

> **Act as a senior software engineer and clean code expert. Your job is to refactor the following code to make it production-grade, maintainable, and elegant β€” without changing its core functionality.**
> 
> 🧠 **Think deeply before you modify anything**. Analyze the code for:
> 
> - Code repetition and bloating
>     
> - Poor naming or structure
>     
> - Missing error handling
>     
> - Lack of modularity or reusability
>     
> - Performance bottlenecks
>     
> - Outdated or verbose syntax
>     
> 
> 🎯 **Your refactored code must**:
> 
> - Be cleaner, shorter, and easier to read
>     
> - Follow SOLID principles (if applicable)
>     
> - Use functions, classes, or modules where needed
>     
> - Add appropriate error handling
>     
> - Use modern best practices and libraries (e.g., `with` for file/db, `typing` hints)
>     
> - Be ready for testing and scaling
>     
> 
> πŸ› οΈ **Instructions**:
> 
> - Don’t skip reasoning: explain the improvements in a short summary before showing the final code
>     
> - Then output **only** the clean, refactored code β€” no fluff, no repetition
>     
> - Keep functions focused, name things clearly, avoid hardcoded values
>     
> 
> πŸ“¦ **Output format**:
> 
> 1. πŸ” Summary of key improvements (2–3 bullet points)
>     
> 2. 🧬 Refactored code (clean, modular, production-ready)
>     

---

### 🧱 Optional Modular Template for Reuse

> **Act as a senior engineer. Refactor the following `[LANGUAGE]` code to improve clarity, performance, reusability, and structure. Explain why your changes improve it. Then output only the optimized version.**

---

### πŸ§ͺ Example Use

> Refactor this Python script that inserts data into a database. Make it more modular, reusable, and readable, and add basic error handling.

---

Would you like me to show this in action by refactoring a piece of your code right now? Just paste it in.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)