<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/building-scalable-backend-apps-in-swift-h6s2gzfe4" -->

---
title: Building scalable backend apps in Swift | daily.dev
description: A deep-dive into structuring server-side Swift backends using onion, hexagonal, and clean architecture principles. Covers domain models with enforced business...
canonical: https://daily.dev/posts/building-scalable-backend-apps-in-swift-h6s2gzfe4
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Building scalable backend apps in Swift | daily.dev
og:description: A deep-dive into structuring server-side Swift backends using onion, hexagonal, and clean architecture principles. Covers domain models with enforced business...
og:url: https://daily.dev/posts/building-scalable-backend-apps-in-swift-h6s2gzfe4
og:image: https://api.daily.dev/og/posts/H6s2gzFE4.png
og:image:alt: Building scalable backend apps in Swift
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Building scalable backend apps in Swift

**[The.Swift.Dev.](https://daily.dev/sources/theswiftdev)** · 26 min read · 0 upvotes · 0 comments

## Summary

A deep-dive into structuring server-side Swift backends using onion, hexagonal, and clean architecture principles. Covers domain models with enforced business rules, repository interfaces, use cases with input/output DTOs, role-based access control via Action/Authorizer abstractions, transaction management through executor and scope patterns, database access layer (DBAL) design, and how it all composes together with Postgres, Feather Database, and Vapor/Hummingbird route handlers.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://theswiftdev.com/building-scalable-backend-apps-in-swift>

## Questions this post answers

### How do you implement a repository pattern in Swift for backend applications?

Define a protocol in the domain layer, such as PostRepository, with async throwing methods like insert, update, and delete that operate on domain models. Concrete implementations, like a PostDatabaseRepository, live in the infrastructure layer and use a database access layer to fulfill the protocol, keeping the application core independent of the specific database technology.

_See how daily.dev surfaces architecture patterns like this for developers designing Swift backends._

### How do you manage database transactions and units of work in a Swift backend architecture?

Use separate executor protocols for queries and transactions, such as QueryExecutor and TransactionExecutor, each running a closure against a generic scope containing the needed repositories. A TransactionExecutor implementation calls withTransaction on the database client so operations either fully commit or roll back, keeping multi-table writes like posts and their tags atomic.

_Developers wiring up transactional workflows can track deeper Swift backend patterns on daily.dev._

### How should DTOs differ from domain models in a use case layer in Swift?

Domain models can hold sensitive or internal data, like a password field, while DTOs expose only what a use case's consumers need. A use case such as AddPostUseCase takes an Input struct and returns an output like PostDetailDTO, mapping the domain model to the DTO so internal fields never leak past the application boundary.

_daily.dev helps backend developers compare DTO and domain modeling approaches across languages._

## Similar posts on daily.dev

- [How Far Can Swift Go on the Server? -Part I](https://daily.dev/posts/how-far-can-swift-go-on-the-server--part-i-givocvqcb) · Medium · 0 upvotes · 0 comments
- [Borrowing from Kotlin/Android to Architect Scalable iOS Apps in SwiftUI](https://daily.dev/posts/borrowing-from-kotlin-android-to-architect-scalable-ios-apps-in-swiftui-zar5rarxu) · InfoQ · 0 upvotes · 0 comments
- [Swift Server Has Another Google -- Fatbobman's Swift Weekly \#156](https://daily.dev/posts/swift-server-has-another-google----fatbobman-s-swift-weekly-156-hlv8nxymu) · Fatbobman · 0 upvotes · 0 comments
- [From Spring Boot to Swift: The Business Logic Was the Cheap Part](https://daily.dev/posts/from-spring-boot-to-swift-the-business-logic-was-the-cheap-part-nebmkht0n) · ITNEXT · 1 upvotes · 0 comments
- [Layered Architecture for Building Readable, Robust, and Extensible Apps](https://daily.dev/posts/layered-architecture-for-building-readable-robust-and-extensible-apps-ca78tav68) · Towards Data Science · 0 upvotes · 0 comments

---

Tags: [#architecture](https://daily.dev/tags/architecture), [#swift](https://daily.dev/tags/swift), [#authorization](https://daily.dev/tags/authorization)

[View this post on daily.dev](https://daily.dev/posts/building-scalable-backend-apps-in-swift-h6s2gzfe4)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Building scalable backend apps in Swift","url":"https://daily.dev/posts/building-scalable-backend-apps-in-swift-h6s2gzfe4","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/building-scalable-backend-apps-in-swift-h6s2gzfe4"},"datePublished":"2026-08-16T12:28:13.193Z","dateModified":"2026-08-16T12:28:36.610Z","description":"A deep-dive into structuring server-side Swift backends using onion, hexagonal, and clean architecture principles. Covers domain models with enforced business...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/9835a5cb212ed28889bb9adf76c8d1bd?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/9835a5cb212ed28889bb9adf76c8d1bd?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"The.Swift.Dev.","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"The.Swift.Dev.","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/7e3b70bb1cad410caf3ececac4b04ca9","url":"https://daily.dev/sources/theswiftdev"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/building-scalable-backend-apps-in-swift-h6s2gzfe4","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"architecture,swift,authorization","timeRequired":"PT26M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"The.Swift.Dev.","item":"https://daily.dev/sources/theswiftdev"},{"@type":"ListItem","position":3,"name":"Building scalable backend apps in Swift"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/building-scalable-backend-apps-in-swift-h6s2gzfe4#faq","mainEntity":[{"@type":"Question","name":"How do you implement a repository pattern in Swift for backend applications?","acceptedAnswer":{"@type":"Answer","text":"Define a protocol in the domain layer, such as PostRepository, with async throwing methods like insert, update, and delete that operate on domain models. Concrete implementations, like a PostDatabaseRepository, live in the infrastructure layer and use a database access layer to fulfill the protocol, keeping the application core independent of the specific database technology. See how daily.dev surfaces architecture patterns like this for developers designing Swift backends."}},{"@type":"Question","name":"How do you manage database transactions and units of work in a Swift backend architecture?","acceptedAnswer":{"@type":"Answer","text":"Use separate executor protocols for queries and transactions, such as QueryExecutor and TransactionExecutor, each running a closure against a generic scope containing the needed repositories. A TransactionExecutor implementation calls withTransaction on the database client so operations either fully commit or roll back, keeping multi-table writes like posts and their tags atomic. Developers wiring up transactional workflows can track deeper Swift backend patterns on daily.dev."}},{"@type":"Question","name":"How should DTOs differ from domain models in a use case layer in Swift?","acceptedAnswer":{"@type":"Answer","text":"Domain models can hold sensitive or internal data, like a password field, while DTOs expose only what a use case's consumers need. A use case such as AddPostUseCase takes an Input struct and returns an output like PostDetailDTO, mapping the domain model to the DTO so internal fields never leak past the application boundary. daily.dev helps backend developers compare DTO and domain modeling approaches across languages."}}]}
```

