effect-best-practices

Enforces Effect-TS patterns for services, errors, layers, and React atoms.

Updated Sep 5, 2023
One-click install
npx skills add https://github.com/eyenalxai/dotfiles --skill effect-best-practices-eyenalxai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: effect-best-practices
Source: https://github.com/eyenalxai/dotfiles/tree/main/.agents/skills/effect-best-practices
Command: npx skills add https://github.com/eyenalxai/dotfiles --skill effect-best-practices-eyenalxai

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Effect-TS codebases often drift into inconsistent patterns: generic errors that lose context, deeply nested Layer compositions that slow the TypeScript language server, and React state managed imperatively. This Skill enforces a single opinionated set of conventions so services, errors, schemas, and atoms stay type-safe, testable, and observable. ## Core Features & Use Cases - Service & Layer Conventions: Mandates Effect.Service with accessors and declared dependencies, Layer.mergeAll for flat composition, and Layer.provideMerge to avoid nested types that degrade LSP performance. - Explicit Error Modeling: Requires Schema.TaggedError with rich context fields and catchTag/catchTags handling, forbidding generic NotFoundError-style collapses so frontends can render specific UI per failure. - Effect Atom React Patterns: Covers Atom.make, families, keepAlive, Result.builder rendering with onErrorTag, mutation loading via result.waiting, and reactivityKeys cache invalidation. - Use Case: When writing a new UserService with Effect.Service, wiring it into the app root with Layer.mergeAll, and building a React profile component with useAtomValue and Result.builder, this Skill ensures every step follows the enforced conventions. ## Quick Start Ask the assistant to review or write Effect-TS code such as a service, error type, layer composition, or atom-based React component following these best practices.

Frequently Asked Questions about effect-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define a service in Effect-TS?

Use Effect.Service with accessors set to true and declare dependencies in the dependencies array so layers wire automatically. Define methods with Effect.fn for automatic tracing, and compose everything at the app root with Layer.mergeAll.

How should I handle errors in Effect-TS applications?

Define errors with Schema.TaggedError including a message field and rich context like entity IDs, then handle them with Effect.catchTag or catchTags. Avoid catchAll and mapError because they discard type information needed for specific handling.

What is the Effect Language Server and do I need it?

The Effect Language Server is a TypeScript plugin (@effect/language-service) that detects Effect-specific issues like floating Effects and missing requirements at edit time. Install it as a devDependency and register it in tsconfig.json compilerOptions plugins.

How do I manage React state with effect-atom?

Define atoms outside components with Atom.make, add Atom.keepAlive for persistent global state, and use useAtomValue and useAtomSet hooks in components. Render async results with Result.builder using onErrorTag for typed error handling.

Why is Layer.mergeAll preferred over nested Layer.provide?

Layer.mergeAll produces flat compositions with simpler types, keeping the TypeScript language server fast, while deeply nested Layer.provide chains create recursive types that slow the LSP. Layers also memoize construction so shared services instantiate only once.

When is Context.Tag acceptable instead of Effect.Service?

Context.Tag is acceptable for infrastructure with runtime injection, such as Cloudflare KV or worker bindings, and for factory patterns where resources are provided externally. Business logic services should always use Effect.Service for built-in accessors and Default layers.