Vertical Slice Architecture with Dependency-Cruiser

I like vertical slices because they make a feature easier to delete, move, or review. The folder structure is not the main value. The value is that the code for one workflow is not spread across ten unrelated places.

For product work, that matters. A single user task usually crosses the UI, validation, service logic, data access, and tests. If those pieces live only in broad technical folders, a small change can feel larger than it is. You have to jump from components to schemas to services to repositories and then guess which parts belong together.

With a vertical slice, I try to keep the feature rule close to the feature.

app/features/imports/
  components/
  imports.schema.ts
  imports.service.ts
  imports.repo.ts
  imports.test.ts

This example is deliberately generic. The feature could be an import workflow, a notification setting, or a review step. The point is the boundary: most of the code that changes together is close together.

Shared code still has a place. A button, dialog primitive, date formatter, database client, or authentication helper should not be copied into every slice. But feature-specific rules should not drift into a global helper just because two files need them today.

That is the awkward part of architecture. The first version of a helper often looks harmless. Later it becomes a place where unrelated workflows share hidden behavior. At that point, changing one product flow can accidentally change another.

My rule of thumb is:

  • shared UI primitives can be shared
  • shared infrastructure can be shared
  • product decisions should stay inside the workflow until they are truly common

I also like having a tool check the boundary. A written convention is easy to forget during a busy week. dependency-cruiser can turn some of those conventions into CI feedback.

A simplified rule might say that feature code can import shared code, but shared code cannot import a feature.

{
  name: "shared-must-not-import-features",
  from: { path: "^app/shared" },
  to: { path: "^app/features" },
  severity: "error"
}

That rule is not clever. It is useful because it catches a boring mistake before it becomes normal.

The trade-off is that dependency rules can become their own maintenance burden. If the rules are too strict, engineers spend time fighting the architecture instead of improving the product. If the rules are too loose, they do not protect anything.

I do not think architecture rules should be permanent law. They should describe the shape the codebase needs right now. When the product changes, the rules may need to change too.

This approach is not always worth it. For a tiny app, strict vertical slices may be ceremony. For a library, feature folders may not match how users consume the code. But for a product app with several workflows, vertical slices make it easier to ask the practical question: “What code does this user task actually own?”

That question is more useful than arguing about folder names.

Related Posts

Astro for Documentation and a Professional Site

I use Astro because this site is mostly writing. I do not need a heavy app framework for pages that should load fast and be easy to edit. That sounds simple, but it is the mai

read more

Localization in Product Apps

Localization is not only replacing English strings with another language. In a product app, language touches workflow. It changes labels, validation messages, dates, empty states, permissions copy, d

read more

MCP as a Safe AI Integration Boundary

MCP is interesting because it makes AI integrations feel less like prompt magic and more like software boundaries. That is the part I care about. A model should no

read more

Zod, OpenAPI, and Swagger for API Contracts

A public API is not just backend code. It is a product surface for another developer. That means the contract has to be readable. It also has to be enforced at runtime. Types in the app are useful, b

read more

pg-boss for Durable Background Jobs

The customer problem was not "we need a queue". The problem was that a slow operation made the user wait with no clear answer. That distinction matters. A queue is an implementation detail. The produ

read more

Pragmatic Drag and Drop for Real Ordering Tasks

Drag and drop is easy to add for a demo and harder to make reliable for real work. The product question is not "can the item move on screen?" The question is whether the user can safely change an ord

read more

Prisma and PostgreSQL as the Product Source of Truth

I do not think of PostgreSQL as only infrastructure. In a product app, it is where the product remembers what happened. That makes database design a product decision. I

read more

React Router for Full-Stack Product Workflows

A route is not only a URL. In a product app, a route often represents a task the user is trying to finish. That sounds obvious, but it changes how I design the code. A settings page that starts an im

read more

shadcn-Style UI as an Owned Product System

I like copied UI primitives because they make the component library feel like part of the app, not something the app is borrowing. That is the part of the shadcn/ui-style ap

read more

Dense Operational UI with Tables and Editors

Sometimes a simple form is the wrong UI. If the user needs to compare many values and make careful edits, a table can be kinder than a long page of inputs. Dense UI has a bad reputation when it is us

read more

Vercel AI SDK with Explicit Tool Boundaries

The risky part of an AI feature is not the chat UI. The risky part is what the chat is allowed to do. It is easy to make an assistant feel powerful by giving it tools. With something like the [Vercel

read more

Testing Product Workflows with Vitest and Playwright

I do not want a test suite that only proves functions work. I want it to protect the workflows that would hurt if they broke. That does not mean every rule needs a browser test. Browser tests are val

read more

Zod Beyond Validation

Zod is usually introduced as a validation library. That is true, but the more useful idea is boundary definition. A TypeScript type only helps after data is already inside the pro

read more