Axiomatic Reasoning for LLMs

Implementation Plan on C Sharp

1. Core Principles to C# Mapping

Principle C# Implementation Tooling
Structural Separation OpenAPI contracts + interface definitions Microsoft.AspNetCore.OpenApi, TypeSpec
Generative Conformance Source Generators (compile-time code generation) Roslyn Generator API
Skeleton–Tissue Separation Partial classes + template methods + DI C# partial classes, sealed methods
Validation Gates Roslyn analyzers + architecture tests NetArchTest, ArchUnitNET
Recursive Refinement Incremental builds + Git worktrees + assembly verification Incrementalist, ApiCompatValidateAssemblies
Fixed Premise Git tags + contract assemblies + specification files Git, Microsoft.DotNet.ApiCompat
Inferential Density record, init, required members C# 9–12 language features

2. Technology Stack

Layer Recommendation
Framework .NET 9+ (OpenAPI built-in, incremental source generators)
Build MSBuild + Incrementalist (Git-based impact analysis)
Specification OpenAPI YAML / TypeSpec / JSON Schema
Code Generation Source Generators (Roslyn), OpenAPI Generator
Static Validation Roslyn analyzers (custom + built-in)
Architecture Testing NetArchTest.eNhancedEdition
Module System Namespace conventions (JPMS optional)
CI/CD GitHub Actions / Azure DevOps + conditional gates

3. Structural Specification Layer

3.1 API Contracts (OpenAPI / TypeSpec)

Define all public API contracts in machine-readable format.

# openapi.yaml
openapi: 3.0.3
paths:
  /api/players/{id}:
    get:
      operationId: GetPlayer
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Player'

3.2 Data Contracts (JSON Schema)

Define data structures separately from behavior.

// player-schema.json
{
  "type": "object",
  "required": ["id", "name"],
  "properties": {
    "id": { "type": "string" },
    "name": { "type": "string" },
    "score": { "type": "integer" }
  }
}

