A tech lead is asked to make a shop's pricing reusable for a new point-of-sale system. To do that, the namespaces Shop.Pricing and Shop.Domain are to move out of the project Shop into a project of their own, Shop.Core. Today they share one project with Shop.Ordering and Shop.Infrastructure, and dotnet list reference reports no project reference at all. After the move, Shop.Core must not know anything in Shop, because Shop references Shop.Core. The solution and the code are constructed for this article; the output comes from real runs with CodeCharter v1.7.0 and .NET SDK 10.0.402. The type names resemble those in the article on prioritizing technical debt. The solution and the numbers are different.
Inside one project, the compiler does not hold the direction between namespaces. Any class in Shop.Pricing can use Shop.Ordering, and the build stays green. Only separate projects turn that into an error. After the move, the compiler reports references from Shop.Core to types in Shop as errors, for example CS0246. If someone adds the back reference from Shop.Core to Shop, the build stops with MSB4006 and a circular dependency. So the question is which back references already exist and how the tech lead finds them before moving any files.
Cycle between namespaces
graph cycles searches the coupling graph for groups of nodes that reach each other. Without further options, the command works at namespace level:
> codecharter graph cycles
Level: Namespaces. Totals: 4 node(s), 10 edge(s), 1 component(s), 2 node(s) in cycles.
Component 1 (size 2):
Members (2):
Shop.Ordering (Shop|Shop.Ordering) 5 type(s)
Shop.Pricing (Shop|Shop.Pricing) 5 type(s)
Shortest cycle: Shop|Shop.Ordering -> Shop|Shop.Pricing -> Shop|Shop.Ordering
Closing edges (2):
Shop|Shop.Pricing -> Shop|Shop.Ordering (weight 2, breaks)
Shop|Shop.Ordering -> Shop|Shop.Pricing (weight 3, breaks)
Shop.Ordering uses Shop.Pricing, and that is intended, because the order service computes prices. The edge Shop.Pricing -> Shop.Ordering with weight 2 blocks the move. The breaks marker says that removing it alone dissolves the cycle. With --level types, the same graph reports no cycle, because no chain of types leads back to its start. The back edge only becomes visible once the graph rolls types up into namespaces.
cycles does not name the types behind the edge, not even in JSON. The tech lead finds them with graph hubs --scope Shop.Pricing --sort-by fan_out, which ranks the namespace's types by outgoing edges. For the top candidates, graph neighborhood shows the targets:
> codecharter graph neighborhood LoyaltyDiscount --direction out --signatures none
Focus: Shop.Pricing.LoyaltyDiscount (class) .\src\Shop\Pricing\LoyaltyDiscount.cs:6
…
Uses (2):
Shop.Domain.Customer (record) .\src\Shop\Domain\Customer.cs:3 distance 1 [Uses]
Shop.Ordering.IOrderRepository (interface) .\src\Shop\Ordering\IOrderRepository.cs:5 distance 1 [Uses]
Calls (1):
Shop.Ordering.IOrderRepository (interface) .\src\Shop\Ordering\IOrderRepository.cs:5 distance 1 [Calls]
Weight 2 is exactly these two edges. LoyaltyDiscount receives IOrderRepository through its constructor and uses it to ask how many orders a customer has already placed. For PriceCalculator, neighborhood shows no edge to Shop.Ordering, although the file contains using Shop.Ordering;. The section on the limits of the graph explains why.
Cut inside the same project
The tech lead cuts the edge while everything still builds in one project. Shop.Pricing gets an interface of its own with exactly the method the discount needs:
namespace Shop.Pricing;
public interface ICustomerOrderHistory
{
int CountForCustomer(int customerId);
}
LoyaltyDiscount now takes an ICustomerOrderHistory. InMemoryOrderRepository in Shop.Infrastructure implements both interfaces, and the DI registration hands out the same instance for both. The build has no errors, and the program computes the same amount. graph diff compares the branch's graph with main, as the technical debt article does after a refactoring. With --level namespaces, the command rolls the edge lists up into namespaces:
> codecharter graph diff --base main --level namespaces
Base: main @ 1a7a98de915f3e9663b1abd16a70a23c00b65c4c. Head: (working tree) @ ?.
Nodes: 17 -> 18 (+1/-0). Edges: 26 -> 27 (+1/-2/~0).
Added nodes (1):
+ Shop.Pricing.ICustomerOrderHistory (interface)
Removed nodes (0):
Added edges (1):
+ Shop|Shop.Infrastructure -Implements-> Shop|Shop.Pricing (weight=1)
Removed edges (2):
- Shop|Shop.Pricing -Uses-> Shop|Shop.Ordering (weight=1)
- Shop|Shop.Pricing -Calls-> Shop|Shop.Ordering (weight=1)
…
The Nodes and Edges lines count types and edges between types; only the lists below them are rolled up. That is why 26 plus 1 minus 2 does not give 27. The new edge points from Shop.Infrastructure to Shop.Pricing, the direction that is allowed after the move. graph cycles then reports "0 component(s)". For the 17 types of the example, the first comparison against main took 36.9 seconds. CodeCharter creates a separate checkout for it, restores the packages and analyzes it. A second run against the same base came from the cache after 8.3 seconds.
Limits of the graph
Empty output from graph cycles only means that no captured edge points back any more. Edges come from inheritance, interfaces, types in signatures, resolved method calls, attributes and object creations. PriceCalculator, however, reads a constant from Shop.Ordering and calls a rounding helper for the older target framework:
var discount = Math.Min(discounts.Sum(policy => policy.RateFor(order.Customer)), OrderingDefaults.MaxDiscountRate);
var gross = net * (1 - discount) * (1 + taxRates.RateFor(order.Customer.CountryCode));
#if NET9_0
return LegacyRounding.Round(gross);
#else
return Math.Round(gross, 2, MidpointRounding.ToEven);
#endif
Reading the constant is not a method call and appears in no signature. graph impact OrderingDefaults therefore reports "No dependents found." The project builds for net10.0 and net9.0, but the graph models only net10.0. It does not know the call in the #if NET9_0 branch, and graph impact LegacyRounding reports no dependents either. Every run states this gap on stderr:
Project '…\src\Shop\Shop.csproj' targets several frameworks and was modelled for net10.0 only (not for net9.0): types, members, metrics and relations that exist only under #if for those targets are not modelled; analyzer diagnostics still cover every target.
A third reference sits in a string. PricingPlugins loads an extra discount with Type.GetType("Shop.Ordering.SeasonalRebate"). There is no edge for it, and the compiler does not see the name either. A text search on the branch with the cut finds all three remaining references in seconds:
> git grep -n "Shop\.Ordering\|OrderingDefaults\|LegacyRounding" -- src/Shop/Pricing src/Shop/Domain
src/Shop/Pricing/PriceCalculator.cs:2:using Shop.Ordering;
src/Shop/Pricing/PriceCalculator.cs:11: var discount = Math.Min(discounts.Sum(policy => policy.RateFor(order.Customer)), OrderingDefaults.MaxDiscountRate);
src/Shop/Pricing/PriceCalculator.cs:14: return LegacyRounding.Round(gross);
src/Shop/Pricing/PricingPlugins.cs:5: private static readonly string[] PluginTypeNames = ["Shop.Ordering.SeasonalRebate"];
The type names in the search pattern, however, come from knowing the case. Without that knowledge, the tech lead searches only for Shop.Ordering. On the same branch that yields two hits, the using line in PriceCalculator.cs and the string in PricingPlugins.cs. Both lead to the other places, but only the build delivers the complete set.
DI registrations are missing from the graph for a similar reason. services.AddScoped<IDiscountPolicy, LoyaltyDiscount>() passes the types as type arguments to a method outside the solution. graph impact LoyaltyDiscount --no-through-implementations therefore reports no dependents, although ServiceRegistration registers the class. Without the option, ServiceRegistration does appear in the list, but only because it calls PricingPlugins. For the move the gap is harmless, because the registration points from Shop to Shop.Core. Anyone who wants to delete LoyaltyDiscount, however, does not find the registering code this way.
Trial build and run
The compiler checks the move itself more thoroughly than the graph does. In the example, the move was played once without a prior cut, starting straight from main: new project, git mv of both folders, a reference from Shop to Shop.Core. The build reported the back references in waves. After each build the team fixed what was reported, after the first one with the cut from the previous section:
| Build | Errors | Reported or fixed |
|---|---|---|
| 1 | 6 | using Shop.Ordering in LoyaltyDiscount.cs and PriceCalculator.cs, IOrderRepository in the constructor, per target framework |
| 2 | 2 | using Shop.Ordering in PriceCalculator.cs, per target framework |
| 3 | 3 | OrderingDefaults for both target frameworks, LegacyRounding only for net9.0 |
| 4 | 0 | constant moved to Shop.Pricing.PricingDefaults, LegacyRounding moved to Shop.Core |
The third build reports CS0103 for LegacyRounding only for net9.0, because the compiler builds each target framework separately. The errors from method bodies only appeared once the using lines were resolved. After the green build, the first run failed:
> dotnet run --project src/Shop -f net10.0 --no-build
Unhandled exception. System.InvalidOperationException: Discount plugin 'Shop.Ordering.SeasonalRebate' not found.
at Shop.Pricing.PricingPlugins.Load()+MoveNext() in …\src\Shop.Core\Pricing\PricingPlugins.cs:line 11
…
Type.GetType with a name without an assembly no longer found the type once the call came from Shop.Core. The name "Shop.Ordering.SeasonalRebate, Shop" got the run through, but it wrote the assembly name Shop into Shop.Core, which is exactly the back reference the move is meant to avoid. The point-of-sale system would have inherited this plugin name. The team therefore reversed the direction: PricingPlugins.Load now takes an assembly and the type names, and ServiceRegistration in Shop passes both. After that, both target frameworks ran, and git grep finds neither Shop.Ordering nor , Shop in src/Shop.Core.
Without the graph, the team also reached the goal, with four builds, one runtime error and one fix to the plugin loading. The graph does not save the trial build. It shows which edge points back before the first file moves, and the cut can be built and tested inside the same project. After the cut, the move in the example took three builds with 2, 3 and 0 errors and one failing run.
Boundary in the pull request
Weeks can pass between the cut and the move, and during that time the build does not protect the boundary. In the example, a later branch adds a ReorderDiscount that uses IOrderRepository again. The build is green, and graph diff shows the back edge but exits with 0:
> codecharter graph diff --base refactor/pricing-seam --head HEAD --level namespaces
…
Added edges (2):
+ Shop|Shop.Pricing -Uses-> Shop|Shop.Ordering (weight=1)
+ Shop|Shop.Pricing -Calls-> Shop|Shop.Ordering (weight=1)
…
For a gate, the team records the direction as a rule of its own:
@name "Pricing does not depend on Ordering"
@severity error
@category "Architecture"
…
from t in Types
where t.Namespace.FullName == "Shop.Pricing"
&& t.UsedTypes.Any(u => u.Namespace.FullName == "Shop.Ordering")
select t
codecharter analyze Shop.slnx --rules .codecharter/boundary --rules-only reports the class ReorderDiscount as an error on the feature branch and exits with 1. On the branch with the cut, the same call exits with 0. The call checks the whole solution, not only the pull request's diff. UsedTypes counts only signatures, so the rule does not report the constant in PriceCalculator either. After the move the rule becomes unnecessary, because MSBuild then holds the project boundary. graph cycles remains useful for the namespaces that stayed in the project Shop.
Coding agents get the same queries as MCP tools, for example graph_cycles and graph_diff, and max_tokens limits the size of the answer. According to the documentation, the first graph_diff against a new base immediately returns isPending: true and computes in the background. The agent then calls it again with the same values. The notices in every answer name the multi-targeting gap and describe the edges as signatures and resolved calls. They do not mention constants or reflection. An agent that extracts a namespace therefore builds and starts the application for every target framework after the cut before it takes an empty graph_cycles as proof.