DEV Community

AranaDeDoros
AranaDeDoros

Posted on

DDD and Typelevel cookbook

Hello everyone.

Scala's a programming language I've enjoyed learning on the side not only because I think it's stylish but because it's made me a better developer.

Some of the gripes you encounter once you try to go intermediate or beyond, it's the Typelevel stack complexity. You just want to bootstrap a server and start writing some routes, and tbh sometimes the docs aren't that friendly. That's why I wrote Scala 3 Domain Design & Typelevel Stack Cookbook — a book that teaches some DDD in Scala and gives you some recipes to get you started on the stack (cats, cats-effects, fs2, http4s).

It's a WIP currently at 40%. You can read a couple of chapters for free in leanpub: https://leanpub.com/scala3-domain-typestack-dev

Top comments (2)

Collapse
 
crdtcto profile image
Kane Lim

Hello Glad to see you, I am Kane Lim from Hong Kong. I have over 10 years of development experience. I am writing this because your post was interesting.

This addresses a real pain point in the Scala ecosystem. Typelevel becomes much easier once the abstractions are connected to concrete architectural boundaries rather than introduced as isolated type theory.

I would make the cookbook even stronger by organizing recipes around a vertical slice: domain algebra, smart constructors, effect boundaries, repository typeclasses, Cats Effect resource lifecycles, FS2 streaming, and http4s transport adapters. Showing where IO enters the architecture would also help readers understand why pure domain logic should remain effect agnostic.

A particularly useful addition would be property based testing with ScalaCheck and compile time guarantees around domain invariants. DDD combined with Scala's type system can eliminate entire classes of invalid states rather than merely detecting them at runtime.

Great initiative. Practical Typelevel material is genuinely valuable, and I would enjoy exchanging ideas around functional DDD architecture.

Collapse
 
aranadedoros profile image
AranaDeDoros • Edited

Hello Kim.

Thanks for commenting.

Those would make great additions indeed. That being said, they're a bit more complex than I want for this version. I do touch upon some of those topics, albeit briefly:

  • Bootstrapping an http4s Server
  • Routers — Defining, Composing and Merging Routes
  • Decoding & Validating Requests
  • Centralized Error Handling Middleware
  • JWT Authentication
  • Rate Limiting
  • Config, Logging & Structured Context
  • Wiring Your App as a Resource Graph
  • Concurrency Patterns: Fibers, Parallelism, Timeouts & Racing
  • Scheduled Jobs with fs2
  • Handling Uploaded and Returned Files Safely with fs2

Depending on the feedback, I might extend it, but only time and people will tell.