3.3 Domain Contracts (C# Interfaces)

Define behavior contracts using C# type system.

public interface IPlayerRepository
{
    Task<Player> GetByIdAsync(string id, CancellationToken token);
    Task UpdateAsync(Player player, CancellationToken token);
}

4. Generative Conformance

4.1 Source Generator Pattern

Implement incremental source generators for specification-to-code transformation.

[Generator]
public class SkeletonGenerator : IIncrementalGenerator
{
    public void Initialize(IncrementalGeneratorInitializationContext context)
    {
        var provider = context.SyntaxProvider
            .CreateSyntaxProvider(predicate: static (s, _) => IsTargetInterface(s),
                                   transform: static (ctx, _) => GetInterfaceSymbol(ctx))
            .Where(static m => m is not null);
        
        context.RegisterSourceOutput(provider, GenerateSkeletonClass);
    }
}

4.2 Build Integration

Configure generation in .csproj:

<PropertyGroup>
  <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
  <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

5. Skeleton–Tissue Architecture

5.1 Skeleton Layer (Invariant)

Template method pattern with sealed orchestration methods.

public abstract class ServiceSkeleton : IService
{
    public sealed async Task<Result> ExecuteAsync(Request req)
    {
        await OnBeforeExecute(req);
        var result = await ExecuteCoreAsync(req);
        await OnAfterExecute(result);
        return result;
    }
    
    protected abstract Task<Result> ExecuteCoreAsync(Request req);
    protected virtual Task OnBeforeExecute(Request req) => Task.CompletedTask;
    protected virtual Task OnAfterExecute(Result res) => Task.CompletedTask;
}

5.2 Tissue Layer (Generated)

Concrete implementations generated from specification.

// Auto-generated from OpenAPI/JSON Schema
public partial class PlayerService : ServiceSkeleton, IPlayerService
{
    private readonly IPlayerRepository _repository;
    
    public partial PlayerService(IPlayerRepository repository)
    {
        _repository = repository;
    }
    
    protected override async Task<Result> ExecuteCoreAsync(Request req)
    {
        // Generated business logic
    }
}

5.3 Manual Extension (Separate File)

// Manual extension - not regenerated
public partial class PlayerService
{
    partial void OnConstructed()
    {
        Logger.LogInformation("Service initialized");
    }
    
    protected override async Task OnAfterExecute(Result res)
    {
        await PublishEventAsync(res);
    }
}

6. Validation Gates

6.1 Compile-Time (Roslyn Analyzers)

Enforce tissue layer constraints at compilation.

[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class TissueConformanceAnalyzer : DiagnosticAnalyzer
{
    // Rule: Generated types must implement skeleton interfaces
}

6.2 Architecture Tests (NetArchTest)

Enforce layer dependencies in unit tests.

[Fact]
public void Tissue_Should_Only_Depend_On_Skeleton()
{
    var rule = Types().That().ResideInNamespace("Tissue")
        .Should().OnlyDependOn(Types().That().ResideInNamespace("Skeleton"));
    rule.Check(Architecture);
}

6.3 Generator Tests (Verify.SourceGenerators)

Snapshot-test generated outputs.

[Fact]
public Task Generator_Produces_Correct_Skeleton()
{
    var test = new CSharpSourceGeneratorTest<MyGenerator>
    {
        TestCode = InputSource,
        ExpectedDiagnostics = { }
    };
    test.TestState.GeneratedSources.Add(ExpectedOutput);
    return test.RunAsync();
}

7. Recursive Refinement Workflow

7.1 Phase Transition Process

Phase N complete
    │
    ├── Git tag: phase-N-complete
    ├── Save contract assembly as baseline (ApiCompat)
    │
    ▼
Modify structural specification (OpenAPI / JSON Schema)
    │
    ├── Incrementalist detects affected projects
    ├── Incremental source generator runs only on changed inputs
    │
    ▼
Validation gates
    │
    ├── Roslyn analyzers (compile-time)
    ├── NetArchTest (unit test)
    ├── ApiCompat (assembly compatibility)
    │
    ▼
Phase N+1 complete
    │
    └── Git tag: phase-N+1-complete

7.2 Git Worktree for Parallel Phases

git worktree add ../project-phase2 phase2-branch
git worktree add ../project-phase3 phase3-branch

7.3 Incremental Build Configuration

<Target Name="GenerateFromSpec" 
        Inputs="@(OpenApiSpec)" 
        Outputs="@(GeneratedCode)">
    <OpenApiGenerator Inputs="@(OpenApiSpec)" Outputs="@(GeneratedCode)"/>
</Target>

8. CI/CD Integration

8.1 GitHub Actions Pipeline

name: Deep Coding Validation
on: [push, pull_request]
jobs:
  validate:
    steps:
      - name: Impact analysis
        run: incrementalist run -b main -- build --no-incremental
      
      - name: Architecture tests
        run: dotnet test --filter "Category=Architecture"
      
      - name: Generator tests
        run: dotnet test --filter "Category=GeneratorTest"
      
      - name: API compatibility
        run: dotnet build -p:ApiCompatValidateAssemblies=true
      
      - name: Verify generated code is committed
        run: git diff --exit-code -- '**/*.g.cs'

8.2 Feature Flags for Gradual Rollout

if (await featureManager.IsEnabledAsync("NewFeature"))
{
    return await newImplementation.ExecuteAsync();
}
return await legacyImplementation.ExecuteAsync();

9. Implementation Phases

Phase Scope Deliverable
0 Infrastructure .NET 9 SDK, Git worktree training, NetArchTest in CI
1 API contracts OpenAPI/TypeSpec definitions + generated interfaces
2 Data contracts JSON Schema + generated POCOs with JsonSchema.Net
3 Business logic (optional) Skeleton abstract classes + generated tissue stubs
4 Governance Weekly drift detection, compatibility reports

10. Constraints and Mitigations

Constraint Mitigation
Reflection-heavy libraries (EF Core, Newtonsoft.Json) Apply Deep Coding only to contract layer. Internal implementation uses traditional patterns.
Partial classes do not work with structs Use DI + abstract factory for performance-critical areas.
Generated code debugging difficulty Enable EmitCompilerGeneratedFiles, use source link.
Unity runtime differences Apply Deep Coding only to ECS layer. Keep asset pipeline separate.
Build time in large monorepos Incrementalist + incremental source generators reduce to practical levels.

11. Expected Benefits

12. Conclusion

C# and .NET provide all necessary language features and tooling to implement Deep Coding methodology. The stack—OpenAPI for contracts, source generators for conformance, partial classes for skeleton-tissue separation, Roslyn analyzers and NetArchTest for validation, and Incrementalist plus Git worktrees for recursive refinement—forms a complete, production-ready foundation. ASP.NET Core projects achieve full compatibility; game development (MonoGame, Unity) achieves partial but valuable applicability. Following the phased implementation plan minimizes risk while delivering measurable ROI within months. ```