1amageek/swift-web
SwiftWeb is a Swift framework for server-rendered web applications with an
What You Build
flowchart LR
App["SwiftWeb.App"] --> Scene["Scene and routes"]
Scene --> Page["@Page"]
Page --> Document["HTMLDocument"]
Document --> HTML["server-rendered HTML"]
Document --> Island["ClientComponent"]
Island --> WASM["Swift WASM runtime"]
WASM --> Browser["hydration, state, and events"]| Layer | Responsibility | |---|---| | SwiftHTML | HTML elements, reusable Component values, documents, and rendering | | SwiftWeb | Application scenes, pages, routing, request context, actions, and actors | | SwiftWebUI | Layout, controls, themes, modifiers, and client components | | sweb | Project generation, generated packages, development server, independent services, Storyboard, and production builds |
Requirements
SwiftWeb pins the host toolchain and WASM SDK to the same snapshot.
| Item | Required value | |---|---| | Swift tools version | 6.4 | | Swiftly selector | 6.4.x-snapshot-2026-08-14 | | Swift toolchain | swift-6.4.x-DEVELOPMENT-SNAPSHOT-2026-08-14-a | | Browser SDK | swift-6.4.x-DEVELOPMENT-SNAPSHOT-2026-08-14-a_wasm | | Package platform | macOS 26.2 or newer |
Select the pinned Swift toolchain and install the matching WASM SDK. SwiftWeb automatically detects the toolchain in its standard macOS installation location. See Toolchain for discovery rules and optional overrides.
Quick Start
Release 0.14.0
Install the sweb executable from the 0.14.0 release with Mint:
export PATH="$SWIFT_WEB_TOOLCHAIN_BIN:$PATH"
mint install 1amageek/swift-web@0.14.0 sweb
sweb --helpCreate and run an application:
sweb new MyApp --output .
cd MyApp
sweb devOpen http://127.0.0.1:3000. If port 3000 is occupied, sweb dev selects the next available port and prints it.
The generated package depends on released versions of SwiftWeb and SwiftHTML:
// swift-tools-version: 6.4
import PackageDescription
let package = Package(
name: "MyApp",
platforms: [.macOS("26.2")],
products: [
.library(name: "MyApp", targets: ["MyApp"]),
],
dependencies: [
.package(url: "https://github.com/1amageek/swift-web.git", from: "0.14.0"),
.package(url: "https://github.com/1amageek/swift-html.git", from: "0.16.1"),
],
targets: [
.target(
name: "MyApp",
dependencies: [
.product(name: "SwiftHTML", package: "swift-html"),
.product(name: "SwiftWeb", package: "swift-web"),
],
swiftSettings: [
.enableUpcomingFeature("ApproachableConcurrency"),
]
),
],
swiftLanguageModes: [.v6]
)Try the current checkout
To try changes from a checkout, build the CLI and run the example from that same checkout instead of mixing a released CLI with source from main:
git clone https://github.com/1amageek/swift-web.git
cd swift-web
swift build --product sweb --jobs 2
export PATH="$PWD/.build/debug:$PATH"
cd Examples/CounterApp
sweb devThe bundled examples resolve SwiftWeb from the repository root. See CounterApp for its local hosting model.
Development Workflow
sweb dev maintains desired source state and the currently serving worker. It materializes generated packages, rebuilds changed browser/server paths, swaps a ready worker, and recovers from build failures without discarding the last good application.
flowchart LR
Edit["edit Sources"] --> Dev["sweb dev"]
Dev --> Prepare["materialize .swiftweb/generated"]
Prepare --> Build["build WASM and server worker"]
Build --> Serve["serve latest successful generation"]
Serve --> HMR["browser HMR or page patch"]
HMR --> EditGenerated content is build output. Keep application changes in Package.swift and Sources; do not edit .swiftweb/generated directly.
| Command | Purpose | |---|---| | sweb new <Name> [--output <directory>] | Create a minimal application | | sweb new <Name> --ai | Create a chat-oriented SwiftWebUI application | | sweb new <Name> --adapter <owner/repository> | Add an adapter package and configured production environment | | sweb prepare [--environment <name>] [--runtime standard|embedded] | Resolve adapters and materialize configured environments | | sweb xcode | Refresh and open .swiftweb/generated/dev | | sweb dev [--environment <name>] [--host <host>] [--port <port>] | Build and run the selected environment locally | | sweb storyboard | Runs the declared application through the Storyboard selection contract; the catalog is an independent repository | | sweb build [--environment <name>] [--runtime standard|embedded] | Build and verify the selected environment | | sweb deploy [--environment <name>] [--runtime standard|embedded] | Build, verify, and deploy the selected environment | | sweb clean [--storyboard] [--swiftpm] [--all] | Remove selected generated output |
All package commands accept --package-path <directory>. Lifecycle commands select their default environment from the source-controlled sweb.json.
Run sweb xcode to use the generated <AppName>-dev scheme in Xcode:
cd MyApp
sweb xcodeProduction Builds and Deployment
Build the complete selected environment. Service adapters build independent service applications, the Host adapter owns primary application compilation, and the Deployment adapter owns platform validation:
cd MyApp
sweb build --environment productionDeploy only after the same environment has passed prepare and build:
sweb deploy --environment productionsweb deploy reruns prepare and build before the deployment operation. Remote state changes remain isolated to selected Service and Deployment adapter deploy tasks.
The browser runtime profile is selected at the build boundary. Application source keeps the same actor call surface in both profiles:
sweb build --environment production --runtime embeddedEmbedded builds use the pinned matching Embedded WASM SDK. The development server remains a Standard WASM workflow; use prepare, build, or deploy for Embedded artifacts.
Project Layout
MyApp/
├─ Package.swift
├─ sweb.json source-controlled environments
├─ Sources/MyApp/
│ ├─ App.swift
│ ├─ Routes/
│ └─ Components/
└─ .swiftweb/ generated; do not edit
└─ generated/
├─ environments/<name>/workspace/
│ └─ services/<service-name>/
├─ dev/
├─ server/
└─ wasm/SwiftWeb itself is split into runtime, browser, UI, development, and host targets. The documentation index maps each current contract to its owning area.
Host, Deployment, and Service Adapters
Deployment integrations live outside the core package. sweb new adds the selected adapter as a SwiftPM dependency and writes its environment selection to sweb.json:
sweb new Chat --ai --adapter owner/repository --output .
sweb new App --adapter owner/repository --output .The adapter repository contract is documented in Host, Deployment, and Service Adapter Contract. Service applications remain build/deploy units rather than Swift-facing interfaces. Actor connections retain the concrete Swift Distributed Actor surface described by the Actor integration design.
Examples
| Example | Demonstrates | |---|---| | HelloWorld | Minimal app, static @Page, SwiftHTML, and SwiftWebUI rendering | | CounterApp | .actor(Type.self, identity:), local Actor hosting, browser and server @RemoteActor calls, hydration, and Server Actions |
cd Examples/HelloWorld
sweb devDocumentation
Read the changelog for release-level changes, then use the documentation index for current public contracts, architecture decisions, and verification runbooks.
Contributing
Use the pinned toolchain for every validation command. Run the non-Metal Native tests with SwiftPM. Bound compilation separately so a cold build does not consume the test execution budget:
scripts/swift-test-timeout.sh 1200 -- swift build --build-tests --jobs 2
scripts/swift-test-timeout.sh 120 -- swift test --skip-buildUse --filter <SuiteOrTestName> for focused runs. Browser tests are opt-in; the Service Actor HTTP boundary gate checks forwarding between two native hosts through Chromium. It is separate from the Swift-WASM hydration and development-loop gate, which requires the full Chromium suite plus WebKit hydration, navigation-free Actor mutation, and reload persistence. WebKit launch is checked before Swift builds; both counter npm commands select this same required gate:
cd Tests/BrowserE2E
npm run install-webkit
npm run counter-wasmSee Development Reconciler Verification for the required environment and acceptance conditions.
License
SwiftWeb is available under the MIT License.
Package Metadata
Repository: 1amageek/swift-web
Default branch: main
README: README.md