Mosaic Available

Mosaic

Amalgame's web framework. A productive HTTPS server in the spirit of Next.js (filesystem routing), Caddy (Let's Encrypt certificates via native ACME), Go net/http (thread pool, no event loop). 100% Amalgame stack on top of OpenSSL 3.x and nghttp2 — sessions, auth, security middleware, static files: all already shipped.

Install & run

Mosaic is a library: add the stack to your project and write your handlers. The mosaic tool creates the project, generates routes from app/, builds, and restarts the server on every save. First install amc. Full guide on docs.amalgame.me → Mosaic.

With the mosaic tool

# install the tool once
curl -sSL https://raw.githubusercontent.com/amalgame-lang/mosaic/main/install.sh | bash

# create a project and run it in dev mode (http://localhost:3000)
mosaic new my-app
cd my-app
mosaic dev

Without the tool

# add the stack to your project, write server.am, run it
amc package add web
amc run server.am

One binary can serve N sites over HTTPS: MosaicServer dispatches requests by Host, picks the certificate by SNI and redirects :80 to :443. It mounts static sites, WebApps and reverse proxies:

// server.am — amc package add web net-proxy, then amc run server.am
namespace App
import Amalgame.Web
import Amalgame.Tls
import Amalgame.Net.Proxy

public class Program {
    public static void Main(string[] args) {
        let api: ReverseProxy = ReverseProxy.New()
            .Forward("/", "http://127.0.0.1:8080")

        let m: MosaicServer = MosaicServer.New()
            .WithCertDir("./certs")
            .AddStaticSite(["example.com"], "/srv/example/public")
            .AddHandler(["api.example.com"], (req: HttpRequest) => api.Handle(req))

        // at startup: one Let's Encrypt cert per domain if missing or expiring within 30 days
        let domains: List<string> = m.DomainList()
        for i in 0..domains.Count() {
            let d: string = domains.Get(i)
            if (AcmeNative.NeedsRenewal(m.certPathOf(d), 30)) {
                AcmeNative.EnsureCert(d, "admin@example.com", "./certs", AcmeNative.LeProd())
            }
        }

        m.ServeHttps(443)   // SNI per domain + :80 → :443 redirect
    }
}

Details in the installation guide.

Composable-package architecture

The stack follows the Amalgame convention: small, focused packages. Import just TLS for a custom protocol, just HTTP for a low-level client/server, or amalgame-web + the mosaic tool for the full stack.

v0.40.1 shipped

amalgame-web

The runtime library: WebApp, Router (:param + *splat), sessions (memory / signed cookie HMAC / Redis), security middleware, auth (Basic / JWT / OAuth2), static files, input validation, observability, 8 Serve modes including in-process HTTPS, and MosaicServer — a multi-site, multi-domain HTTPS front (Host dispatch + SNI + :80→:443, bounded thread pool) that also mounts reverse proxies via AddHandler.

v0.29.7 shipped

amalgame-net-http

Pure-AM HTTP/1.1 parser + HTTPS client (chunked decode). HTTP/2 via nghttp2 (h2c + ALPN h2). HTTPS-over-HTTP/1.1 server with SNI (N domains, 1 cert each) and keep-alive. Fiber-driven async server (epoll). RFC 6455 WebSocket. Parser limits for L7 anti-DDoS. Bounded worker pools (ServePool), IPv6 dual-stack listeners.

v0.3.6 shipped

amalgame-tls

OpenSSL 3.x binding (LibreSSL too). TLS 1.2/1.3, ALPN, SNI, client-auth. Native RFC 8555 ACME — pure-AM state machine, no certbot subprocess. Embedded-renewal helpers. Native multi-SAN since v0.3.6.

v0.2.1 shipped

amalgame-net-proxy

HTTP/1.1 reverse proxy + load balancer — longest-prefix routing, X-Forwarded-For, hop-by-hop stripping, weighted round-robin / ip-hash / least-connections. Mounted in code, standalone or behind MosaicServer (AddHandler).

v0.6.0 shipped

mosaic (the tool)

The build tool / CLI — not a package. Scans app/ and generates _routes.am (Next.js convention), drives amc + gcc, serves public/ automatically. new, dev, build and hot-reload.

HTTPS Hello world — native ACME, the binary handles the rest

One AcmeNative.EnsureCert call provisions the certificate (http-01 challenge, RFC 8555, no certbot), then ServeHttpsMt terminates TLS in-process — no reverse proxy required.

