The Code Patterns I Use, and When I Skip Them
An app that gets slower to change every month usually has a structure problem. Either too little: everything is tangled, so one fix breaks three other things. Or too much: patterns built for large companies, so a small change touches six files.
Software has a lot of named patterns. SOLID, DRY, Clean Architecture, 12-Factor. Each one solves a real problem. Each one also has a cost: extra files, extra steps and slower changes, paid for nothing where the problem does not exist.
So I do not apply them all, everywhere. My rule of thumb: a pattern has to fix a problem I have now, or one I can see coming soon. Each pattern, in detail, is in the Technical tab.
A real case: a rule that only lived in a doc
In the job-alert app I build, each business area (billing, proposals, job alerts and so on) has one front door. Other code may only reach that area through one file. That keeps each area’s insides private, so I can change them without breaking the rest of the app.
The rule was written down. But AI tools take whichever shortcut is closest. An audit in October 2026 counted 323 shortcuts past those front doors, in 160 files. Nothing was broken yet. Each shortcut was a spot where a change in one area could quietly break another.
Now other code goes through the front doors, and a test fails on any new shortcut. The same work found 2 saves that skipped their checks. One could reset a member’s saved settings to defaults if two saves landed at once. Both are fixed.
The lesson: a structure rule only holds if something checks it. A doc is not enough when AI writes the code.
What I add at each stage
| Stage | What I add |
|---|---|
| MVP | The rules I never skip (below), one folder per business area, settings kept out of the code. Little else. |
| Before launch | A thin wrapper around payments, logins and AI, so each outside service can be swapped in one place. A separate test environment and database. |
| In production, making money | A full 12-Factor review, and wrappers on every outside service. |
In my job-alert app, the payment service is used from one file in the whole app. If the AI provider fails, a second one takes over, and no other code needs to know.
The rules I never skip
Everything above depends on the app and its stage. These do not. They are part of my 15 architecture rules, and they apply on day one:
- Check every input at the edge. Forms, API calls, AI answers, data from the database. Never trust a shape you did not check.
- Keep three shapes apart. What the database stores, what the business logic uses, and what the API sends back. A database change should not break the screen.
- Every update and delete checks ownership. The query itself confirms the row belongs to this user. Not an earlier check that could be stale.
- Read-then-write runs in a locked transaction. Two clicks at once must not create two records or spend one credit twice.
These are the ones that cost real money and real user trust when they go wrong. AI tools skip them often, which is why my PR review skill checks them on every change.
Four questions to ask your developer
- Where does the billing code live? Listen for one place, not “all over”.
- If we switch payment or email provider, how many files change? One or a few is a good answer.
- Which patterns are you skipping for now, and why? A good answer names one and the problem it would solve later.
- What stops AI from taking shortcuts past the structure? A test, not a doc.
You don’t need to know any of these pattern names. I pick the ones that fit your stage, skip the rest, and tell you in plain words what each one buys you.
The short version
The patterns are tools. Each one fixes one problem and costs extra work everywhere else. Add a pattern when its problem shows up, keep the safety rules from day one, and back every structure rule with a test, not a doc.
Which problem does your app have today: bugs that come back, slow changes, or code nobody wants to touch?
Each pattern, what it means, and when I use it or skip it.
Modular monolith
What it is. One app, one deploy, split into folders by business area. Not split by technical layer.
In my app UConquer, each area gets one folder: billing, proposals, job alerts, notifications and so on. Inside each folder, the same file names every time:
lib/modules/proposals/
proposals.queries.ts talks to the database, nothing else
proposals.model.ts the data shapes, and converting between them
proposals.rules.ts the business rules and input checks
proposals.workflow.ts ties the other three together
Other code only talks to a module through its workflow file, its front door. Pages never reach into another module’s database file. That keeps each folder’s insides private, so I can change them without breaking the rest of the app. It also means the back end could move to its own server later: each workflow function becomes one endpoint.
Browser screens can’t use the front door, because it brings database code with it. Plain values and checks both sides need, like “monthly or yearly”, live in a separate lib/shared/ folder.
A rule like this drifts if it only lives in a doc. AI takes whichever import is closest. So a test reads every import and fails on any shortcut.
This is also called feature-based or modular architecture. Same idea.
When I use it. Any app with two or more business areas. When something breaks in billing, I open one folder. When I change billing, I know proposals is not touched.
When I skip it. A small app that does one job, like a single-purpose browser extension. A flat folder is fine there until a second business area shows up.
Why not microservices? Separate services mean separate deploys, network calls between them, and data that can drift out of sync. That cost pays off with large teams. For one developer or a small team, a well-split monolith gets the same clean edges for much less.
Index files (barrel files)
What it is. One index.ts per folder that re-exports what is inside, so other code imports from the folder name instead of each file.
The trade-off. Clarity and ease of use against build and test time. An index file gives each module one public door and short, clean imports. The cost: a big index file makes builds and tests load every file it lists, even the ones the code does not use.
When I use it. It is a very common pattern, and small index files cost little. Most teams pick clarity, and so would I.
When I change it. When builds or tests get slow. Then I split the big index file, or import the file directly where it matters.
Clean Architecture and Hexagonal (ports and adapters)
What it is. The core business logic does not know which outside service it talks to. Each outside service sits behind one small file, an adapter. Swap the service, change one file.
When I use it. Only where an outside service or an important business flow is involved:
- Payments (Stripe)
- Logins (Clerk)
- AI calls (OpenAI, Claude)
- Email and job platform integrations
- Background queues
Stripe is imported in one file in the whole app. My AI module can fall back to a second provider when the first one fails, and no other code needs to know.
When I skip it. Settings pages, admin screens, plain create-read-update-delete. Adding ports and adapters to a settings form gives you four files where one would do.
Domain-Driven Design (DDD)
What it is. The code uses the same words as the business. The database models the business, not the screens.
When I use it. The light parts, always. Table names, type names and function names match what the business calls things. If the product says “proposal”, the code does not say “submission”.
When I skip it. The heavy parts: aggregates for everything, event sourcing, layers of domain objects. Those help large teams on complex domains. On a small SaaS they slow every change.
MVC (Model, View, Controller)
What it is. The classic split: data, screen, and the code that connects them.
When I skip it. I do not organize Next.js apps as MVC folders. The framework already has its own shape, and business-area folders work better.
What I keep. One idea: the controller stays thin. My routes only coordinate. They check who the user is, check the input, call the workflow, and return the result. No business rules in a route.
SOLID
What it is. Five rules for organizing code. Mostly about keeping each piece small and focused, and depending on simple contracts instead of concrete tools.
When I use it. Mostly the first rule, single responsibility. On the front end, each hook does one job, and a page hook only combines them. On the back end, each file in a module has one role.
The “depend on contracts” rule I use only at the edges, where outside services are. That is the hexagonal part above.
When I skip it. Deep class trees and an interface for every function. In TypeScript, plain functions and plain types do the job with less code.
DRY (Don’t Repeat Yourself)
What it is. Each piece of knowledge lives in one place.
When I use it. For rules and facts. One validation style for every input. One place that decides if a user can do something. One path per feature. If the rule changes, it changes once.
When I skip it. For code that only looks alike. Two screens may share layout today and change for different reasons tomorrow. Merging them early ties them together. I copy once, and pull out shared code on the third time, when the pattern is real.
KISS (Keep It Simple)
What it is. The simplest thing that works.
When I use it. Always. In practice that means fewer states, simpler workflows, and deleting special cases when the general version already covers them. Before I build a feature, I check it against the product’s current stage. If it does not serve this stage, it waits.
When it bends. Never for safety. Simple does not mean skipping the rules I never skip, on the Project manager tab.
12-Factor App
What it is. Twelve rules for running a web app: settings in environment variables, the same code in every environment, logs as a stream, and so on.
When I use it. For any deployed SaaS. Secrets never live in code. My test environment has its own database, separate from live. Live and test run the same code.
I audited UConquer against all twelve: 8 pass, 3 pass in part, and 1 cannot be checked from the code alone, because the hosting platform handles it.
When I skip it. Chasing a perfect score. The gaps left are small, like pinning the exact Node version in a config file. I fix those when they cause a real problem, not to tick a box.
More Posts
All posts
November 25, 2026
Why Your App Went Offline on Vercel's Free Plan (and How to Stay Under the Limits)
Vercel's free plan pauses every site on the account when one monthly limit runs out. What the limits mean in plain words, what uses them up, and the fixes, from a real case.
November 24, 2026
Why Your Project Starts With a Small Paid Step: Requirements and an Estimate Before the Build
A price given before the work is measured is a guess, and someone pays for it later. What a small paid first step gets you: written decisions, a cost range and a time range, and the choice to stop there.