vroqjs.com

01-house-style/06-reuse-over-rewrite.md

Reuse over rewrite

Reuse over rewrite

Vroq apps should prefer reusing and extending existing code instead of creating new competing patterns.

This rule is critical for keeping apps consistent and preventing architecture drift when ChatGPT edits code repeatedly over time.

Why reuse matters

Reusing existing helpers, components, sections, reducers, and API clients helps:

  • keep patterns consistent
  • reduce duplicate logic
  • make debugging easier
  • reduce the amount of code ChatGPT needs to understand

Introducing a second pattern for the same problem makes future edits harder.

Reuse checklist

Before writing new code, check whether an existing solution already exists:

  • existing component that can be extended
  • existing section with similar behavior
  • existing helper function
  • existing API client
  • existing reducer or action pattern

If one exists, prefer extending it.

When new code is justified

Creating new code is justified when:

  • the existing pattern clearly does not fit the problem
  • reusing the existing pattern would make the code harder to understand
  • the new behavior represents a genuinely different responsibility

Extending patterns

Instead of copying code, extend the existing pattern.

Examples:

Good:

  • add a new action to an existing feature reducer
  • add a prop to an existing component
  • extend an API client with a new method

Bad:

  • duplicating an existing reducer in a new file
  • creating another component with nearly identical behavior
  • writing a second API wrapper for the same service

Avoid pattern drift

Over time, apps become messy when multiple solutions exist for the same problem.

ChatGPT should actively prevent this by preferring the existing pattern unless it is clearly wrong.

Final rule

Prefer improving and extending the existing structure rather than adding parallel structures.