← All reports
Architecture decision report

Next.js SaaS Frontend Architecture Before Tests

Whether to first reshape the frontend architecture and boundaries or begin adding tests immediately, and which architecture/testing approach best fits a complex multi-tenant Next.js SaaS frontend.

nextjs-saas-frontend-architecture-before-tests.md
UC-012 · 2026-07-03Recommended

Scaling a large Next.js SaaS frontend: architecture before introducing tests?

I'm working on a fairly large SaaS product built with Static Next.js. The application supports multiple business configurations/tenants and consumes GraphQL APIs.

As the product has grown, the frontend has accumulated a lot of domain-specific business logic. At this point, almost every new feature or change risks introducing regressions somewhere else. Unfortunately, we currently don't have any unit tests or E2E tests in place.

My initial thought is that before investing heavily in testing, we should improve the frontend architecture and establish clearer boundaries for business logic. Otherwise, I'm concerned we'll end up writing tests around a structure that is already difficult to maintain.

A few questions for teams that have gone through this stage:

- Would you prioritize architectural improvements before introducing tests, or start adding tests immediately and refactor incrementally? - What frontend architecture patterns have worked well for large-scale Next.js applications with complex domain logic? - How do you typically separate UI, state management, API interactions, and business/domain logic? - Are there any proven approaches such as Feature-Sliced Design, Clean Architecture, DDD-inspired frontend architecture, vertical slices, etc., that have scaled well for you? - What testing strategy would you recommend for a codebase that currently has zero test coverage? - Are there any open-source Next.js repositories or large-scale frontend projects that demonstrate good architecture and testing practices?

Tech stack: Next.js, GraphQL, multi-tenant / multiple business configurations, no existing unit or E2E tests.

I'd really appreciate hearing from engineers who have scaled similar applications and what they would do if starting from this situation today.

Original question on Stack Overflow ↗

Recommendation

Adopt an incremental layered architecture with a rich domain/application boundary, and start tests immediately around the highest-risk tenant and business-rule flows.

Your regressions are coming from scattered domain logic, so you should first stop business rules from leaking into pages and GraphQL glue while adding a small, focused test suite that protects the riskiest paths.

Options compared
Incremental layered architecture plus immediate testsPick
FitStrong fit

It reduces coupling now and protects the most fragile flows without freezing delivery for a large redesign.

Big upfront architecture rewrite before testsAvoid
FitWeak fit

It delays safety while the existing code keeps changing, and the knowledge base warns against over-layering or ceremonial redesigns.

Tests first, no structural refactorViable
FitFair fit

It gives fast risk reduction, but tests will be harder to maintain if business rules keep living in pages and integration glue.

Feature-Sliced Design / vertical slicesViable
FitFair fit

Useful as an organization scheme for separating features, but it should sit on top of clear domain/application boundaries rather than replace them.

Architecture shape
Next.js pages/components feature/application services domain model and tenant policy GraphQL adapter backend APIs
Assumptions
None recorded.
Tradeoffs
Explicit layers add indirection
They make business rules easier to test and change safely.
A rich domain model improves clarity
It requires discipline and can be overkill if some flows are truly simple.
Starting tests now means you may need to revise them as boundaries improve
That is still safer than deferring coverage.
This is still provisional because
You did not specify whether tenant differences are mostly data-driven or structurally different flows.
The highest-risk user journeys are not identified, so the first tests have to be inferred.
Risks and mitigations
Over-engineering the architecture into thin pass-through layers; mitigate by only adding layers where they own real decisions.
Trying to test everything at the UI level; mitigate by using many fast unit/integration tests and only a few E2E tests.
Tenant or authorization regressions slipping through refactors; mitigate by adding explicit regression tests for cross-tenant and role-based cases.
Answer these next
01What is the defining tenant/configuration model in the product: are tenant differences mostly data-driven, rule-driven, or structurally different flows/components?
02Which parts of the frontend are the biggest sources of regression risk today: domain rules, state management, GraphQL data handling, or page/component composition?
03Which user journeys are most business-critical or most likely to break if changed?
Revisit this if
If tenant differences are mostly structural and not just rule-based, split by bounded context or feature slices more aggressively.
If GraphQL is unstable rather than a stable boundary, move more defensive logic into the application layer and add contract tests.
If the highest-risk flows are heavily browser-state driven, increase component and E2E coverage for those journeys.
Curated references
[1]Business Logic OrganizationPatterns of Enterprise Application Architecture
The main pain is scattered domain rules causing regressions, so comparing where to centralize behavior directly informs whether logic should move out of page components and GraphQL glue.
[2]Layered Application ArchitecturePatterns of Enterprise Application Architecture
The frontend mixes presentation, data access, and tenant-specific business rules, so explicit layers fit the separation the team is missing.
[3]Domain ModelDomain Model
The app’s tenant and business-configuration variants suggest the domain is rich enough that a stronger model could reduce duplicated rule handling and accidental coupling.
[4]Domain-Driven DesignDomain Driven Design
This is less a UI tweak than a complex business domain living in the frontend, which makes DDD a useful framing for boundaries and shared language.
[5]Test PyramidThe Practical Test Pyramid
With no tests in place and regressions already frequent, a layered mix of fast unit tests and a smaller number of higher-level tests scales better than relying on E2E alone.
[6]Authorization Regression TestingAuthorization Regression Testing Cheat Sheet
Original question by Dulana on Stack Overflow (2026-06-25), licensed CC BY-SA 4.0. Report generated by the Architect Buddy pipeline on 2026-07-03, reviewed and edited by a human. This is architectural guidance, not a substitute for your own judgment.