Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.prism.byescaleira.com/llms.txt

Use this file to discover all available pages before exploring further.

Installation

Prism is distributed as a Swift package. No Homebrew formulas, no CocoaPods, no extra tooling — just add it to your Package.swift.

Requirements

RequirementMinimum
Swift6.0+
macOS14.0+ (Sonoma)
LinuxNot currently supported (Network.framework is Apple-only)
Xcode16.0+ (optional, for IDE support)
Prism uses Apple’s Network.framework for its TCP layer, which means it currently runs on macOS only. Linux support via raw sockets is on the roadmap.

Swift Package Manager

Add Prism as a dependency in your Package.swift:
Package.swift
// swift-tools-version: 6.0
import PackageDescription

let package = Package(
    name: "my-server",
    platforms: [.macOS(.v14)],
    dependencies: [
        .package(url: "https://github.com/byescaleira/prism.git", from: "4.4.0")
    ],
    targets: [
        .executableTarget(
            name: "my-server",
            dependencies: [
                .product(name: "PrismServer", package: "prism")
            ]
        )
    ]
)
Then build:
swift build
Pin to a specific version for production stability: .package(url: "...", exact: "4.4.0"). Use from: for automatic minor/patch updates.

Available Products

Prism is a monorepo with multiple library products. You only need to import what you use:
ProductWhat it includes
PrismServerThe full server framework — HTTP, routing, middleware, database, WebSocket, GraphQL, MCP, and all 36+ modules
PrismFoundationCore utilities shared across all Prism modules (logging, extensions, protocols)
For server development, you’ll almost always want PrismServer — it includes everything.

Project Scaffolding

Prism includes a built-in project generator that creates a production-ready project structure for you:
import PrismServer

// Generate a complete project
try PrismServerScaffold.generate(
    name: "my-api",
    directory: "./my-api"
)
This creates:
my-api/
  Package.swift          # Pre-configured with Prism dependency
  Sources/
    main.swift           # Server with example routes
  Dockerfile             # Multi-stage build for production
  .gitignore             # Swift-appropriate gitignore
You can also create a project manually — the scaffold is a convenience, not a requirement. The quickstart guide walks through manual setup step by step.

Docker

The scaffold generates a Dockerfile, but you can also write your own. Here’s a production-ready setup:
Dockerfile
# Build stage
FROM swift:6.0-jammy AS builder
WORKDIR /app
COPY Package.swift Package.resolved ./
RUN swift package resolve
COPY Sources/ Sources/
RUN swift build -c release

# Run stage
FROM swift:6.0-jammy-slim
WORKDIR /app
COPY --from=builder /app/.build/release/my-server .
EXPOSE 8080
CMD ["./my-server"]
Build and run:
docker build -t my-server .
docker run -p 8080:8080 my-server
The multi-stage build keeps your production image small — it only includes the compiled binary and Swift runtime, not the build tools or source code.

Configuration

Prism reads configuration from environment variables and .env files using PrismConfig:
PORT=3000 HOST=0.0.0.0 PRISM_ENV=production swift run
Access configuration in your code:
let config = PrismConfig.load()

let port = config.port              // UInt16, from PORT env var (default 8080)
let host = config.host              // String, from HOST env var (default "0.0.0.0")
let isProd = config.isProduction    // Bool, checks PRISM_ENV == "production"

// Custom keys
let dbPath = config.get("DATABASE_PATH", default: ":memory:")
let maxConn = config.getInt("MAX_CONNECTIONS", default: 5)
let debug = config.getBool("DEBUG", default: false)
let secret = try config.require("SESSION_SECRET")  // Throws if missing

Verify Installation

Create a minimal server to verify everything works:
Sources/main.swift
import PrismServer

let server = PrismHTTPServer(port: 8080)

await server.get("/") { _ in
    .json(["status": "ok", "framework": "Prism", "version": "4.4.0"])
}

print("Server starting on http://localhost:8080")
try await server.start()
try await Task.sleep(for: .seconds(.max))
swift run
In another terminal:
curl http://localhost:8080
# {"status":"ok","framework":"Prism","version":"4.4.0"}
If you see the JSON response, Prism is installed and working.

IDE Setup

Open the package directory in Xcode:
open Package.swift
Xcode resolves dependencies automatically. You get full autocomplete, jump-to-definition, and debugging.

Next Steps

Quickstart Tutorial

Build a complete REST API with database, validation, and error handling.

Core Concepts

Understand how the server, routing, and middleware pipeline work together.