# Building an Agentic Software Factory with Skills and OpenTelemetry

> Pair AGENTS.md, 8 composable SKILL.md workflows, 59 verification gates, and local Aspire OpenTelemetry traces so AI coding agents ship safely.

Kind: Lab · Reviewed: 2026-12-02 · Author: Milan Jovanović
Canonical: https://modularmonolith.com/guides/agentic-software-factory/
Reference Repository: https://github.com/m-jovanovic/modular-monolith/tree/3c8d0cf5601d287b645c1ca59b7b3e811659ec74

An **Agentic Software Factory** turns a well-structured modular monolith into a self-verifying environment for AI coding agents (Claude Code, Codex, Antigravity, Cursor). Orbit combines a concise root `AGENTS.md`, eight task-specific `SKILL.md` playbooks, 59 automated build/architecture/database gates, and end-to-end OpenTelemetry wired to a local Aspire Dashboard.

## Give agents task-scoped skills instead of 5,000-line prompts

Dumping every rule into one giant prompt wastes context and dilutes compliance. Orbit keeps root `AGENTS.md` focused on non-negotiable invariants and routes specific engineering tasks to `.agents/skills/`:

| Task | Skill Path | What It Enforces |
| --- | --- | --- |
| Re-target repo to a new business domain | `.agents/skills/domain-adaptation/SKILL.md` | Bounded context mapping, schema naming, replacing sample commerce modules |
| Add a new module end-to-end | `.agents/skills/scaffold-module/SKILL.md` | 5 projects, schema registration, Outbox/Inbox migrations, Dockerfile, ArchTests |
| Implement a feature slice | `.agents/skills/add-vertical-slice/SKILL.md` | DDD aggregate `Result<T>`, EF Core write + FluentValidation, Dapper read, `IEndpoint` |
| Wire async events or `PublicApi` | `.agents/skills/cross-module-messaging/SKILL.md` | Domain event -> Outbox -> `Orbit.Common.EventBus` topic -> Idempotent Inbox |
| Plug in Clerk, Auth0, Entra, or Keycloak | `.agents/skills/configure-auth-idp/SKILL.md` | External OIDC authentication + JIT user sync + internal RBAC `IPermissionService` |

## Close the runtime loop with OpenTelemetry and Aspire

Static checks catch compile-time and schema mistakes, but asynchronous sagas fail at *runtime*. In Orbit, `InsertOutboxMessagesInterceptor` stores `Activity.Current?.Id` (`trace_parent`) on every `OutboxMessage`. When `ModuleOutboxProcessor` relays the event to `ChannelEventBus`, producer and consumer spans link back to the originating HTTP request.

Boot the stack and inspect live traces and channel telemetry:

```sh
docker compose up -d --build
curl -s http://localhost:5000/api/system/architecture | jq
# Open Aspire Dashboard UI at http://localhost:18888
```

Both human engineers and AI agents can query `/api/system/architecture` (active module schemas, topic subscriptions, delivered/retried/dead-lettered counts) and inspect distributed traces in Aspire (`http://localhost:18888`) to verify every async hop.

## Summary

- Keep `AGENTS.md` short and modularize procedural workflows into `.agents/skills/<skill>/SKILL.md`.
- Never allow agents to weaken `Orbit.ArchitectureTests` or `TreatWarningsAsErrors=true` to make a failing change pass.
- Propagate W3C `trace_parent` through Outbox and EventBus messages into local Aspire OpenTelemetry so agents debug runtime behavior with real evidence.

## Frequently asked questions

### Why do AI coding agents struggle in traditional monoliths without a software factory setup?

Without explicit schema rules, vertical-slice templates, and runtime traces, agents take the shortest path that compiles: joining foreign tables, swallowing errors with exceptions, and guessing why async sagas stall.

### How does sharing OpenTelemetry with coding agents improve reliability?

Orbit propagates W3C trace_parent through PostgreSQL outbox_messages into ChannelEventBus spans and exports Traces, Metrics, and Structured Logs to a local Aspire Dashboard, letting agents inspect exact async failure spans instead of coding blind.

