# Direct Style Scala 3: A Practical Guide A reference for LLM agents implementing direct-style Scala 3 applications with virtual threads. Each chapter covers a single use-case using [Tapir](https://tapir.softwaremill.com), [Ox](https://ox.softwaremill.com), and the direct-style ecosystem. ## Chapters - [Resource Management](01-resource-management.md) — `useInScope`, `useCloseableInScope`, reverse-order release, scope-based cleanup. - [Background Processes](02-background-processes.md) — `OxApp` entry point, `fork`/`forkUser` for daemon vs. user threads, `forever`/`sleep` for periodic loops, orderly shutdown. - [Type-Safe Configuration](03-type-safe-configuration.md) — PureConfig with `derives ConfigReader`, environment variable overrides, `Sensitive` wrapper, load-time validation. - [Compile-Time Dependency Injection](04-compile-time-dependency-injection.md) — MacWire `autowire`, `autowireMembersOf` for config extraction, `wireList` for collecting endpoints. - [Error Handling](05-error-handling.md) — `Fail` ADT, Ox `either` blocks with `.ok()` short-circuiting, `transactEither`, `.catching`, nesting rules. - [Error Output Customisation](06-error-output-customisation.md) — JSON error responses for all error types. Bidirectional `Fail` → HTTP status code mapping, `failOutput`, `defaultHandlers` for decode failures and 404s. - [Decode Failure Handling](07-decode-failure-handling.md) — `DefaultDecodeFailureHandler` customisation: respond/message/response pipeline, `onDecodeFailureNextEndpoint`, custom failure messages, `hideEndpointsWithAuth`. - [Authentication](08-authentication.md) — `secureEndpoint[T]`, `AuthTokenOps[T]` trait, `Auth[T]` authenticator, `handleSecurity` wiring. - [HTTP Server Configuration](09-http-server-configuration.md) — Security headers, CORS, serving static files for SPAs, request cancellation, `NettySyncServer` startup. - [SQL Persistence](10-sql-persistence.md) — Magnum with PostgreSQL: `@Table` case classes, `DbCodec` for opaque types, `Repo`/`TableInfo`, `sql` interpolation, Flyway migrations, HikariCP. - [Version API](11-version-api.md) — `sbt-buildinfo` generating `BuildInfo` with git commit hash, served from a Tapir endpoint. - [Sending Emails](12-sending-emails.md) — `EmailScheduler` trait, pluggable senders (SMTP, Mailgun, dummy), email templates, background batch processing. - [Compile-Time OpenAPI Generation](13-compile-time-openapi-generation.md) — Build-time OpenAPI YAML generation for frontend client codegen (not runtime Swagger UI). `EndpointsForDocs`, `@main` generator, sbt task wiring. - [Testing HTTP Endpoints](14-testing-http-endpoints.md) — `TapirSyncStubInterpreter` stub backend, `SttpClientInterpreter` for type-safe requests, testing public and secured endpoints in-process. - [OpenTelemetry Observability](15-opentelemetry-observability.md) — SDK auto-configuration, Tapir tracing/metrics interceptors, sttp client instrumentation, custom metrics, `PropagatingVirtualThreadFactory` for context propagation, MDC log correlation. - [Kafka Streaming](16-kafka-streaming.md) — `KafkaFlow.subscribe`, `mapPar`, `KafkaDrain` publishing, offset commits, transactional produce-and-commit, graceful shutdown.