Application Layers and Separation of Concerns

Follow one request through the screen, the permission check, the business rules, and storage, then pull out one rule without adding services you don't need.

Content date: October 15, 2026.

Plain English

Layers keep apart jobs that change for different reasons. In a club sign-up app, the presentation layer is the form people see. Application logic runs one whole task, like "cancel my spot." Business rules decide what is allowed, like "no cancellations within 24 hours of the event." Storage code reads and writes the database. All of these can live in one app on one server. A folder named services doesn't create a boundary by itself.

Use this when

Do this once one feature works and its rules are getting hard to find. First understand where code runs and where trust changes; see "Frontend vs Backend" and "API Layers and Middleware."

If you are just starting

Trace one request and label each chunk of code by its job before moving anything. Keep it one app, split into modules (files with one job and a short list of what they offer). Pull a rule out only when you can name it and test it alone. Don't build a separate network service just to match a diagram.

When your project grows

Make clear which part depends on which, and who owns each. Keep UI frameworks and database details out of the business rules. Test the real connections as well as the isolated rules. Split into separate deployments only for a real operations or ownership need, because each split adds network failures and coordination work.

Worked example

The cancel-my-spot route parses the request, confirms the student owns the spot, applies a 24-hour cutoff, and updates the database. The cutoff becomes a small function that takes the event time and current time, with its own tests. The route still verifies the caller and does the update. The rule is easy to find and test, and no new service was needed.

Practice

Trace and separate one request

  1. Pick one working request and record what it does on success and on each failure.
  2. Draw its calls and label each as screen, permission check, business decision, or storage.
  3. Move one responsibility into its own module with clear inputs and outputs, keeping permission checks on the request path.
  4. Rerun the original cases and compare before and after.

Deliverable: A before and after request map, a small diff for the extraction, and results showing the behavior matches.

Common mistakes to watch for

  • Code moves into five new folders, but the files still import each other in circles, so nothing is easier to change.
  • The 24-hour rule is copied into the form and the server, only one is updated, and the screen offers a cancellation the server refuses.
  • The ownership check is left behind when code leaves the route, and anyone can cancel anyone's spot.
  • A five-person club app is split into three services, and one failed network call can lose a sign-up.

Prompting

A weak prompt

Convert this small app to microservices and add every architecture layer.

A better prompt

Trace one workflow in this app, [for example, cancelling a club spot], from the screen through request checks and business rules to storage. Point out where one function mixes jobs. Propose the smallest useful module boundary, keep permission checks on the request path, and keep behavior the same. Test the rule alone and the whole request.

Splitting code to fit a diagram creates work with no payoff. Splitting for a specific change or test you need makes that change cheaper.

Check before you move on

  • You traced a real request from screen to storage.
  • The new boundary solves a problem you can state in a sentence.
  • Each module's dependencies show in its imports.
  • Permission checks still run on every request.
  • You retested the whole request, not just the rule.

You are done when

  • You can find and change a business rule without reading unrelated screen or database code.
  • Every allowed and refused case that passed before still passes.

Questions to think about

A developer says a presentation layer and a business layer mean two separate servers. Right?

No. Modules inside one app can keep layers apart with no network between them. Separate deployments are a different decision with their own costs.

The unit test for the cancellation cutoff passes. Is the cancel route verified?

Not yet. The route also depends on identity, ownership, storage, and error handling, so test the whole request too.

A teammate wants to move a rule into a new file. What makes that worth it?

The rule has one clear job and explicit inputs, and the move makes a real task easier, like changing or testing the cutoff.

Official references