Direct style scala

From VirtusLab/scala-skill · View interactive version

Direct style scala is an AI agent skill from the GitHub repository VirtusLab/scala-skill. Scala coding style, tooling, and functional programming guidance, with dedicated sections on direct-style Scala, Ox structured concurrency, and synchronous Tapir. Auto-load for any task involving Scala code, especially when using direct-style or "plain" Scala.

How to use this skill

Skill file

Scala tooling

server keeps the environment of its first start; sbt shutdown to reset it.

that JVM. unknown event: sbt/clientJob means the sbt runner is too old.

Bare settings apply to all subprojects (no ThisBuild /). Tasks are cached:

wrap side-effecting custom tasks in Def.uncached.

https://repo1.maven.org/maven2/<group-with-slashes>/<artifact>/maven-metadata.xml,

including the suffix (com/softwaremill/ox/core_3; sbt plugins:

_sbt2_3). Take the latest stable <version>; <release> may be a prerelease

(RC, M<n>, SNAP, alpha, beta, NIGHTLY). NEVER use

search.maven.org/solrsearch (stale by months). Find unknown coordinates via

https://index.scala-lang.org/api/autocomplete?q=<name>.

-Wunused:all, -Wvalue-discard, -Wnonunit-statement in scalacOptions.

Fix warnings in code; only use @nowarn for generated code or unfixable

third-party issues (with a comment explaining why).

Coding style

entities

each top-level declaration's visibility (narrowest the call sites allow).

Read Code Organization and Visibility when

adding packages/modules or widening visibility.

operation, or a short orchestration of named steps.

feed the next line; keep a named val when the name documents intent.

overlapping or redundant tests.

prevents accidental signature drift during refactors.

Performance

computeIntensive or cede() — see [CPU-intensive

work](150-shared-state-across-threads.md#cpu-intensive-work).

Direct-style Scala

NEVER .serverLogic* (it needs an effect wrapper).

threads, queues, locks, or lifecycle flags. See [Use Ox

primitives](150-shared-state-across-threads.md#use-ox-primitives).

supervised per request/job; return the fork's result, never an object

owning running forks. Read [Scope

propagation](150-shared-state-across-threads.md#scope-propagation) before

taking (using Ox) / (using ResourceScope) or forking from a factory.

java.io stream is NOT ended by scope cancellation — shutdown deadlocks.

BEFORE driving a subprocess or reading a blocking external stream (socket,

SSE), read [Subprocesses and External

Streams](170-subprocesses-and-external-streams.md).

Functional programming

Worked examples: Domain Modeling.

shared mutable state.

as class fields. Class-level vars break reasoning and testability. The sole

exception is mutable state encapsulated by an Ox Actor, which serialises every

invocation onto a single thread — the actor is what makes the field safe to hold

(see Concurrency and Inter-Thread Communication).

Use only immutable collections (Map, Set, List) — never mutable.Map,

mutable.Set, mutable.Buffer (mutable collections are fine in test fakes).

state => state functions; confine the var to the smallest scope.

(parameter or constructor) — never call them inside methods.

constructed — enums, ADTs, opaque types, Option for absence (never

null), smart constructors returning Either (not require)

enums — NEVER use raw primitives for domain concepts (identifiers,

quantities, configuration values).

try/catch. Exceptions only for unrecoverable errors that end the current

request/message.

Use-Case Guide

BEFORE writing code that uses Tapir, Ox, or sttp, or touches a topic listed

below, read the relevant chapter(s) in full. Follow every API and > Required /

> Important callout exactly — do NOT substitute another approach. Read the

chapter file from this skill's directory, or with a raw HTTP GET from the base

URL below — never via a tool that summarises the page (summaries drop callouts

and exact API calls).

https://raw.githubusercontent.com/virtuslab/scala-skill/refs/heads/master/direct-style-scala/skills/direct-style-scala/

Application Structure

Error Handling

HTTP & Endpoints

Data & Integration

Testing & Observability

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.