Skip to content

Service Maps

The service map diagram shows which Context.Tag services your Effect program depends on and how steps in the program consume those services. For project-wide analysis, the --service-map flag produces a deduplicated registry of all services across your codebase.

Service dependency map showing transfer program depending on AccountRepo and AuditLog

Terminal window
npx effect-analyze ./src/transfer.ts --format mermaid-services

This produces a Mermaid diagram that groups steps by the services they require. Each service appears as a node, with edges connecting it to the steps that consume it.

For a program that depends on AccountService and AuditLog:

graph TB
subgraph Services
S1[AccountService]
S2[AuditLog]
end
S1 --> getBalance
S1 --> debit
S1 --> credit
S2 --> audit.record

Auto mode includes a service map when your program has two or more distinct Context.Tag dependencies. Programs with a single service or no services skip this view in favor of more relevant diagrams.

When analyzing a directory, use --service-map to discover all services across the project and see which files consume them:

Terminal window
npx effect-analyze ./src --service-map

This deduplicates services that appear in multiple files and produces a consolidated registry showing:

  • Every Context.Tag defined in the project
  • Which files provide implementations (via Layer)
  • Which files consume the service (via yield* or Effect.provideService)

Generate service maps through the library API:

import { analyze, renderServiceGraphMermaid } from "effect-analyzer"
import { Effect } from "effect"
const ir = await Effect.runPromise(analyze("./src/transfer.ts").single())
const diagram = renderServiceGraphMermaid(ir)
console.log(diagram)

For project-wide analysis:

import { buildProjectServiceMap } from "effect-analyzer"
const serviceMap = buildProjectServiceMap(allIRs)
// serviceMap.services - Map of service name to ServiceArtifact

The ServiceArtifact type contains:

  • tagName - the Context.Tag identifier
  • providers - files and layers that provide an implementation
  • consumers - files and steps that consume the service

When running in directory mode with --colocate, each generated .effect-analysis.md file includes the service dependencies for that file’s programs:

Terminal window
npx effect-analyze ./src --colocate

This writes a *.effect-analysis.md file next to each source file, containing diagrams, complexity metrics, and the service dependency list.