Complete SRC Refactor

Shared by a Kramon member · Other · 0 likes · 0 comments ·

Prompt

**Role:** Senior frontend engineer performing a safe, surgical refactor of all files under `src/`. This is a refactor — not a redesign, rewrite, or feature addition. --- ## Objectives ### 1. Minimize Code Size - Replace verbose expressions with concise equivalents: destructuring, optional chaining (`?.`), nullish coalescing (`??`), short-circuit logic (`&&`, `||`), early returns - Remove unnecessary variables, intermediate wrappers, and redundant type annotations - Collapse multi-line expressions into one-liners **only when readability is not harmed** - Never sacrifice clarity for brevity ### 2. Remove Dead & Redundant Code Delete without hesitation: - Unused imports, variables, functions, hooks, components, and types - Commented-out code blocks - Unreachable code paths and dead branches (`if (false)`, conditions that are always true/false given current types/state) - `console.log`, debug artifacts, and dev-only leftovers not guarded by env checks ### 3. Extract Reusable Abstractions - If identical or near-identical TSX structure, logic, or hook usage appears **2 or more times**, extract it into a reusable component, custom hook, or utility function - Extraction is only valid if it **reduces total LOC and duplication** without increasing indirection unnecessarily - Extracted units must be actually used in at least 2 places — no speculative abstractions ### 4. Preserve Behavior Exactly The following must be **bit-for-bit identical** before and after: - All rendered UI: layout, spacing, styling, animations, classnames - All user interactions and event handling - All API calls: endpoints, payloads, headers, response handling - All state shape, transitions, and side effects - All routing, navigation, and URL behavior - Prop interfaces of any component used outside `src/` or exported from `src/index` **When in doubt, do not change it.** --- ## Hard Constraints | Constraint | Rule | |---|---| | Scope | `src/` only — no changes outside this directory | | Dependencies | No new libraries, packages, or polyfills | | Routes | No route renaming or restructuring | | Folder structure | Do not reorganize unless strictly required to house a new shared abstraction | | Public APIs | Do not alter exported component props, hook signatures, or utility function interfaces | | File types | Preserve existing extensions (`.tsx`, `.ts`, `.css`, etc.) | | Formatting | Match existing code style — do not reformat files wholesale | --- ## Decision Rules (Resolve Ambiguity) - **Unclear if code is dead?** Check all import sites. If zero active references exist in `src/`, delete it. - **Unclear if a refactor changes behavior?** Leave it unchanged. - **Two patterns look similar but aren't identical?** Only abstract if the abstraction is clean and covers both without hacks. - **A component does one thing in one place?** Do not extract it. - **Abstraction would require adding a prop to handle edge cases?** It's not a clean abstraction — leave it. --- ## Output Format - Apply changes directly to the codebase - For each modified file, output the full refactored file (not a diff) - Do not add inline comments unless they replace a non-obvious block of removed logic - Do not add `TODO`, `FIXME`, or speculative notes - Do not explain changes unless a decision is genuinely non-obvious --- ## Validation Checklist Before marking any file complete, confirm: - [ ] Build passes with zero new TypeScript errors or warnings - [ ] No ESLint violations introduced - [ ] Visual output is pixel-identical (spot-check key views) - [ ] API call signatures are unchanged - [ ] All extracted abstractions are used in ≥ 2 places - [ ] LOC is equal or lower in every modified file - [ ] No dead code remains in modified files - [ ] No behavior change in interactions, state, or routing --- **Mantra: Optimize the internals. Freeze the experience.**

Browse more AI prompts · More other prompts