<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: LDS Labs</title>
    <description>The latest articles on DEV Community by LDS Labs (ldslabs).</description>
    <link>https://dev.to/ldslabs</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F14440%2Fdd4f72c7-8d89-49b3-a89a-976ac5bc71c9.png</url>
      <title>DEV Community: LDS Labs</title>
      <link>https://dev.to/ldslabs</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ldslabs"/>
    <language>en</language>
    <item>
      <title>What Every Java SaaS Backend Keeps Rebuilding — and How to Structure It Once</title>
      <dc:creator>Bruno Gilberto</dc:creator>
      <pubDate>Thu, 20 Aug 2026 19:50:22 +0000</pubDate>
      <link>https://dev.to/ldslabs/what-every-java-saas-backend-keeps-rebuilding-and-how-to-structure-it-once-35hk</link>
      <guid>https://dev.to/ldslabs/what-every-java-saas-backend-keeps-rebuilding-and-how-to-structure-it-once-35hk</guid>
      <description>&lt;p&gt;Starting a new SaaS product is exciting until you realize how much work happens before you can build the feature that actually makes the product unique.&lt;/p&gt;

&lt;p&gt;For many Java and Spring Boot applications, the list looks familiar:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;authentication;&lt;/li&gt;
&lt;li&gt;refresh token handling;&lt;/li&gt;
&lt;li&gt;organizations and tenants;&lt;/li&gt;
&lt;li&gt;authorization;&lt;/li&gt;
&lt;li&gt;audit trails;&lt;/li&gt;
&lt;li&gt;database migrations;&lt;/li&gt;
&lt;li&gt;consistent API errors;&lt;/li&gt;
&lt;li&gt;API documentation;&lt;/li&gt;
&lt;li&gt;automated tests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these features is the reason the SaaS exists.&lt;/p&gt;

&lt;p&gt;But they quickly become part of its foundation.&lt;/p&gt;

&lt;p&gt;The interesting question is not whether we need them.&lt;/p&gt;

&lt;p&gt;It is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How can we structure these recurring concerns so that we don't redesign the foundation every time we start a new product?&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Authentication is more than issuing a JWT
&lt;/h2&gt;

&lt;p&gt;A basic authentication example can be surprisingly small.&lt;/p&gt;

&lt;p&gt;A production-oriented authentication design usually isn't.&lt;/p&gt;

&lt;p&gt;Once access tokens are introduced, several other decisions appear:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How are tokens signed and verified?&lt;/li&gt;
&lt;li&gt;How long should access tokens live?&lt;/li&gt;
&lt;li&gt;How are refresh tokens handled?&lt;/li&gt;
&lt;li&gt;Can refresh tokens be rotated?&lt;/li&gt;
&lt;li&gt;What happens when an old refresh token is reused?&lt;/li&gt;
&lt;li&gt;How do we revoke sessions without turning access-token validation into a database lookup?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These decisions should live inside an explicit authentication boundary rather than being scattered across controllers and business services.&lt;/p&gt;

&lt;p&gt;For example, a SaaS foundation might use asymmetric JWT signing such as RS256 for access tokens while treating refresh tokens as a separate lifecycle.&lt;/p&gt;

&lt;p&gt;The important part isn't RS256 itself.&lt;/p&gt;

&lt;p&gt;It's making authentication a well-defined subsystem.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Multi-tenancy needs an explicit context
&lt;/h2&gt;

&lt;p&gt;For many B2B SaaS applications, authentication answers:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Who is this user?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But the application also needs to answer:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In which organization is this operation happening?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That distinction becomes critical when the same user can interact with different organizations.&lt;/p&gt;

&lt;p&gt;One useful pattern is establishing a tenant or organization context near the request boundary.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP Request
    |
Authentication
    |
Organization Resolution
    |
TenantContext
    |
Authorization
    |
Application Service
    |
