vroqjs.com

03-app-structure/09-when-to-create-a-new-file.md

When to create a new file

When to create a new file

Creating new files helps keep code organized, but unnecessary files can make the project harder to navigate.

Use these rules to decide when a new file is justified.

Good reasons to create a new file

Create a new file when there is a **clear responsibility boundary**.

Examples:

  • a feature reducer
  • a feature actions file
  • a feature API client
  • a reusable component
  • a feature section extracted from a large file

If a piece of logic can be named clearly and has a focused role, it likely deserves its own file.

Signs a file should be split

Consider splitting a file when:

  • it has multiple unrelated responsibilities
  • it becomes difficult to read in one pass
  • a subsection of logic could stand alone
  • multiple developers or LLM edits frequently touch different parts

Avoid unnecessary files

Do not create new files for:

  • tiny helpers used once
  • trivial logic that makes the feature harder to follow
  • speculative abstractions

Keeping related logic close together is sometimes better than splitting too early.

Prefer feature grouping

If a file belongs clearly to a feature, place it inside the feature folder.

Example:

features/files/
  filesReducer.js
  filesActions.js
  FileListSection.js
  fileApi.js

Avoid scattering feature files across unrelated directories.

Final rule

Create a new file when it makes the code easier to understand and maintain.

If the new file would make the project harder to navigate, keep the logic where it is.