swift-server-foundation
is a comprehensive server-side Swift library that consolidates essential packages for building robust, scalable server applications. Rather than managing multiple dependencies, this foundation provides unified access to authentication, database connectivity, rate limiting, logging, routing, and server infrastructure tools.
This foundation re-exports the following specialized packages, organized by domain:
- EmailAddress - Domain-accurate and type-safe email address handling that adheres to web standards
- Domain - Type-safe domain model consistent with web standards for reliable domain handling
- JWT - Standards-compliant JSON Web Token creation, signing, and verification using Apple's Crypto framework
- PasswordValidation - Robust password validation with customizable security policies
- Crypto - Apple's Swift Crypto framework for cryptographic operations, hashing, and secure key management
- Throttling - Flexible rate limiting and throttling implementation to protect APIs from abuse and ensure fair usage
- PostgresKit - PostgreSQL database driver with async/await support for reliable data persistence
- Database Configuration - Built-in utilities for managing database connections and configurations
- AsyncHTTPClient - Non-blocking HTTP client built on SwiftNIO for making external API calls
- Logging - Apple's unified logging API for structured, configurable application logging
- Event Loop Management - Connection pooling and event loop group utilities for optimal performance
- EnvironmentVariables - Type-safe environment variable handling with validation and defaults
- Environment Variables Test Support - Testing utilities for environment-dependent code
- DateParsing - Comprehensive date parsing for RFC 2822, RFC 5322, and Unix epoch timestamps with robust error handling
- FoundationExtensions - Powerful extensions for date manipulation, validation, and formatting with intuitive operations like
date + 1.day
- URLRouting - Point-Free's powerful URL routing library for type-safe navigation
- URLRoutingTranslating - Internationalization support for routing with multi-language URL patterns
- Translating - Comprehensive translation and localization framework
- Builders - Result builders for creating collections and content with declarative, SwiftUI-like syntax
- Dependencies - SwiftUI Environment-inspired dependency management for controllable and testable applications
- CasePaths - Key path-like functionality for enum cases
- IssueReporting - Runtime issue reporting and debugging utilities
Instead of importing multiple individual packages:
import AsyncHTTPClient
import PostgresKit
import JWT
import Throttling
import Logging
import EnvironmentVariables
// ... and many more
Simply import the foundation:
import ServerFoundation
// All server functionality is now available:
let logger = Logger(label: "com.example.app")
let jwt = try JWT.signed(/* ... */)
let client = HTTPClient(eventLoopGroupProvider: .shared)
let rateLimiter = RateLimiter(rate: 100, per: .minute)
let dbConfig = try DatabaseConfiguration.live
To use swift-server-foundation in your project, add it to your Package.swift
dependencies:
dependencies: [
.package(url: "https://github.com/coenttb/swift-server-foundation.git", exact: "0.0.1")
]
The package includes ServerFoundationEnvVars
for environment-specific configuration:
import ServerFoundationEnvVars
// Access environment variables with type safety
let port = EnvVars.PORT.value ?? 8080
let databaseUrl = EnvVars.DATABASE_URL.require()
- boiler: A minimal Swift web framework for building type-safe servers
- swift-web-foundation: Web development foundation library with HTML, CSS, and form handling
- coenttb-com-server: The backend server for coenttb.com, written entirely in Swift and powered by this foundation
If you're working on your own Swift server project, feel free to learn, fork, and contribute.
Got thoughts? Found something you love? Something you hate? Let me know! Your feedback helps make this project better for everyone. Open an issue or start a discussion—I'm all ears.
This project is licensed under the Apache 2.0 License. See the LICENSE.