Skip to content

coenttb/swift-server-foundation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

swift-server-foundation

CI Development Status

A foundation library for server-side Swift development that consolidates essential packages for building server applications.

Overview

swift-server-foundation provides a unified interface to commonly-used server development packages. Instead of managing multiple dependencies individually, this foundation package re-exports and integrates type safety, authentication, infrastructure, and utility libraries into a single import.

Features

  • Type-safe domain models for email addresses, domains, and JWT
  • Password validation with customizable security policies
  • Cryptographic operations via Apple's Crypto framework
  • Rate limiting and request throttling
  • HTTP client with async/await support
  • Structured logging with Apple's unified logging API
  • Environment variable handling with type safety
  • URL routing with internationalization support
  • Declarative content builders

Installation

Add swift-server-foundation to your Package.swift dependencies:

dependencies: [
    .package(url: "https://github.com/coenttb/swift-server-foundation.git", from: "0.0.1")
]

Quick Start

Import the foundation to access all included packages:

import ServerFoundation

// Logging
let logger = Logger(label: "com.example.app")

// HTTP Client
let client = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup))

// JWT
let jwt = try JWT(
    payload: ["user_id": "12345"],
    signedBy: key
)

Usage

Type Safety & Domain Modeling

Security

  • Crypto - Cryptographic operations and key management
  • Throttling - Rate limiting for API protection

Server Infrastructure

Configuration

  • EnvironmentVariables - Type-safe environment variable handling
  • ServerFoundationEnvVars - Environment-specific configuration

Date & Time

Routing & Localization

Utilities

Environment Variables

The ServerFoundationEnvVars module provides type-safe access to environment configuration:

import ServerFoundationEnvVars

// Access with defaults
let port = EnvVars.PORT.value ?? 8080

// Require value (throws if missing)
let apiKey = try EnvVars.API_KEY.require()

Related Packages

Dependencies

Used By

Third-Party Dependencies

License

This project is licensed under the Apache 2.0 License. See LICENSE for details.

Contributing

Contributions are welcome. Please open an issue or submit a pull request on GitHub.

About

A Swift package with tools to simplify server development.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Languages