Server-Side Swift Generator
Generates and guides server-side Swift projects using Vapor or Hummingbird, including API design, database integration, authentication, deployment, and shared code with iOS clients.
When This Skill Activates
Use this skill when the user:
- Asks to "create a backend" or "build an API" in Swift
- Mentions "Vapor", "Hummingbird", or "server-side Swift"
- Wants JWT, OAuth, or session authentication on the server
- Needs to share Codable models between an iOS app and a Swift server
- Asks about sending push notifications from a server (APNSwift)
- Wants to deploy a Swift server (Docker, Fly.io, Railway)
- Mentions Fluent ORM, database migrations, or PostgreSQL with Swift
- Asks about WebSockets or real-time features on the server
- Wants to replace CloudKit with a custom backend
Pre-Generation Checks
1. Project Context Detection
- Check if a
Package.swiftalready exists - Determine if this is a new project or adding to an existing one
- Check Swift version (async/await requires Swift 5.5+, Hummingbird 2 requires Swift 6+)
- Search for existing server-side code
Glob: **/Package.swift, **/configure.swift, **/routes.swift, **/entrypoint.swift
Grep: "import Vapor" or "import Hummingbird" or "import Fluent"
2. Conflict Detection
Search for existing server implementations:
Glob: **/Controllers/*.swift, **/Migrations/*.swift, **/Models/*.swift
Grep: "RouteCollection" or "AsyncMigration" or "func routes"
If found, ask user:
- Extend existing server with new endpoints?
- Replace existing implementation?
3. iOS Client Detection
Check if an iOS client exists in the workspace:
Glob: **/*.xcodeproj, **/*.xcworkspace
Grep: "import SwiftUI" or "import UIKit"
If found, recommend SharedModels package pattern.
Architecture Decision Gate
Before asking about framework choice, validate that server-side Swift is the right technology for this project. Reference architecture-decisions.md for the full decision framework.
Quick Validation (ask yourself, not the user)
- Does the user have a Swift team or iOS app? → If no, surface alternatives (Go, Node.js, Python)
- Does client-server code sharing provide value? → Strongest signal for Swift
- Does the project need integrations Swift lacks (Kafka, Elasticsearch, email)? → Surface ecosystem gaps honestly
If any red flags, present trade-offs from architecture-decisions.md before proceeding. Example:
"Before we start — server-side Swift works best when you have an iOS app that can share models with the backend. Since your project is [web-only / cross-platform / ML-heavy], you might want to consider [Node.js / Go / Python] instead. Want me to explain the trade-offs, or proceed with Swift?"
If "Help me decide" on Vapor vs Hummingbird
Don't default arbitrarily. Ask about context:
- Team size and experience — New to server Swift? → Vapor (more docs, bigger community)
- Project type — Lambda/microservice? → Hummingbird (smaller binary, first-class Lambda)
- Compile time sensitivity — Tight CI/CD? → Hummingbird (lighter dependency graph)
- Feature needs — Need ORM + auth + WebSocket out of the box? → Vapor
Reference the weighted decision matrix in architecture-decisions.md for detailed comparison.
Configuration Questions
Ask user via AskUserQuestion:
-
Which framework do you want to use?
- Vapor (batteries-included, Fluent ORM, larger community — 78% market share)
- Hummingbird (lightweight, pure structured concurrency, modular — ideal for microservices/Lambda)
- Help me decide (I'll ask about your project context)
-
What database do you need?
- PostgreSQL (recommended for production)
- SQLite (development/lightweight)
- None (stateless API)
- MongoDB
-
What authentication method?
- JWT (stateless, recommended for mobile APIs)
- Session-based (web apps)
- Sign in with Apple (server-side validation)
- Bearer token (simple)
- None
-
Do you need shared models with an iOS client?
- Yes, create a SharedModels package
- No, server-only project
Generation Process
Step 1: Project Scaffolding
Generate the project structure based on framework choice:
Vapor:
Sources/App/
├── Controllers/
├── Migrations/
├── Models/
├── DTOs/
├── configure.swift
├── entrypoint.swift
└── routes.swift
Tests/AppTests/
Package.swift
Dockerfile
docker-compose.yml
.env
.gitignore
Hummingbird:
Sources/App/
├── Controllers/
├── Models/
├── Application+build.swift
└── App.swift
Tests/AppTests/
Package.swift
Dockerfile
Step 2: Core Files
Generate based on configuration:
Package.swift- Dependencies for chosen framework + database + authconfigure.swift/Application+build.swift- App configuration- Entry point with environment detection
- Basic health check endpoint
Step 3: Database Layer (if selected)
- Model files with Fluent property wrappers
- Migration files with
AsyncMigration - Database configuration in
configure.swift
Step 4: Authentication (if selected)
- Auth middleware and authenticators
- Token/session model and migration
- Protected route groups
- Login/register endpoints
Step 5: Shared Models (if selected)
SharedModels/package with DTOs- Update both
Package.swiftfiles to depend on SharedModels - API endpoint protocol definitions
Step 6: Deployment Files
- Multi-stage
Dockerfile docker-compose.ymlwith database service.envtemplate with required variables
Swift 6 Concurrency Notes
Vapor 4 Async/Await
All new code should use async/await exclusively:
app.get("users") { req async throws -> [User] in
try await User.query(on: req.db).all()
}
Hummingbird 2 Pure Concurrency
Hummingbird 2 is built entirely on structured concurrency with no EventLoopFuture APIs:
router.get("users") { request, context async throws -> [UserDTO] in
try await userRepository.findAll()
}
Sendable Compliance
All DTOs shared between client and server must be Sendable:
public struct UserDTO: Codable, Sendable {
public let id: UUID?
public let name: String
public let email: String
}
Output Format
Files Created
YourProject/
├── Sources/App/
│ ├── Controllers/
│ │ └── TodoController.swift # Route collection
│ ├── Migrations/
│ │ └── CreateTodo.swift # Database migration
│ ├── Models/
│ │ └── Todo.swift # Fluent model
│ ├── DTOs/
│ │ └── TodoDTO.swift # Request/response DTO
│ ├── configure.swift # App configuration
│ ├── entrypoint.swift # Entry point
│ └── routes.swift # Route registration
├── Tests/AppTests/
│ └── TodoTests.swift # Integration tests
├── Package.swift # Dependencies
├── Dockerfile # Multi-stage build
├── docker-compose.yml # App + database
└── .env # Environment variables
Integration Steps
Run locally:
# Start database
docker-compose up db -d
# Run migrations
swift run App migrate --yes
# Start server
swift run App serve --hostname 0.0.0.0 --port 8080
Connect from iOS client:
let client = URLSessionAPIClient(
configuration: .init(baseURL: URL(string: "http://localhost:8080/api/v1")!)
)
let todos = try await client.request(ListTodosEndpoint())
Testing
@Suite("API Tests", .serialized)
struct TodoTests {
@Test("Create todo returns 200")
func createTodo() async throws {
try await withApp(configure: configure) { app in
let dto = TodoDTO(title: "Test")
try await app.testing().test(.POST, "api/v1/todos", beforeRequest: { req in
try req.content.encode(dto)
}, afterResponse: { res async throws in
#expect(res.status == .ok)