namespace App
import Amalgame.Web
import Amalgame.Tls

public class Program {
    public static void Main(string[] args) {
        // Native RFC 8555 ACME — no subprocess, ES256 account key
        AcmeNative.EnsureCert("my-site.com", "admin@my-site.com",
                            "./certs", AcmeNative.LeStaging())

        let app: WebApp = WebApp.New()
            .WithSecurityHeaders(SecurityHeaders.StrictHtml())  // HSTS, CSP, XFO…
            .WithCsrf(Csrf.Default())                          // double-submit cookie
            .WithRateLimit(RateLimit.PerIp(100, 60))            // 100 req / 60 s / IP
            .WithStatic(Static.New("/assets", "./public").WithCacheMaxAge(3600))
        Routes.Bind(app)                                  // routes generated from app/

        app.ServeHttpsMt(443, "./certs/my-site.com/fullchain.pem",
                              "./certs/my-site.com/privkey.pem")
    }
}

Filesystem routing — Next.js convention

Every .am file under app/ becomes a route. Names with [id] capture a parameter (:id), [...slug] captures a catch-all (*slug). mosaic build scans the tree and generates _routes.am; Routes.Bind(app) wires it all up. Files in public/ are served automatically.

my-app/
├── amalgame.toml
├── mosaic.toml              # [security.*], [tls], [logging]…
├── server.am                # entry point: WebApp + Routes.Bind
├── app/
│   ├── index.am             → GET /
│   ├── about.am             → GET /about
│   ├── users/
│   │   ├── index.am         → GET /users
│   │   ├── [id].am          → GET /users/:id
│   │   └── [id]/posts.am    → GET /users/:id/posts
│   └── api/
│       ├── login.am         → POST /api/login
│       └── [...path].am     → catch-all route
├── lib/
├── public/                  # served at / (ETag, 304, binary-safe)
└── data/

Each file exports a Page class with methods named after the HTTP verb (GET / POST / PUT / PATCH / DELETE), each taking a WebContext:

// app/users/[id].am
namespace App.Users.Detail
import Amalgame.Web
import Amalgame.Net.Http

public class Page {
    public static HttpResponse GET(ctx: WebContext) {
        let id: string = ctx.Param("id")
        let user = Db.FindUser(id)
        if (user == null) {
            return HttpResponse.New().Status(404).Text("User not found")
        }
        return HttpResponse.New().Json(user)
    }
}

The mosaic tool — from scaffold to prod

Three commands cover the whole cycle: new, dev, build. The tool installs once (curl … install.sh | bash) and runs from any project.

mosaic new

Scaffold (v0.4+)

mosaic new my-app drops a working project skeleton and auto-runs amc package add — mosaic dev produces a serving binary on the very next command.

mosaic dev

DEV — watch + livereload (v0.2/0.3+)

Watches app/ and server.am, rebuilds + restarts the server on every save. WebSocket daemon on :35729 → the browser refreshes after each build.

mosaic dev --supervise

Hot-reload supervisor (v0.5+)

The freshly-built worker is swapped behind a TCP shim: in-flight WebSocket connections survive code edits. No disruption for connected clients.

mosaic build

PROD — one-shot build

Full pipeline: regenerate _routes.am, run amc then gcc, produce the binary. Reads amalgame.lock to resolve package archives. You ship a native binary.

L7 security + auth built-in — already shipped

