Service Mapper
Analyze a codebase and produce a structured, AI-agent-friendly service map. The output documents every microservice, how they communicate, what databases and tables they own, and what external systems they integrate with.
When to Use
- Onboarding to an unfamiliar codebase
- Generating or updating a CLAUDE.md or SERVICE-MAP.md
- Before planning a new feature (understand what exists)
- Auditing service boundaries and ownership
- Detecting architectural violations (shared DBs, direct HTTP between services, etc.)
- After significant refactoring to verify the architecture still makes sense
Workflow
Execute these steps in order. Each step builds on the previous.
Step 1: Identify Service Boundaries
Scan the repository structure to find all deployable units (services, workers, lambdas, cron jobs).
What to look for:
| Signal |
Examples |
| Entrypoints |
main.go, main.ts, index.ts, app.py, Program.cs, main.rs |
| Build configs |
Dockerfile, docker-compose.yaml, serverless.yml, app.yaml |
| Package manifests |
package.json, go.mod, Cargo.toml, pom.xml, *.csproj |
| Deployment specs |
K8s manifests, Terraform, Helm charts, DO app specs |
| Monorepo markers |
packages/, services/, apps/, cmd/, internal/ |
For each service, record:
- Name
- Language / framework
- Entrypoint file
- Port (if HTTP)
- Type:
webservice | worker | cron | lambda | gateway
Step 2: Map Inter-Service Communication
For each service, trace how it talks to other services.
Communication patterns to detect:
| Pattern |
How to Find |
| REST / HTTP |
Look for HTTP client calls, fetch, axios, http.Get, base URLs pointing to other services |
| Message bus (RabbitMQ, Kafka, NATS, SQS) |
Look for publish, subscribe, consume, queue names, exchange declarations, topic subscriptions |
| gRPC |
Look for .proto files, gRPC client/server setup, grpc.Dial |
| Shared library / SDK |
Look for internal packages imported across services (e.g., DatabaseClient, shared types) |
| Direct function calls |
In monoliths or tightly coupled services — function imports across module boundaries |
| Event contracts |
Shared schema definitions (Zod, Protobuf, Avro, JSON Schema) that define inter-service messages |
For each connection, record:
- Source service
- Target service
- Protocol (HTTP / AMQP / gRPC / SDK / etc.)
- Direction (unidirectional / request-response / pub-sub)
- What data flows (event names, endpoint paths, RPC methods)
Step 3: Map Database Ownership
Identify every database, schema, or table and determine which service owns it.
What to look for:
| Signal |
Examples |
| DB connection strings |
DATABASE_URL, SUPABASE_URL, MONGO_URI, connection config |
| ORM models / migrations |
Prisma schema, TypeORM entities, GORM models, Alembic migrations, Knex migrations |
| Raw SQL |
CREATE TABLE, SELECT FROM, table names in queries |
| DB client imports |
Which services import the DB client or ORM? |
| Gateway pattern |
Does one service proxy DB access for others? |
For each data store, record:
- Type (PostgreSQL, MongoDB, Redis, S3, etc.)
- Tables / collections (list them)
- Owner service (the service that writes to it)
- Reader services (services that read from it — directly or via gateway)
- Access pattern:
direct | via-gateway-service | via-message-bus
Flag violations:
- Multiple services writing to the same table (shared mutable state)
- Services bypassing a DB gateway to access the database directly
- No clear owner for a table
Step 4: Map External Integrations
Find every connection to systems outside the codebase.
What to look for:
| Signal |
Examples |
| API clients |
REST clients, SDK imports, webhook handlers |
| API keys / secrets |
Environment variables like *_API_KEY, *_SECRET, *_TOKEN |
| External URLs |
Hardcoded or configured URLs to third-party services |
| Webhook endpoints |
Routes that receive callbacks from external systems |
For each integration, record:
- External system name (e.g., Stripe, SendGrid, S3)
- Which service connects to it
- Direction:
outbound (we call them) | inbound (they call us) | bidirectional
- Auth method (API key, OAuth, mTLS, etc.)
- Data exchanged (what we send/receive)
Step 5: Trace Event Flows
For event-driven architectures, map the full lifecycle of key events.
For each event type:
- Publisher (which service emits it)
- Subscribers (which services consume it)
- Payload schema (or reference to contract)
- What triggers the event
- What downstream effects it causes
Build 3-5 critical flow diagrams showing end-to-end event chains (e.g., "user action → ingestion → processing → storage → notification").
Step 6: Generate the Service Map
Produce the output document using the structure in TEMPLATES.md.
Discovery Commands
Use these to accelerate analysis. Adapt to the project's language/framework.
Find entrypoints
# Go
find . -name "main.go" -not -path "*/vendor/*"
# Node/TypeScript
find . -name "index.ts" -path "*/src/*" -not -path "*/node_modules/*"
# Python
find . -name "main.py" -o -name "app.py" -o -name "wsgi.py" | grep -v __pycache__
Find message bus usage
# RabbitMQ / AMQP
grep -rn "publish\|subscribe\|consume\|createChannel\|assertQueue\|assertExchange" --include="*.ts" --include="*.go" --include="*.py"
# Kafka
grep -rn "producer\|consumer\|KafkaClient\|kafka.NewReader\|kafka.NewWriter" --include="*.ts" --include="*.go" --include="*.py"
# Event type constants
grep -rn "EVENT_TYPE\|event_type\|EventType\|ROUTING_KEY\|routing_key" --include="*.ts" --include="*.go" --include="*.py"
Find database access
# Table names in SQL
grep -rn "FROM \|INTO \|UPDATE \|CREATE TABLE\|ALTER TABLE" --include="*.ts" --include="*.go" --include="*.py" --include="*.sql"
# ORM models
grep -rn "Entity\|@Table\|@Model\|tableName\|__tablename__" --include="*.ts" --include="*.py" --include="*.java"
# DB connection setup
grep -rn "DATABASE_URL\|SUPABASE_URL\|MONGO_URI\|createConnection\|createPool\|getConnection" --include="*.ts" --include="*.go" --include="*.py" --include="*.env*"
Find external API calls
# HTTP clients
grep -rn "axios\|fetch(\|http.Get\|http.Post\|requests.get\|requests.post\|HttpClient" --include="*.ts" --include="*.go" --include="*.py"
# API keys in env
grep -rn "API_KEY\|API_SECRET\|_TOKEN\|_SECRET" --include="*.env*" --include="*.yaml" --include="*.ts"
Find deployment configs
# Docker
find . -name "Dockerfile" -o -name "docker-compose*.yaml" -o -name "docker-compose*.yml"
# Kubernetes
find . -name "*.yaml" -path "*/k8s/*" -o -name "*.yaml" -path "*/deploy*/*"
# Serverless
find . -name "serverless.yml" -o -name "serverless.ts"
# Cloud platform
find . -name "app.yaml" -o -name "app.spec.yaml" -o -name "*.tf"
Quality Checks
Before presenting the service map, verify:
Supporting Files
- TEMPLATES.md — Output format and examples for the service map
1---2name: service-mapper3description: Analyze a codebase to produce a complete service map — microservices, inter-service communication, database ownership, external integrations, and event flows. Generates AI-agent-friendly markdown. Use when onboarding to a new codebase, auditing architecture, updating CLAUDE.md, or before planning new features. Triggers on "map services", "service map", "map the architecture", "what services exist", "how do services communicate", "map this repo", "generate service map", "architecture map".4---56# Service Mapper78Analyze a codebase and produce a structured, AI-agent-friendly service map. The output documents every microservice, how they communicate, what databases and tables they own, and what external systems they integrate with.910## When to Use1112- Onboarding to an unfamiliar codebase13- Generating or updating a CLAUDE.md or SERVICE-MAP.md14- Before planning a new feature (understand what exists)15- Auditing service boundaries and ownership16- Detecting architectural violations (shared DBs, direct HTTP between services, etc.)17- After significant refactoring to verify the architecture still makes sense1819## Workflow2021Execute these steps in order. Each step builds on the previous.2223### Step 1: Identify Service Boundaries2425Scan the repository structure to find all deployable units (services, workers, lambdas, cron jobs).2627**What to look for:**2829| Signal | Examples |30|--------|----------|31| Entrypoints | `main.go`, `main.ts`, `index.ts`, `app.py`, `Program.cs`, `main.rs` |32| Build configs | `Dockerfile`, `docker-compose.yaml`, `serverless.yml`, `app.yaml` |33| Package manifests | `package.json`, `go.mod`, `Cargo.toml`, `pom.xml`, `*.csproj` |34| Deployment specs | K8s manifests, Terraform, Helm charts, DO app specs |35| Monorepo markers | `packages/`, `services/`, `apps/`, `cmd/`, `internal/` |3637**For each service, record:**38- Name39- Language / framework40- Entrypoint file41- Port (if HTTP)42- Type: `webservice` | `worker` | `cron` | `lambda` | `gateway`4344### Step 2: Map Inter-Service Communication4546For each service, trace how it talks to other services.4748**Communication patterns to detect:**4950| Pattern | How to Find |51|---------|-------------|52| **REST / HTTP** | Look for HTTP client calls, `fetch`, `axios`, `http.Get`, base URLs pointing to other services |53| **Message bus (RabbitMQ, Kafka, NATS, SQS)** | Look for `publish`, `subscribe`, `consume`, queue names, exchange declarations, topic subscriptions |54| **gRPC** | Look for `.proto` files, gRPC client/server setup, `grpc.Dial` |55| **Shared library / SDK** | Look for internal packages imported across services (e.g., `DatabaseClient`, shared types) |56| **Direct function calls** | In monoliths or tightly coupled services — function imports across module boundaries |57| **Event contracts** | Shared schema definitions (Zod, Protobuf, Avro, JSON Schema) that define inter-service messages |5859**For each connection, record:**60- Source service61- Target service62- Protocol (HTTP / AMQP / gRPC / SDK / etc.)63- Direction (unidirectional / request-response / pub-sub)64- What data flows (event names, endpoint paths, RPC methods)6566### Step 3: Map Database Ownership6768Identify every database, schema, or table and determine which service owns it.6970**What to look for:**7172| Signal | Examples |73|--------|----------|74| DB connection strings | `DATABASE_URL`, `SUPABASE_URL`, `MONGO_URI`, connection config |75| ORM models / migrations | Prisma schema, TypeORM entities, GORM models, Alembic migrations, Knex migrations |76| Raw SQL | `CREATE TABLE`, `SELECT FROM`, table names in queries |77| DB client imports | Which services import the DB client or ORM? |78| Gateway pattern | Does one service proxy DB access for others? |7980**For each data store, record:**81- Type (PostgreSQL, MongoDB, Redis, S3, etc.)82- Tables / collections (list them)83- Owner service (the service that writes to it)84- Reader services (services that read from it — directly or via gateway)85- Access pattern: `direct` | `via-gateway-service` | `via-message-bus`8687**Flag violations:**88- Multiple services writing to the same table (shared mutable state)89- Services bypassing a DB gateway to access the database directly90- No clear owner for a table9192### Step 4: Map External Integrations9394Find every connection to systems outside the codebase.9596**What to look for:**9798| Signal | Examples |99|--------|----------|100| API clients | REST clients, SDK imports, webhook handlers |101| API keys / secrets | Environment variables like `*_API_KEY`, `*_SECRET`, `*_TOKEN` |102| External URLs | Hardcoded or configured URLs to third-party services |103| Webhook endpoints | Routes that receive callbacks from external systems |104105**For each integration, record:**106- External system name (e.g., Stripe, SendGrid, S3)107- Which service connects to it108- Direction: `outbound` (we call them) | `inbound` (they call us) | `bidirectional`109- Auth method (API key, OAuth, mTLS, etc.)110- Data exchanged (what we send/receive)111112### Step 5: Trace Event Flows113114For event-driven architectures, map the full lifecycle of key events.115116**For each event type:**117- Publisher (which service emits it)118- Subscribers (which services consume it)119- Payload schema (or reference to contract)120- What triggers the event121- What downstream effects it causes122123Build 3-5 critical flow diagrams showing end-to-end event chains (e.g., "user action → ingestion → processing → storage → notification").124125### Step 6: Generate the Service Map126127Produce the output document using the structure in [TEMPLATES.md](TEMPLATES.md).128129---130131## Discovery Commands132133Use these to accelerate analysis. Adapt to the project's language/framework.134135### Find entrypoints136```bash137# Go138find . -name "main.go" -not -path "*/vendor/*"139140# Node/TypeScript141find . -name "index.ts" -path "*/src/*" -not -path "*/node_modules/*"142143# Python144find . -name "main.py" -o -name "app.py" -o -name "wsgi.py" | grep -v __pycache__145```146147### Find message bus usage148```bash149# RabbitMQ / AMQP150grep -rn "publish\|subscribe\|consume\|createChannel\|assertQueue\|assertExchange" --include="*.ts" --include="*.go" --include="*.py"151152# Kafka153grep -rn "producer\|consumer\|KafkaClient\|kafka.NewReader\|kafka.NewWriter" --include="*.ts" --include="*.go" --include="*.py"154155# Event type constants156grep -rn "EVENT_TYPE\|event_type\|EventType\|ROUTING_KEY\|routing_key" --include="*.ts" --include="*.go" --include="*.py"157```158159### Find database access160```bash161# Table names in SQL162grep -rn "FROM \|INTO \|UPDATE \|CREATE TABLE\|ALTER TABLE" --include="*.ts" --include="*.go" --include="*.py" --include="*.sql"163164# ORM models165grep -rn "Entity\|@Table\|@Model\|tableName\|__tablename__" --include="*.ts" --include="*.py" --include="*.java"166167# DB connection setup168grep -rn "DATABASE_URL\|SUPABASE_URL\|MONGO_URI\|createConnection\|createPool\|getConnection" --include="*.ts" --include="*.go" --include="*.py" --include="*.env*"169```170171### Find external API calls172```bash173# HTTP clients174grep -rn "axios\|fetch(\|http.Get\|http.Post\|requests.get\|requests.post\|HttpClient" --include="*.ts" --include="*.go" --include="*.py"175176# API keys in env177grep -rn "API_KEY\|API_SECRET\|_TOKEN\|_SECRET" --include="*.env*" --include="*.yaml" --include="*.ts"178```179180### Find deployment configs181```bash182# Docker183find . -name "Dockerfile" -o -name "docker-compose*.yaml" -o -name "docker-compose*.yml"184185# Kubernetes186find . -name "*.yaml" -path "*/k8s/*" -o -name "*.yaml" -path "*/deploy*/*"187188# Serverless189find . -name "serverless.yml" -o -name "serverless.ts"190191# Cloud platform192find . -name "app.yaml" -o -name "app.spec.yaml" -o -name "*.tf"193```194195## Quality Checks196197Before presenting the service map, verify:198199- [ ] Every service has a clear type (webservice/worker/cron/lambda/gateway)200- [ ] Every inter-service connection has protocol and direction documented201- [ ] Every database table has exactly one owner service identified202- [ ] Every external integration has the connecting service identified203- [ ] No orphan services (services with zero connections — likely missed something)204- [ ] Event flows cover the critical business paths205- [ ] ASCII diagrams are present for high-level architecture and key flows206- [ ] The map is self-contained — an AI agent can understand the architecture without reading code207208## Supporting Files209210- [TEMPLATES.md](TEMPLATES.md) — Output format and examples for the service map