Persistence
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of passing an organization identifier manually through every layer, the application establishes the active context and downstream components operate within that boundary.&lt;/p&gt;

&lt;p&gt;This doesn't magically make an application tenant-safe.&lt;/p&gt;

&lt;p&gt;Queries, authorization rules, tests, and persistence boundaries still need to enforce isolation.&lt;/p&gt;

&lt;p&gt;But the context makes the tenant boundary explicit.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Roles alone eventually become limiting
&lt;/h2&gt;

&lt;p&gt;A simple application might start with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ADMIN
USER
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then requirements arrive.&lt;/p&gt;

&lt;p&gt;One user can manage billing but not members.&lt;/p&gt;

&lt;p&gt;Another can view reports but not modify settings.&lt;/p&gt;

&lt;p&gt;Someone else can manage operational data without having administrative access.&lt;/p&gt;

&lt;p&gt;If every combination becomes another role, the model quickly becomes difficult to maintain.&lt;/p&gt;

&lt;p&gt;A capability-based model gives us another level of abstraction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ROLE
  |
  +-- capability:members.read
  +-- capability:members.write
  +-- capability:billing.read
  +-- capability:settings.write
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Roles can still exist.&lt;/p&gt;

&lt;p&gt;But instead of business code asking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Is this user an ADMIN?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;it can ask:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Can this user perform this capability?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That distinction becomes increasingly valuable as a SaaS product grows.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Audit logs are different from application logs
&lt;/h2&gt;

&lt;p&gt;Application logs help engineers understand what the software is doing.&lt;/p&gt;

&lt;p&gt;Audit records answer a different class of question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Who performed this business-relevant action, in which organization, and when?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;changing a member's permissions;&lt;/li&gt;
&lt;li&gt;modifying organization settings;&lt;/li&gt;
&lt;li&gt;creating or revoking access;&lt;/li&gt;
&lt;li&gt;performing sensitive administrative operations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These events benefit from a structured, append-oriented model.&lt;/p&gt;

&lt;p&gt;An audit entry might contain information such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;actor
organization
action
resource
timestamp
metadata
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact model varies by product, but treating auditing as an architectural concern from the beginning is much easier than reconstructing it later from application logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Database evolution should be reproducible
&lt;/h2&gt;

&lt;p&gt;A database schema isn't static.&lt;/p&gt;

&lt;p&gt;Tables change.&lt;br&gt;&lt;br&gt;
Indexes appear.&lt;br&gt;&lt;br&gt;
Constraints evolve.&lt;br&gt;&lt;br&gt;
New environments need to reproduce the same structure.&lt;/p&gt;

&lt;p&gt;Database migrations provide an ordered history of that evolution.&lt;/p&gt;

&lt;p&gt;With PostgreSQL and a migration tool such as Flyway, the application can keep schema changes versioned alongside the codebase.&lt;/p&gt;

&lt;p&gt;This gives developers a repeatable path from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;empty database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;current application schema
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;without relying on undocumented manual SQL steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. API errors deserve a contract too
&lt;/h2&gt;

&lt;p&gt;Successful API responses usually receive a lot of design attention.&lt;/p&gt;

&lt;p&gt;Errors often don't.&lt;/p&gt;

&lt;p&gt;Without a standard, endpoints gradually return different shapes for validation failures, authorization errors, missing resources, and unexpected conditions.&lt;/p&gt;

&lt;p&gt;RFC 7807-style problem details provide a useful foundation for a consistent error contract.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Forbidden"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"detail"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"instance"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The goal isn't simply compliance with a specification.&lt;/p&gt;

&lt;p&gt;The goal is predictability for every client consuming the API.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Documentation should describe the actual API
&lt;/h2&gt;

&lt;p&gt;OpenAPI becomes significantly more useful when it evolves with the application instead of living as a document someone occasionally remembers to update.&lt;/p&gt;

&lt;p&gt;A useful SaaS foundation should make the API contract discoverable and keep documentation close to the implementation.&lt;/p&gt;