L3/L4 defense stays with the operator (kernel sysctl, firewall, CDN). Everything application-layer is in the framework, opt-in via .With*() and orchestrated by WebApp in the right pipeline order:

  • ✓WithSecurityHeaders (v0.4) — StrictHtml() / StrictApi(): HSTS, CSP, X-Frame-Options, nosniff, Referrer-Policy, Permissions-Policy, COOP/COEP
  • ✓WithCsrf (v0.7) — double-submit cookie, 256-bit token, Secure + SameSite=Lax
  • ✓WithCors (v0.5) — deny by default, AllowAll / Strict presets, OPTIONS preflight handling
  • ✓WithRateLimit (v0.6) — per-IP fixed window, 429 + Retry-After on overflow
  • ✓WithHostGuard (v0.30) — allow-list of accepted Hosts, 400 for the rest; CR/LF neutralised in access logs
  • ✓LoginGuard (v0.31) — counts failed logins per key (IP, username): by default 5 failures in 15 min lock for 15 min, 429 + Retry-After
  • ✓CSP nonce (v0.32) — SecurityHeaders.WithCspNonce(): one nonce per request in ctx.CspNonce, strict CSP without 'unsafe-inline'
  • ✓Validator (v0.36) — declarative per-field rules (Required, Email, Int, Range, OneOf…), errors as JSON, typed values
  • ✓WithStatic (v0.13 · caching v0.27 · hardened v0.29) — file serving, strong ETag + Last-Modified, 304 (If-None-Match / If-Modified-Since), Range 206 / 416, pre-compressed .gz selection, path-traversal guard, ~35 MIME types; refuses hidden files (except .well-known), .am / .lock files and symlinks that leave the root
  • ✓WithCompress (v0.26) — on-the-fly gzip, negotiated via Accept-Encoding (text/*, JSON, JS, SVG, XML), sets Vary; via amalgame-compress
  • ✓Multipart uploads (v0.25) — ctx.Multipart() → UploadedFile (binary-safe, SaveTo / Bytes / Text) + text fields, capped by max_body_bytes
  • ✓Template engine (v0.24) — Mustache-like Template, HTML auto-escape by default (closes the .Html() XSS hole), ctx.Render(path, data); {{{x}}} for raw; context filters {{x|js}}, {{x|attr}}, {{x|url}} (v0.29); list loops {{#items}}…{{/items}} via TemplateContext (v0.40)
  • ✓BasicAuth (v0.15, RFC 7617) · JwtAuth (v0.16, HS256) · OAuth2Client (v0.17, GitHub/Google presets, authorization-code flow; PKCE v0.34; OIDC id_token verification in RS256 v0.35)
  • ✓Sessions — MemorySessionStore, SignedCookieSessionStore (HMAC-SHA-256, stateless), RedisSessionStore
  • ✓WithLogging (v0.8.2) — structured access logs via amalgame-logging, driven by [logging]
  • ✓Anti-slowloris timeouts via HttpServerConfig — header/body/idle timeouts, max_body_bytes, max_header_bytes

HTTPS certificates via native ACME (RFC 8555)

One AcmeNative.EnsureCert(domain, email, dir, server) call and Mosaic provisions the certificate via the http-01 challenge, on a pure-Amalgame ACME state machine (ES256 account key) — no more certbot subprocess. Certs are written to <dir>/<domain>/{fullchain.pem, privkey.pem}. For embedded renewal: AcmeNative.NeedsRenewal(certPath, days) + CertDaysRemaining(certPath) in a thread. Let's Encrypt staging via AcmeNative.LeStaging(). Since tls v0.3.6, EnsureCert takes several comma-separated domains: a single multi-SAN certificate, stored under the first domain.

RFC 6455 WebSocket — built-in server

The WebSocket server lives in amalgame-net-http: Ws.Serve in cleartext, Wss.Serve over TLS. The handler receives a connection and loops on WsConn. The *With variants apply the same socket timeouts as the HTTP server.

namespace App
import Amalgame.Net.Http

public class Program {
    public static void Main(string[] args) {
        let handler = conn => {
            while (!WsConn.IsClosed(conn)) {
                let msg: string = WsConn.ReceiveText(conn)
                if (String_Length(msg) == 0) { return 0 }   // disconnected
                WsConn.SendText(conn, "echo @ " + msg)
            }
            return 0
        }
        Ws.Serve(8080, handler)   // ws://  — Wss.Serve(port, cert, key, handler) for wss://
    }
}

Subprotocol negotiation (v0.17) — Ws.ServeWithProtocols(port, "v2.json,v1", handler) echoes back the first Sec-WebSocket-Protocol the server supports; WsConn.Subprotocol(conn) reads it. Phoenix-style multi-client pub/sub (channels, topics, broadcast) is not yet a framework primitive: build it on top of WsConn, or wait for a dedicated version (see roadmap).

Server-Sent Events — one-way push

For live push (progress, notifications, tickers) without the weight of a WebSocket: app.Sse("/events", sc => { ... }) (v0.28). The handler holds the connection and pushes frames via SseConn — Send(data) (false when the client leaves), SendEvent(event, data, id), Comment (heartbeat), Retry. Browser side: new EventSource("/events"). On MosaicServer, AddSseRoute(hosts, path, handler) does the same (v0.39).

Concurrency: thread pool or fibers, your choice

Go net/http model — blocking I/O, native multi-core, no async/await contaminating your code. WebApp exposes 8 Serve modes; pick based on load.

  • ✓Serve / ServeWith — serial HTTP/1.1 loop, simple, for dev or low load
  • ✓ServeMt / ServeMtWith — one thread per connection (~8 MB lazy stack), prod default for CPU-bound handlers
  • ✓ServeAsync / ServeAsyncWith (v0.12) — 1 thread, N fibers (~64 KB/conn), Linux epoll — ideal for I/O-bound handlers, thousands of connections
  • ✓ServeHttps / ServeHttpsMt (v0.14) — in-process TLS termination, no reverse proxy required
  • ✓MosaicServer.ServeHttps (v0.37) — fixed thread pool; WithWorkers(n) and WithBacklog(n) (v0.38) set its size and the kernel listen queue
  • ✓HTTP/1.1 keep-alive — enabled whenever idle_timeout_sec > 0
  • ✓HEAD (v0.36.1) — with no HEAD route, the GET route answers, without the body (RFC 7231)
  • ✓Graceful shutdown — SIGTERM/SIGINT handler, drains in-flight requests, clean exit
  • ✓WithObservability (v0.33) — /healthz and /readyz for probes; Prometheus /metrics, served only to loopback or private IPs, or with a token

Roadmap — where we are

The stack started from scratch in mid-May 2026 and shipped, in a few weeks, an end-to-end usable web stack. Here's the real state.

Shipped

The core

Filesystem routing, in-process HTTPS, native RFC 8555 ACME, full security pack (CSRF/CORS/headers/rate-limit), auth (Basic/JWT/OAuth2), sessions (memory/signed cookie/Redis), static files, fiber async, hot-reload supervisor, HTTPS client.

Shipped

Rendering, uploads & real-time

Auto-escaping template engine (anti-XSS), binary-safe multipart uploads, negotiated gzip compression, static Last-Modified + Range 206 + .gz selection, Server-Sent Events (WebApp.Sse), WebSocket subprotocol negotiation. (June 2026.)

Shipped

Hardening & operations

Hardened static files and |js |attr |url filters (v0.29), WithHostGuard (v0.30), LoginGuard (v0.31), CSP nonce (v0.32), WithObservability (v0.33), PKCE (v0.34), OIDC RS256 id_token (v0.35), Validator (v0.36), HEAD → GET (v0.36.1), Windows fixes (v0.36.2–0.36.3), bounded thread pool then WithWorkers / WithBacklog (v0.37–0.38), AddSseRoute (v0.39), template list loops (v0.40), gcc 14+ (v0.40.1). Native multi-SAN ACME (tls v0.3.6). (June–November 2026.)

Later

HTTP & TLS polish

sendfile(2) zero-copy for static. OCSP stapling, dns-01 challenge + wildcards. RS256 JWT in JwtAuth. Async I/O for H2/HTTPS/WS (gated on TLS-side fibers).

Later

WebSocket & real-time

Binary + continuation frames, wss:// client-side, per-message-deflate. Phoenix-style pub/sub channels primitive (topics + broadcast), multi-node via Redis Pub/Sub.

Later

Ops & breadth

OpenTelemetry tracing, systemd Type=notify. amalgame-queue, amalgame-cron, amalgame-openapi.

Beyond HTTP — nginx "front door" ambition

Beyond HTTPS listening, Mosaic aims at the nginx/apache front-door role: reverse proxy, load balancing, raw TCP/UDP proxying. Inventory in the beyond-http.md proposal. Reverse proxy, load balancing and the raw TCP proxy have shipped; SFTP remains roadmap.

shipped

HTTP/HTTPS reverse proxy

amalgame-net-proxy — proxy in front of N upstreams: longest-prefix routing, X-Forwarded-For, hop-by-hop stripping. Mounted in code, standalone or behind MosaicServer (AddHandler). HTTP/2 + transparent WebSocket forwarding still roadmap.

shipped

Load balancing

Weighted round-robin, least-connections, IP-hash — a pool per route via ForwardPool(prefix, UpstreamPool). Active health checks, outlier detection and sticky sessions are still roadmap.

shipped

TCP/UDP raw proxy

amalgame-net-stream — nginx stream {} or HAProxy TCP mode equivalent. Fronting Postgres, Redis Sentinel, MQTT. In the registry: v0.3.0, TCP and UDP, with load balancing and IPv6.

prio LOW

SFTP

amalgame-net-ssh (libssh2 binding, SFTP automation). For mail, the receiving server (net-smtp-server) and sending (mail-send) are already in the registry.

Go further

Mosaic is available. The spec remains the source of truth; changes go through PRs on the repos.