Files
ai-code-exploration/README.md
T

2.9 KiB

AI Code Exploration Exercise

A small C# application in the Active Record style, for practicing using coding agents to explore unfamiliar codebases.

What this is

The src/Before/ folder contains a small domain model (Client, Order) backed by a fake EF Core DbContext. The src/Before.Console/ project is a demo console app that seeds data and queries it.

You do not need to read or understand the code before starting. The point is to use a coding agent to produce diagrams that reveal the structure and behavior.

Prerequisites

  • A coding agent with access to this repo (Claude Code, Cursor, Copilot, etc.)
  • .NET SDK 10.0 (to build and run)
  • mmdc CLI for Mermaid rendering, or IDE Mermaid preview

Setup

  1. Clone this repo
  2. Open ai-code-exploration.sln in your IDE
  3. Build to verify everything compiles:
    dotnet build
    

Tasks

Use a coding agent to create diagrams of this codebase. Start broad, then iterate with follow-up prompts to refine.

Task 1: Class diagram (sanity check)

Prompt your agent to create a class diagram of the classes in src/Before/ using Mermaid. Iterate until you're satisfied it captures the structure accurately.

What to check: Are the inheritance relationships correct? Are the associations (Client → Orders, Order → Client) visible? Is the DbContext leak (domain objects reaching persistence) shown?

Task 2: Sequence diagram — happy path

Prompt your agent to create a sequence diagram for the flow when Client.FindByName("Jane Doe") is called. Show the interactions from the call site, through DbBase.Find<T>(), to the DbContext lookup, and the result returning.

Task 3: Sequence diagram — exception path

Prompt your agent to create a sequence diagram for Client.FindByNameRequired("Nobody") — when the client is not found. What interactions differ from the happy path? Where is ObjectNotFoundException thrown?

Task 4 (stretch): Full initialization flow

From Program.cs (the Console entry point), trace how the database gets initialized and what interactions happen on Client and Order entities. Include the exception flow from Task 3. This will be a larger diagram — iterate and simplify as needed.

Tips

  • Start broad, then refine: "Draw me a class diagram of src/Before/" is enough to start.
  • Iterate on the prompt: If the first diagram is missing something, ask the agent to add it. You don't need to write Mermaid syntax.
  • Validate: Use mmdc to check syntax, visually check the diagram against the code.
  • The skill is directing the agent, not writing diagrams by hand.

Background

This is the "before" code from a refactoring exercise (db-subclass-to-dto) where the Active Record pattern is extracted into a DTO + POCO design. The Active Record structure — with its DbContext leak through entity inheritance — is the kind of thing you want to understand before refactoring.