Skip to content

Commit a792922

Browse files
committed
update skills
1 parent 6e21738 commit a792922

3 files changed

Lines changed: 148 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: effect-ts-guide
3+
description: Teach and apply Effect-TS practices (effect, @effect/schema, @effect/platform) for architecture, typed errors, Layers, dependency injection, resource safety, testing, and migration from async/await/Promise. Use when a user asks how to use Effect, requests best practices, wants to refactor to Effect, or needs mapping from platform modules to Node/Bun/Browser APIs.
4+
---
5+
6+
# Effect TS Guide
7+
8+
## Overview
9+
10+
Use this skill to teach Effect-TS fundamentals and best practices, then apply them to user code and architecture questions.
11+
12+
## Teaching workflow
13+
14+
1. Clarify context: runtime (node/bun/browser), goal (new app, refactor, review), and constraints.
15+
2. Separate core vs shell: identify pure domain logic vs effects and boundaries.
16+
3. Model errors and dependencies: define tagged error types and Context.Tag service interfaces.
17+
4. Compose with Effect: use pipe/Effect.gen, typed errors, and Layer provisioning.
18+
5. Validate inputs at boundaries with @effect/schema before entering core.
19+
6. Explain resource safety: acquireRelease, scoped lifetimes, and clean finalizers.
20+
7. Provide minimal, runnable examples tailored to the user context.
21+
8. If the user asks for version-specific or "latest" details, verify with official docs before answering.
22+
23+
## Core practices (short list)
24+
25+
- Use Effect for all side effects; keep core functions pure and total.
26+
- Avoid async/await, raw Promise chains, and try/catch in application logic.
27+
- Use Context.Tag + Layer for dependency injection and testability.
28+
- Use tagged error unions and Match.exhaustive for total handling.
29+
- Decode unknown at the boundary with @effect/schema; never leak unknown into core.
30+
- Use Effect.acquireRelease/Effect.scoped for resource safety.
31+
- Use @effect/platform services instead of host APIs (fetch, fs, child_process, etc.).
32+
33+
## References
34+
35+
- Read `references/best-practices.md` for the extended checklist and examples.
36+
- Read `references/platform-map.md` when comparing @effect/platform to Node/Bun/Browser APIs.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Effect-TS Best Practices (concise)
2+
3+
## Design principles
4+
5+
- Keep core logic pure; isolate IO in a thin shell.
6+
- Model errors explicitly with tagged unions; avoid exceptions.
7+
- Prefer immutable data and total functions.
8+
9+
## Composition
10+
11+
- Use pipe + Effect.flatMap/map or Effect.gen for sequential flows.
12+
- Interop with Promise only at boundaries via Effect.try/Effect.tryPromise.
13+
- Use Match.exhaustive for union handling; avoid switch in domain logic.
14+
15+
## Dependency injection
16+
17+
- Define services with Context.Tag and small interfaces.
18+
- Provide live layers at runtime; provide test layers in unit tests.
19+
- Keep service interfaces free of concrete implementations and globals.
20+
21+
## Boundary validation
22+
23+
- Accept unknown at the boundary only.
24+
- Decode with @effect/schema and pass validated types into core.
25+
- Fail fast on invalid input; keep validation errors typed.
26+
27+
## Resource safety
28+
29+
- Use Effect.acquireRelease for resources (connections, files, locks).
30+
- Use Effect.scoped to control lifetimes and ensure finalizers run.
31+
32+
## Platform usage
33+
34+
- Use @effect/platform services instead of host APIs:
35+
- HttpClient/HttpServer for HTTP
36+
- FileSystem/Path for files and paths
37+
- Command/Terminal for CLI and processes
38+
- KeyValueStore for local storage-like needs
39+
40+
## Runtime and entrypoints
41+
42+
- Use Effect.runMain (or platform runtime helpers) for application entry.
43+
- Use Logger/PlatformLogger for structured logging.
44+
45+
## Testing
46+
47+
- Write tests as Effects; provide test layers/mocks.
48+
- Use TestClock/Ref for deterministic time and state.
49+
- Use property-based tests for invariants when appropriate.
50+
51+
## Minimal example (service + layer)
52+
53+
```ts
54+
import { Context, Effect, Layer, pipe } from "effect"
55+
56+
class Clock extends Context.Tag("Clock")<Clock, {
57+
readonly nowMillis: Effect.Effect<number, never>
58+
}>() {}
59+
60+
const ClockLive = Layer.succeed(Clock, {
61+
nowMillis: Effect.sync(() => Date.now())
62+
})
63+
64+
const program = pipe(
65+
Clock,
66+
Effect.flatMap((clock) => clock.nowMillis),
67+
Effect.map((ms) => ({ now: ms }))
68+
)
69+
70+
const main = Effect.provide(program, ClockLive)
71+
```
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# @effect/platform map (what it replaces)
2+
3+
## Core idea
4+
5+
- @effect/platform provides platform-neutral service interfaces and Layers.
6+
- It does not monkey-patch globals; you must provide a platform layer.
7+
8+
## Implementation packages
9+
10+
- Node: @effect/platform-node
11+
- Bun: @effect/platform-bun
12+
- Browser: @effect/platform-browser
13+
14+
## Common mappings
15+
16+
- FileSystem -> node:fs / fs.promises / Bun file APIs
17+
- Path -> node:path / Bun path / Deno path
18+
- Command (+ CommandExecutor) -> child_process.spawn/exec / Deno.Command / Bun.spawn
19+
- Terminal -> process.stdin/stdout / readline
20+
- KeyValueStore -> Map / localStorage / file-backed KV
21+
- PlatformConfigProvider -> dotenv + process.env + file tree config
22+
- PlatformLogger -> console + file logging
23+
- Runtime/runMain -> manual main + process signal handling
24+
25+
## HTTP stack
26+
27+
- HttpClient -> fetch / undici / axios
28+
- FetchHttpClient -> fetch implementation
29+
- HttpServer/HttpRouter/HttpMiddleware -> node:http + express/fastify/koa
30+
- HttpApi/OpenApi -> manual route + schema + OpenAPI toolchain
31+
32+
## Sockets and workers
33+
34+
- Socket/SocketServer -> net / ws / WebSocket
35+
- Worker/WorkerRunner -> worker_threads / Web Workers
36+
37+
## Data and utilities
38+
39+
- Headers/Cookies/Multipart/Etag -> manual header/cookie parsing or third-party middleware
40+
- Url/UrlParams -> URL / URLSearchParams
41+
- Ndjson/MsgPack -> ad-hoc codecs or third-party libs

0 commit comments

Comments
 (0)