
zio-config
by connectstrata
Skill files for coding agents working with Scala
SKILL.md
name: zio-config description: Standardized patterns for creating and reading ZIO configuration using zio-config with magnolia derivation. Use when creating new configuration classes, reading configuration values, or refactoring existing config code to follow project standards.
ZIO Config Pattern
Overview
Use these patterns to maintain consistency across the codebase when working with ZIO configuration.
Config Definition Pattern
Create config classes following this structure:
- Wrapper case class - Define a final case class containing the config values
- Given Config[T] - Create using
deriveConfig[T]fromzio.config.magnolia - Namespace nesting - Nest config under appropriate namespaces using
.nested() - Strong typing - Parse values to domain types with custom
DeriveConfig[T]instances
Namespace Nesting
Important: zio-config applies nested() parameters in reverse order.
given config: Config[GraphqlCorsConfig] = deriveConfig[GraphqlCorsConfig]
.nested("cors")
.nested("graphql")
This searches the graphql.cors namespace (not cors.graphql).
Examples
Simple config:
final case class GraphqlCorsConfig(allowedOrigin: String)
object GraphqlCorsConfig {
given config: Config[GraphqlCorsConfig] =
deriveConfig[GraphqlCorsConfig]
.nested("cors")
.nested("graphql")
}
Config with strong types:
case class ConnectionSecretsServiceConfig(namespace: String, kmsKeyArn: Arn)
object ConnectionSecretsServiceConfig {
given arnConfig: DeriveConfig[Arn] =
DeriveConfig[String].map(Arn.fromString)
given config: Config[ConnectionSecretsServiceConfig] =
deriveConfig[ConnectionSecretsServiceConfig]
.nested("connection-secrets-service")
}
Prompt for namespace - When creating new configs, ask the user which namespace to nest the config under.
Config Reading Pattern
Use ZIO.config[T] to read configuration values.
Simple ZLayer
For layers with constructor dependencies, use ZLayer.derive[T]:
final case class MyService(config: MyConfig, otherDep: OtherService)
object MyService {
val layer: ZLayer[OtherService, Config.Error, MyService] =
ZLayer.derive[MyService]
}
The macro automatically calls ZIO.config[MyConfig] when constructing the service.
Complex ZLayer
For layers requiring custom initialization logic, use ZLayer.fromZIO with ZIO.config[T]:
val devLayer: ZLayer[Any, Config.Error, DynamoDbClient] = ZLayer.fromZIO {
for {
config <- ZIO.config[LocalDynamoDbConfig]
tables <- DynamoDbConfig.tables
client = DynamoDbClient
.builder()
.endpointOverride(URI.create(s"http://${config.host}:${config.port}"))
.credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create("dummyKey", "dummySecret")
)
)
.region(US_EAST_1)
.build()
_ = LocalDynamoDb.createTablesIfNotExists(client, tables)
} yield client
}
Required Imports
import zio.Config
import zio.config.magnolia.deriveConfig
For strong typing:
import zio.config.magnolia.DeriveConfig
スコア
総合スコア
リポジトリの品質指標に基づく評価
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
レビュー
レビュー機能は近日公開予定です