Code organization
Structuring a codebase so people can find and change things safely.
Code organization covers folders, modules, naming and where logic lives. A predictable structure lets new people and AI agents work in the codebase quickly. Organizing by feature often scales better than organizing by technical layer.
Why it matters for a product engineer
A predictable structure lets people, and now coding agents, find the right place to change. It decides how far a change spreads, how easy the code is to test, and sometimes how the business works: which code is free and which is paid, which team owns what. Most of it is cheap to decide early and expensive to change later.
How to do it
- Group code by feature at the top level, and by technical layer inside each feature.
- Put each piece of logic in one place, and let the rest call it.
- Make the boundaries visible in folders and imports, so a wrong dependency stands out.
- Use names that match the product’s words, the same ones users and documents use.
- Write a short map of the codebase in the repository, for new people and for agents.
- Move code when the structure no longer fits. Do it in small steps, not in one big change.
Common mistakes
- A
utilsfolder that slowly holds everything. - Folders by file type only, so one feature is spread across the whole tree.
- The same rule written in several places.
- Structure decided once and never revisited.
- Boundaries that exist in a diagram but not in the imports.
Example
Papermark’s open-core business is drawn in folders. Everything under ee/ and app/(ee) is under a
commercial licence; the rest of the repository is AGPLv3. Inside ee/features are the features people
pay for: AI, billing, permissions, security, templates and workflows. Background jobs live in
lib/trigger. (Papermark in In practice)
Part of Papermark's repository, and what each folder means
app/(ee)/1 ee/features/ ai/ billing/ permissions/ security/ templates/ workflows/2 ee/stripe/utils.ts3 lib/trigger/4 lib/tinybird/5
- 1CommercialPaid pages, under the enterprise licence.
- 2Paid featuresWhat data room customers pay for, one folder each.
- 3PricesThe plan amounts, in public code.
- 4Background jobsPDF pages, videos, bulk downloads, notifications.
- 5Analytics eventsPage views per document version.
The licence line follows the folders, so anyone can see what is free and what is paid.
Observedgithub.com/mfts/papermark, 17 Nov 2026
Sources: Presentation domain data layering (Martin Fowler) ↗
In practice
Real productsResources
1- articleStart here
Presentation domain data layering ↗
Martin Fowler · 7 minThe most common way to separate concerns in an application, and why to organize by feature at the top level.