&lt;p&gt;This becomes particularly valuable when the backend is consumed by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a web frontend;&lt;/li&gt;
&lt;li&gt;mobile applications;&lt;/li&gt;
&lt;li&gt;external integrations;&lt;/li&gt;
&lt;li&gt;other services.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8. The foundation needs tests
&lt;/h2&gt;

&lt;p&gt;Reusable architecture without tests can become reusable uncertainty.&lt;/p&gt;

&lt;p&gt;The important behaviors of the foundation should be executable.&lt;/p&gt;

&lt;p&gt;That includes areas such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;authentication behavior;&lt;/li&gt;
&lt;li&gt;authorization boundaries;&lt;/li&gt;
&lt;li&gt;organization isolation;&lt;/li&gt;
&lt;li&gt;refresh token lifecycle;&lt;/li&gt;
&lt;li&gt;persistence behavior;&lt;/li&gt;
&lt;li&gt;API contracts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tests aren't just there to prevent regressions.&lt;/p&gt;

&lt;p&gt;They document what the foundation promises to do.&lt;/p&gt;

&lt;h2&gt;
  
  
  The recurring pattern
&lt;/h2&gt;

&lt;p&gt;Put these pieces together and a familiar architecture begins to emerge:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Request
   |
Authentication
   |
Organization Context
   |
Capability Authorization
   |
Application Logic
   |
Persistence
   |
PostgreSQL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Surrounding that core are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Audit
Migrations
OpenAPI
Problem Details
Automated Tests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;None of this defines the business domain.&lt;/p&gt;

&lt;p&gt;And that's exactly the point.&lt;/p&gt;

&lt;p&gt;These are infrastructure and application concerns that appear repeatedly across SaaS products.&lt;/p&gt;

&lt;p&gt;The domain should be the part that changes.&lt;/p&gt;

&lt;p&gt;The foundation shouldn't need to be reinvented every time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reuse the foundation, not the business
&lt;/h2&gt;

&lt;p&gt;There's an important distinction here.&lt;/p&gt;

&lt;p&gt;A reusable SaaS foundation shouldn't attempt to be a finished SaaS application.&lt;/p&gt;

&lt;p&gt;Otherwise, developers spend their time removing someone else's product assumptions.&lt;/p&gt;

&lt;p&gt;A better boundary is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reusable foundation
        +
Your business domain
        =
Your product
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A reference application can still be extremely valuable, but its purpose should be to demonstrate how the foundation is used — not to become the template developers blindly copy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why we built the LDS SaaS Starter
&lt;/h2&gt;

&lt;p&gt;This recurring problem is what led us to build the &lt;strong&gt;LDS SaaS Starter&lt;/strong&gt; at LDS Labs.&lt;/p&gt;

&lt;p&gt;It's a reusable Java 21 + Spring Boot backend foundation where concerns such as authentication, organizational context, capability-based authorization, auditing, PostgreSQL/Flyway persistence, OpenAPI, standardized API errors, and automated tests are organized explicitly.&lt;/p&gt;

&lt;p&gt;A separate reference application demonstrates the architecture in a working domain without turning that domain into part of the reusable foundation.&lt;/p&gt;

&lt;p&gt;The goal isn't to claim that every SaaS should have the same architecture.&lt;/p&gt;

&lt;p&gt;It's much simpler:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stop solving the same foundation problems from zero when you could spend that effort on what makes your product different.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you're building a SaaS with Java and Spring Boot, you can explore the architecture, reference application, demo, and Founder License at:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ldshome.com.br/?utm_source=devto&amp;amp;utm_medium=community&amp;amp;utm_campaign=founder_launch_v1&amp;amp;utm_content=first_article" rel="noopener noreferrer"&gt;https://ldshome.com.br&lt;/a&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>java</category>
      <category>springboot</category>
    </item>
  </channel>
</rss>
