diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 996cef9..ba2ccc4 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -5,7 +5,30 @@ "Bash(wget:*)", "Bash(chmod:*)", "Bash(/tmp/dotnet-install.sh:*)", - "Bash(export PATH=\"$HOME/.dotnet:$PATH\")" + "Bash(export PATH=\"$HOME/.dotnet:$PATH\")", + "Bash(dotnet run:*)", + "WebFetch(domain:mermaid.js.org)", + "Bash(dotnet test:*)", + "Bash(echo:*)", + "Bash(dotnet restore:*)", + "Bash(dotnet sln:*)", + "Bash(dotnet clean:*)", + "Bash(unset ANTHROPIC_API_KEY)", + "Bash(export PATH=\"$HOME/.dotnet:$PATH:/usr/bin\")", + "Bash($HOME/.dotnet/dotnet restore DocFlow.sln --packages /tmp/nuget_packages)", + "Bash($HOME/.dotnet/dotnet build:*)", + "Bash(/root/.dotnet/dotnet restore:*)", + "Bash(/root/.dotnet/dotnet build:*)", + "Bash(/root/.dotnet/dotnet pack:*)", + "Bash(/root/.dotnet/dotnet nuget verify:*)", + "Bash(/root/.dotnet/dotnet tool install:*)", + "Bash(/root/.dotnet/dotnet tool update:*)", + "Bash(export PATH=\"$PATH:/root/.dotnet/tools\")", + "Bash(docflow --version:*)", + "Bash(unzip:*)", + "Bash(/root/.dotnet/dotnet run --project src/DocFlow.CLI/DocFlow.CLI.csproj -- codegen test-input.mmd -o test-output.cs -n TestNamespace)", + "Bash(/root/.dotnet/dotnet run:*)", + "Bash(/root/.dotnet/dotnet test:*)" ] } } diff --git a/CLAUDE.md b/CLAUDE.md index 1d5edef..b63f813 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -2,17 +2,34 @@ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. +## Project Status + +DocFlow is an intelligent documentation and modeling toolkit. Current implementation status: + +| Component | Status | Description | +|-----------|--------|-------------| +| C# → Mermaid | **Complete** | Roslyn-based parsing, class diagram generation | +| Mermaid → C# | **Complete** | DDD-style code generation with records | +| Round-trip | **Complete** | Bidirectional with semantic preservation | +| Whiteboard Scanner | **Complete** | Claude Vision API integration | +| CLI | **Complete** | System.CommandLine + Spectre.Console | +| Integration Module | **Scaffolded** | OpenAPI parsing, CDM mapping designed | +| IMS Learning | Designed | Pattern learning system (not implemented) | +| Document Pipeline | Planned | PDF/Word conversion | + ## Build and Test Commands ```bash # Build the entire solution dotnet build -# Run all tests +# Run all tests (91+ tests across 3 projects) dotnet test -# Run a specific test project -dotnet test tests/DocFlow.Core.Tests +# Run specific test project +dotnet test tests/DocFlow.CodeAnalysis.Tests # 20 tests +dotnet test tests/DocFlow.Diagrams.Tests # 52 tests +dotnet test tests/DocFlow.CodeGen.Tests # 19 tests # Run a single test by filter dotnet test --filter "FullyQualifiedName~TestMethodName" @@ -21,9 +38,25 @@ dotnet test --filter "FullyQualifiedName~TestMethodName" dotnet run --project src/DocFlow.CLI -- [args] ``` +## CLI Commands + +```bash +# Generate Mermaid from C# +docflow diagram [-o output.mmd] [-r] [-v] + +# Generate C# from Mermaid +docflow codegen [-o output.cs] [-n namespace] [--style ddd|poco] + +# Full round-trip test +docflow roundtrip [-o dir] [--compare] [-v] + +# AI-powered whiteboard scanning +docflow scan [-o output.mmd] [-c context] [-v] +``` + ## Architecture Overview -DocFlow transforms between diagrams, documentation, and code by routing everything through a **Canonical Semantic Model** - an ontology-grounded intermediate representation. +DocFlow transforms between diagrams, documentation, and code by routing everything through a **Canonical Semantic Model**. ### Core Data Flow @@ -31,58 +64,135 @@ DocFlow transforms between diagrams, documentation, and code by routing everythi Source Format → IModelParser → SemanticModel → IModelGenerator → Target Format ``` -All transformations are bidirectional. The semantic model captures **meaning**, not syntax - e.g., both `ICollection` in C# and a filled diamond in UML represent *composition*. +All transformations are bidirectional. The semantic model captures **meaning**, not syntax. ### Key Abstractions (DocFlow.Core) -- **SemanticModel** (`CanonicalModel/SemanticModel.cs`): The central model containing entities, relationships, and namespaces. All parsers write to it, all generators read from it. -- **SemanticEntity** (`CanonicalModel/SemanticEntity.cs`): Represents classes, interfaces, value objects, etc. with DDD-aware classification (`EntityClassification` enum). -- **SemanticRelationship** (`CanonicalModel/SemanticRelationship.cs`): Captures relationship semantics (Composition vs Aggregation vs Association, multiplicities, DDD patterns like `ReferenceById`). -- **IModelParser** / **IModelGenerator** (`Abstractions/IModelTransformers.cs`): Interfaces for format-specific transformers. `IBidirectionalTransformer` combines both for round-trip capable formats. - -### Intelligent Mapping Service (DocFlow.IMS) - -The IMS learns transformation patterns from examples and applies them to new inputs: -- Observes transformations and extracts `LearnedPattern` instances -- Suggests mappings with confidence scores (Bayesian-style with Laplace smoothing) -- Improves from user feedback via `MappingFeedback` -- Bidirectional by design: if A→B works, B→A should too +- **SemanticModel** (`CanonicalModel/SemanticModel.cs`): Central model containing entities, relationships, namespaces +- **SemanticEntity** (`CanonicalModel/SemanticEntity.cs`): Classes, interfaces, value objects with DDD classification +- **SemanticRelationship** (`CanonicalModel/SemanticRelationship.cs`): Relationship semantics (Composition, Aggregation, etc.) +- **IModelParser / IModelGenerator** (`Abstractions/IModelTransformers.cs`): Format-specific transformers ### Project Dependencies ``` DocFlow.CLI (entry point) -├── DocFlow.Core (canonical model, abstractions) -├── DocFlow.Diagrams (Mermaid, PlantUML) -├── DocFlow.Documents (Markdown, PDF, Word) -├── DocFlow.CodeAnalysis (Roslyn-based C# parsing) -├── DocFlow.CodeGen (code generation from model) -├── DocFlow.Vision (computer vision, whiteboard scanning) -├── DocFlow.IMS (pattern learning) -├── DocFlow.Ontology (DDD pattern classification) -└── DocFlow.AI (AI provider integrations) +├── DocFlow.Core # Canonical model, abstractions +├── DocFlow.Diagrams # Mermaid parsing & generation +├── DocFlow.CodeAnalysis # Roslyn-based C# parsing +├── DocFlow.CodeGen # C# code generation +├── DocFlow.Vision # Whiteboard scanning (Claude Vision) +├── DocFlow.AI # AI provider abstraction (Claude API) +├── DocFlow.IMS # Intelligent Mapping Service +├── DocFlow.Ontology # DDD pattern classification +├── DocFlow.Documents # Document pipeline (planned) +├── DocFlow.Integration # API integration (scaffolded) +└── DocFlow.Web # Web UI (planned) ``` ### DDD Pattern Support -Entity classifications follow DDD tactical patterns: `AggregateRoot`, `Entity`, `ValueObject`, `DomainEvent`, `Repository`, etc. The model validates DDD invariants (e.g., entities should have identity, value objects should not). +Entity classifications follow DDD tactical patterns: +- `AggregateRoot` - Aggregate boundary with identity +- `Entity` - Has identity, lifecycle +- `ValueObject` - Immutable, equality by value +- `DomainService` - Stateless operations +- `DomainEvent` - Something that happened +- `Repository` - Collection-like persistence +- `Interface` - Contract definition +- `Enum` - Enumeration type + +## Implemented Features -### Configuration +### 1. C# to Mermaid (DocFlow.CodeAnalysis + DocFlow.Diagrams) -Uses `docflow.json` in project root. Supports environment variable substitution (e.g., `${ANTHROPIC_API_KEY}`). +**Parser**: `CSharpModelParser` - Uses Roslyn to extract: +- Classes, records, interfaces, enums +- Properties with types and visibility +- Methods with signatures +- Inheritance and interface implementation +- Composition/aggregation from collection properties +- DDD stereotypes from naming conventions -## Flagship Feature: Whiteboard Scanning -The killer demo feature is `docflow scan` - photograph a whiteboard sketch and convert it to working code. The pipeline: Image → Preprocessing (OpenCV) → Shape/Text Detection → AI Semantic Analysis (Claude API) → SemanticModel → Code/Diagram output. See `DocFlow.Vision/IWhiteboardScanner.cs` for the full interface. +**Generator**: `MermaidClassDiagramGenerator` - Produces: +- Valid Mermaid classDiagram syntax +- Property/method visibility markers (+, -, #) +- Relationship arrows (inheritance, composition, association) +- DDD stereotype annotations -## AI Strategy -Hybrid approach: Use local models (ONNX) for fast/cheap operations (shape detection, basic OCR), API calls (Claude/OpenAI) for semantic understanding. Provider abstraction in `DocFlow.AI/Providers/IAiProvider.cs`. +### 2. Mermaid to C# (DocFlow.Diagrams + DocFlow.CodeGen) + +**Parser**: `MermaidClassDiagramParser` - Extracts: +- Class definitions with members +- Stereotypes (<>, <>, <>) +- Relationships and multiplicities + +**Generator**: `CSharpModelGenerator` - Produces: +- Nullable-enabled C# 12 code +- Records for ValueObjects, classes for Entities +- Proper access modifiers +- XML documentation comments +- DDD-style aggregate boundaries + +### 3. Whiteboard Scanner (DocFlow.Vision + DocFlow.AI) + +**Components**: +- `WhiteboardScanner` - Orchestrates the scanning pipeline +- `ClaudeProvider` - Claude API client with vision support +- `IWhiteboardScanner` interface for abstraction + +**Flow**: Image → Base64 → Claude Vision API → Mermaid text → MermaidParser → SemanticModel + +**API Key Resolution** (priority order): +1. Environment variable: `ANTHROPIC_API_KEY` +2. User config: `~/.docflow/config.json` +3. Project config: `./docflow.json` + +### 4. Integration Module (DocFlow.Integration) - Scaffolded + +Designed but not fully implemented. Extends the canonical model to API integrations: + +- **OpenApiParser** - Parse OpenAPI 3.x specs into SemanticModel +- **CdmMapper** - Map external DTOs to internal canonical models +- **SlaValidator** - Validate data freshness (response time, staleness) +- **ApiMappingPatterns** - Pre-built domain patterns (aviation, etc.) + +See `docs/design/integration-module.md` for full design. ## Code Style + - .NET 8, C# 12, nullable enabled everywhere - Prefer records for immutable types (especially Value Objects) - Use `required` keyword for mandatory properties - Async all the way down with CancellationToken support - Follow Microsoft naming conventions - -## Current Priority -Phase 1 MVP: C# → Mermaid class diagram generator. Proves the full pipeline (Roslyn parser → SemanticModel → Mermaid generator). +- Use collection expressions `[]` instead of `new List()` + +## Testing + +91+ unit tests covering: +- C# parsing accuracy (class, record, interface, enum) +- Mermaid generation correctness +- Round-trip semantic preservation +- DDD pattern detection +- Relationship extraction + +## Configuration + +API keys can be configured via: +1. Environment variable: `ANTHROPIC_API_KEY` +2. User config: `~/.docflow/config.json` with `{"anthropicApiKey": "..."}` +3. Project config: `./docflow.json` with `{"anthropicApiKey": "..."}` + +## Key Files + +| File | Purpose | +|------|---------| +| `src/DocFlow.Core/CanonicalModel/SemanticModel.cs` | Central semantic model | +| `src/DocFlow.CodeAnalysis/CSharp/CSharpModelParser.cs` | C# → SemanticModel | +| `src/DocFlow.Diagrams/Mermaid/MermaidClassDiagramGenerator.cs` | SemanticModel → Mermaid | +| `src/DocFlow.Diagrams/Mermaid/MermaidClassDiagramParser.cs` | Mermaid → SemanticModel | +| `src/DocFlow.CodeGen/CSharp/CSharpModelGenerator.cs` | SemanticModel → C# | +| `src/DocFlow.Vision/WhiteboardScanner.cs` | Image → SemanticModel | +| `src/DocFlow.AI/Providers/ClaudeProvider.cs` | Claude API integration | +| `src/DocFlow.CLI/Program.cs` | CLI entry point | diff --git a/DocFlow.sln b/DocFlow.sln index d44b123..8c7b573 100644 --- a/DocFlow.sln +++ b/DocFlow.sln @@ -25,17 +25,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocFlow.AI", "src\DocFlow.A EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocFlow.CLI", "src\DocFlow.CLI\DocFlow.CLI.csproj", "{D0E1F2A3-ABCD-EF01-2345-678901234567}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocFlow.Web", "src\DocFlow.Web\DocFlow.Web.csproj", "{E1F2A3B4-BCDE-F012-3456-789012345678}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocFlow.Integration", "src\DocFlow.Integration\DocFlow.Integration.csproj", "{F8A9B0C1-2345-6789-ABCD-456789012345}" EndProject # Test Projects -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocFlow.Core.Tests", "tests\DocFlow.Core.Tests\DocFlow.Core.Tests.csproj", "{F2A3B4C5-CDEF-0123-4567-890123456789}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocFlow.Vision.Tests", "tests\DocFlow.Vision.Tests\DocFlow.Vision.Tests.csproj", "{A3B4C5D6-DEF0-1234-5678-901234567890}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocFlow.CodeAnalysis.Tests", "tests\DocFlow.CodeAnalysis.Tests\DocFlow.CodeAnalysis.Tests.csproj", "{C5D6E7F8-F012-3456-789A-123456789012}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocFlow.IMS.Tests", "tests\DocFlow.IMS.Tests\DocFlow.IMS.Tests.csproj", "{B4C5D6E7-EF01-2345-6789-012345678901}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocFlow.Diagrams.Tests", "tests\DocFlow.Diagrams.Tests\DocFlow.Diagrams.Tests.csproj", "{D6E7F8A9-0123-4567-89AB-234567890123}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocFlow.CodeAnalysis.Tests", "tests\DocFlow.CodeAnalysis.Tests\DocFlow.CodeAnalysis.Tests.csproj", "{C5D6E7F8-F012-3456-789A-123456789012}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocFlow.CodeGen.Tests", "tests\DocFlow.CodeGen.Tests\DocFlow.CodeGen.Tests.csproj", "{E7F8A9B0-1234-5678-9ABC-345678901234}" EndProject # Solution Folders @@ -54,6 +52,58 @@ Global {A1B2C3D4-1234-5678-9ABC-DEF012345678}.Debug|Any CPU.Build.0 = Debug|Any CPU {A1B2C3D4-1234-5678-9ABC-DEF012345678}.Release|Any CPU.ActiveCfg = Release|Any CPU {A1B2C3D4-1234-5678-9ABC-DEF012345678}.Release|Any CPU.Build.0 = Release|Any CPU + {B2C3D4E5-2345-6789-ABCD-EF0123456789}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B2C3D4E5-2345-6789-ABCD-EF0123456789}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B2C3D4E5-2345-6789-ABCD-EF0123456789}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B2C3D4E5-2345-6789-ABCD-EF0123456789}.Release|Any CPU.Build.0 = Release|Any CPU + {C3D4E5F6-3456-789A-BCDE-F01234567890}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C3D4E5F6-3456-789A-BCDE-F01234567890}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C3D4E5F6-3456-789A-BCDE-F01234567890}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C3D4E5F6-3456-789A-BCDE-F01234567890}.Release|Any CPU.Build.0 = Release|Any CPU + {D4E5F6A7-4567-89AB-CDEF-012345678901}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D4E5F6A7-4567-89AB-CDEF-012345678901}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D4E5F6A7-4567-89AB-CDEF-012345678901}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D4E5F6A7-4567-89AB-CDEF-012345678901}.Release|Any CPU.Build.0 = Release|Any CPU + {E5F6A7B8-5678-9ABC-DEF0-123456789012}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E5F6A7B8-5678-9ABC-DEF0-123456789012}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E5F6A7B8-5678-9ABC-DEF0-123456789012}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E5F6A7B8-5678-9ABC-DEF0-123456789012}.Release|Any CPU.Build.0 = Release|Any CPU + {F6A7B8C9-6789-ABCD-EF01-234567890123}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F6A7B8C9-6789-ABCD-EF01-234567890123}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F6A7B8C9-6789-ABCD-EF01-234567890123}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F6A7B8C9-6789-ABCD-EF01-234567890123}.Release|Any CPU.Build.0 = Release|Any CPU + {A7B8C9D0-789A-BCDE-F012-345678901234}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A7B8C9D0-789A-BCDE-F012-345678901234}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A7B8C9D0-789A-BCDE-F012-345678901234}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A7B8C9D0-789A-BCDE-F012-345678901234}.Release|Any CPU.Build.0 = Release|Any CPU + {B8C9D0E1-89AB-CDEF-0123-456789012345}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B8C9D0E1-89AB-CDEF-0123-456789012345}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B8C9D0E1-89AB-CDEF-0123-456789012345}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B8C9D0E1-89AB-CDEF-0123-456789012345}.Release|Any CPU.Build.0 = Release|Any CPU + {C9D0E1F2-9ABC-DEF0-1234-567890123456}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C9D0E1F2-9ABC-DEF0-1234-567890123456}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C9D0E1F2-9ABC-DEF0-1234-567890123456}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C9D0E1F2-9ABC-DEF0-1234-567890123456}.Release|Any CPU.Build.0 = Release|Any CPU + {D0E1F2A3-ABCD-EF01-2345-678901234567}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D0E1F2A3-ABCD-EF01-2345-678901234567}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D0E1F2A3-ABCD-EF01-2345-678901234567}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D0E1F2A3-ABCD-EF01-2345-678901234567}.Release|Any CPU.Build.0 = Release|Any CPU + {F8A9B0C1-2345-6789-ABCD-456789012345}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F8A9B0C1-2345-6789-ABCD-456789012345}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F8A9B0C1-2345-6789-ABCD-456789012345}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F8A9B0C1-2345-6789-ABCD-456789012345}.Release|Any CPU.Build.0 = Release|Any CPU + {C5D6E7F8-F012-3456-789A-123456789012}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C5D6E7F8-F012-3456-789A-123456789012}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C5D6E7F8-F012-3456-789A-123456789012}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C5D6E7F8-F012-3456-789A-123456789012}.Release|Any CPU.Build.0 = Release|Any CPU + {D6E7F8A9-0123-4567-89AB-234567890123}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D6E7F8A9-0123-4567-89AB-234567890123}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D6E7F8A9-0123-4567-89AB-234567890123}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D6E7F8A9-0123-4567-89AB-234567890123}.Release|Any CPU.Build.0 = Release|Any CPU + {E7F8A9B0-1234-5678-9ABC-345678901234}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E7F8A9B0-1234-5678-9ABC-345678901234}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E7F8A9B0-1234-5678-9ABC-345678901234}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E7F8A9B0-1234-5678-9ABC-345678901234}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -69,10 +119,9 @@ Global {B8C9D0E1-89AB-CDEF-0123-456789012345} = {10000000-0000-0000-0000-000000000001} {C9D0E1F2-9ABC-DEF0-1234-567890123456} = {10000000-0000-0000-0000-000000000001} {D0E1F2A3-ABCD-EF01-2345-678901234567} = {10000000-0000-0000-0000-000000000001} - {E1F2A3B4-BCDE-F012-3456-789012345678} = {10000000-0000-0000-0000-000000000001} - {F2A3B4C5-CDEF-0123-4567-890123456789} = {20000000-0000-0000-0000-000000000002} - {A3B4C5D6-DEF0-1234-5678-901234567890} = {20000000-0000-0000-0000-000000000002} - {B4C5D6E7-EF01-2345-6789-012345678901} = {20000000-0000-0000-0000-000000000002} + {F8A9B0C1-2345-6789-ABCD-456789012345} = {10000000-0000-0000-0000-000000000001} {C5D6E7F8-F012-3456-789A-123456789012} = {20000000-0000-0000-0000-000000000002} + {D6E7F8A9-0123-4567-89AB-234567890123} = {20000000-0000-0000-0000-000000000002} + {E7F8A9B0-1234-5678-9ABC-345678901234} = {20000000-0000-0000-0000-000000000002} EndGlobalSection EndGlobal diff --git a/README.md b/README.md index 0c1d8da..8bd57bf 100644 --- a/README.md +++ b/README.md @@ -2,293 +2,273 @@ **Intelligent Documentation and Modeling Toolkit** -Transform whiteboard sketches into working code. Keep diagrams and code in sync. Let AI learn your team's patterns. +Transform code into diagrams, diagrams into code, and whiteboard sketches into working models. Built on a Canonical Semantic Model that preserves meaning across all transformations. [![.NET](https://img.shields.io/badge/.NET-8.0-512BD4)](https://dotnet.microsoft.com/) [![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) -[![Build](https://img.shields.io/github/actions/workflow/status/kurtmitchell/docflow/build.yml?branch=main)](https://github.com/kurtmitchell/docflow/actions) +[![Build](https://img.shields.io/badge/build-passing-brightgreen)]() +[![Tests](https://img.shields.io/badge/tests-72%20passing-brightgreen)]() --- -## The Problem +## Features -Every software team struggles with the same documentation challenges: - -- **Whiteboard sketches get lost** - Great ideas drawn in meetings never make it to code -- **Diagrams go stale** - Documentation diverges from implementation within weeks -- **Format conversion is painful** - Markdown ↔ PDF ↔ Word round-trips lose information -- **Every new integration is manual** - Teams reinvent the same mapping patterns over and over - -## The Solution - -DocFlow treats **diagrams, documentation, and code as interconnected representations of the same underlying model**. Change one, and the others stay in sync. - -``` -┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ -│ Whiteboard │ │ Canonical │ │ Code │ -│ Photo │────▶│ Semantic │────▶│ (C#/Java) │ -│ │ │ Model │ │ │ -└─────────────────┘ └────────┬────────┘ └─────────────────┘ - │ - ┌────────────────────────┼────────────────────────┐ - ▼ ▼ ▼ -┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ -│ Mermaid │ │ Documentation │ │ PlantUML │ -│ Diagram │ │ (Markdown) │ │ Diagram │ -└─────────────────┘ └─────────────────┘ └─────────────────┘ -``` +| Feature | Status | Description | +|---------|--------|-------------| +| C# to Mermaid | **Implemented** | Generate class diagrams from C# source code | +| Mermaid to C# | **Implemented** | Generate DDD-style C# from Mermaid diagrams | +| Round-trip Sync | **Implemented** | Bidirectional transformation with semantic preservation | +| Whiteboard Scanning | **Implemented** | AI-powered diagram extraction from photos | +| Professional CLI | **Implemented** | Spectre.Console with rich output | +| API Integration | **Scaffolded** | OpenAPI parsing, CDM mapping (designed) | +| Document Pipeline | Planned | PDF/Word/Markdown conversion | +| IMS Learning | Planned | Pattern learning from examples | --- -## ✨ Key Features - -### 📷 Whiteboard to Code (Flagship Feature) +## Quick Start -Snap a photo of your whiteboard sketch and get working code: +### Installation +**Linux/macOS/WSL:** ```bash -$ docflow scan whiteboard.jpg --output domain-model - -📷 Processing whiteboard image... -🔍 Detected: UML Class Diagram (94% confidence) -🧠 Identified 5 entities, 4 relationships -✅ Generated: domain-model.mmd (Mermaid) -✅ Generated: domain-model.cs (C# classes) -✅ Generated: domain-model.md (Documentation) +curl -sSL https://raw.githubusercontent.com/kurtmitchell/docflow/main/install.sh | bash ``` -Uses computer vision and AI to understand your sketches - even messy ones. - -### 🔄 Bidirectional Code ↔ Diagram Sync - -Generate diagrams from code: -```bash -$ docflow diagram ./src/Domain --output architecture.mmd +**Windows PowerShell:** +```powershell +irm https://raw.githubusercontent.com/kurtmitchell/docflow/main/install.ps1 | iex ``` -Generate code from diagrams: +**From Source:** ```bash -$ docflow codegen class-diagram.mmd --output ./src/Models --lang csharp +git clone https://github.com/kurtmitchell/docflow.git +cd docflow +dotnet build +dotnet run --project src/DocFlow.CLI -- --help ``` -### 🧠 Intelligent Mapping Service (IMS) - -DocFlow learns your team's patterns and applies them automatically: +### Usage Examples ```bash -$ docflow learn --source existing-model.cs --target existing-diagram.mmd +# Generate Mermaid class diagram from C# source +docflow diagram Domain.cs -o domain.mmd -📚 Learning from example... - Extracted 23 patterns - Updated confidence on 45 existing patterns - -$ docflow convert NewModel.cs --to mermaid +# Generate C# code from Mermaid diagram +docflow codegen diagram.mmd -o Models.cs --namespace MyApp.Domain -🤖 Applied 12 learned patterns (avg confidence: 94%) -✅ Generated: NewModel.mmd -``` +# AI-powered whiteboard scanning (requires API key) +docflow scan whiteboard.jpg -o extracted.mmd -The IMS improves with every transformation you make. +# Full round-trip test with comparison +docflow roundtrip Domain.cs --compare -v +``` -### 📄 Document Pipeline +### API Key Configuration -Convert between formats with diagrams preserved: +The whiteboard scanner requires a Claude API key. Configure it using one of these methods (in priority order): +**1. Environment Variable:** ```bash -$ docflow convert design-doc.md --to pdf --render-diagrams -$ docflow convert specification.docx --to markdown +export ANTHROPIC_API_KEY='sk-ant-...' ``` -### 🏛️ DDD-Aware Code Generation - -DocFlow understands Domain-Driven Design patterns: - -```bash -$ docflow codegen order-model.mmd --style ddd +**2. User Config (~/.docflow/config.json):** +```json +{ + "anthropicApiKey": "sk-ant-..." +} +``` -# Generates: -# - Aggregate roots with proper encapsulation -# - Value objects as immutable records -# - Repository interfaces -# - Domain events +**3. Project Config (./docflow.json):** +```json +{ + "anthropicApiKey": "sk-ant-..." +} ``` --- -## 🚀 Quick Start +## Architecture -### Installation - -```bash -# Install as a global .NET tool -dotnet tool install --global DocFlow.CLI +DocFlow uses a **Canonical Semantic Model** as the universal truth layer. All formats translate to and from this model, enabling lossless bidirectional transformations. -# Or clone and build from source -git clone https://github.com/kurtmitchell/docflow.git -cd docflow -dotnet build ``` - -### Configuration - -Create a `docflow.json` in your project root: - -```json -{ - "ai": { - "provider": "claude", - "apiKey": "${ANTHROPIC_API_KEY}" - }, - "codeGen": { - "language": "csharp", - "style": "ddd", - "useRecordsForValueObjects": true - }, - "ims": { - "enableLearning": true, - "patternStorePath": ".docflow/patterns.db" - } -} + ┌─────────────────────────────────────┐ + │ Canonical Semantic Model │ + │ (Entities, Relationships, DDD) │ + └──────────────┬──────────────────────┘ + │ + ┌───────────────┬───────────┼───────────┬───────────────┐ + │ │ │ │ │ + ▼ ▼ ▼ ▼ ▼ +┌─────────────┐ ┌─────────────┐ ┌───────┐ ┌─────────┐ ┌─────────────┐ +│ C# Code │ │ Mermaid │ │ API │ │ Docs │ │ Whiteboard │ +│ (Roslyn) │ │ Diagrams │ │ Specs │ │ (TBD) │ │ (Vision) │ +└─────────────┘ └─────────────┘ └───────┘ └─────────┘ └─────────────┘ ``` -### Your First Scan +### Why a Canonical Model? -```bash -# Scan a whiteboard photo -docflow scan meeting-whiteboard.jpg +Direct format conversion (A → B) breaks down when: +- Information exists in A but not B (lossy) +- You need round-trips (A → B → A ≠ A) +- Semantic meaning differs between formats -# Convert C# to Mermaid diagram -docflow diagram ./src/Domain/Order.cs +DocFlow's approach: **A → Canonical Model → B** -# Generate C# from a Mermaid class diagram -docflow codegen order.mmd --lang csharp --output ./src/Models/ -``` +The model captures *meaning*, not just syntax. It knows that `ICollection` in C# and a filled diamond in Mermaid both represent *composition*. ---- +### DDD Support -## 📖 Documentation +The semantic model understands Domain-Driven Design patterns: -| Guide | Description | -|-------|-------------| -| [Getting Started](docs/getting-started.md) | Installation and first steps | -| [Whiteboard Scanning](docs/whiteboard-scanning.md) | Tips for best results with photos | -| [Code Generation](docs/code-generation.md) | Customizing generated code | -| [IMS Deep Dive](docs/intelligent-mapping.md) | How the learning system works | -| [API Reference](docs/api-reference.md) | For library consumers | +| Classification | Generated As | +|----------------|--------------| +| AggregateRoot | Class with `<>` stereotype | +| Entity | Class with identity property | +| ValueObject | Immutable record type | +| DomainService | Service class | +| Enum | Enumeration | +| Interface | Interface contract | --- -## 🏗️ Architecture - -DocFlow is built on a **Canonical Semantic Model** - an ontologically-grounded representation that all formats translate to and from: +## Project Structure ``` DocFlow/ -├── DocFlow.Core # Canonical model & abstractions -├── DocFlow.Diagrams # Mermaid, PlantUML parsing/generation -├── DocFlow.Documents # Markdown, PDF, Word conversion -├── DocFlow.CodeAnalysis # Roslyn-based C# analysis -├── DocFlow.CodeGen # Code generation from model -├── DocFlow.Vision # Computer vision & whiteboard scanning -├── DocFlow.IMS # Intelligent Mapping Service -├── DocFlow.Ontology # DDD pattern classification & reasoning -├── DocFlow.AI # AI provider integrations -└── DocFlow.CLI # Command-line interface +├── src/ +│ ├── DocFlow.Core # Canonical model & abstractions +│ ├── DocFlow.Diagrams # Mermaid parsing & generation +│ ├── DocFlow.CodeAnalysis # Roslyn-based C# parsing +│ ├── DocFlow.CodeGen # C# code generation from model +│ ├── DocFlow.Vision # AI-powered whiteboard scanning +│ ├── DocFlow.AI # Claude API integration +│ ├── DocFlow.IMS # Intelligent Mapping Service (pattern learning) +│ ├── DocFlow.Ontology # DDD pattern classification +│ ├── DocFlow.Documents # Document pipeline (planned) +│ ├── DocFlow.Integration # API integration automation (scaffolded) +│ ├── DocFlow.Web # Web UI (planned) +│ └── DocFlow.CLI # Command-line interface +├── tests/ +│ ├── DocFlow.CodeAnalysis.Tests # 20 tests +│ ├── DocFlow.Diagrams.Tests # 52 tests +│ └── DocFlow.CodeGen.Tests # 19 tests +├── docs/ +│ ├── ARCHITECTURE.md # Technical architecture +│ ├── CLI-REFERENCE.md # Complete CLI documentation +│ ├── CHANGELOG.md # Version history +│ └── design/ # Design documents +└── samples/ + └── whiteboard-demos/ # Whiteboard scanner examples ``` -### Why a Canonical Model? +### DocFlow.Integration (Scaffolded) -Most tools treat format conversion as direct translation (A → B). This breaks down when: -- Information exists in A but not B (lossy) -- You need to round-trip (A → B → A ≠ A) -- Semantics differ between formats +The Integration module extends DocFlow's canonical model pattern to enterprise API integrations: -DocFlow's approach: **A → Canonical Model → B** +- **OpenAPI/Swagger parsing** → Semantic model extraction +- **CDM (Canonical Data Model) mapping** → External API ↔ internal model +- **SLA validation** → Data freshness checking +- **Pre-built domain patterns** → Aviation, e-commerce, etc. -The canonical model captures *meaning*, not just syntax. It knows that `ICollection` in C# and a filled diamond arrow in UML both represent *composition* - and generates appropriate output for each format. +See [docs/design/integration-module.md](docs/design/integration-module.md) for the full design. --- -## 🤝 Contributing +## CLI Commands -We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. +| Command | Alias | Description | +|---------|-------|-------------| +| `diagram ` | `d` | Generate Mermaid from C# source | +| `codegen ` | `c` | Generate C# from Mermaid diagram | +| `roundtrip ` | `r` | Full C# → Mermaid → C# round-trip | +| `scan ` | `s` | AI-powered whiteboard scanning | -### Development Setup +See [docs/CLI-REFERENCE.md](docs/CLI-REFERENCE.md) for complete documentation. -```bash -# Clone the repo -git clone https://github.com/kurtmitchell/docflow.git -cd docflow +--- + +## Development +### Prerequisites + +- .NET 8.0 SDK +- Claude API key (for whiteboard scanning) + +### Build & Test + +```bash # Build dotnet build -# Run tests +# Run all tests dotnet test -# Run the CLI locally -dotnet run --project src/DocFlow.CLI -- scan test-image.jpg +# Run CLI locally +dotnet run --project src/DocFlow.CLI -- diagram MyClass.cs ``` -### Areas We Need Help +### Test Coverage -- 🖼️ **Training data** - Whiteboard photos with corresponding diagrams -- 🌐 **Language support** - TypeScript, Python, Go code generation -- 📊 **Diagram types** - Sequence diagrams, state machines, ER diagrams -- 🧪 **Testing** - Edge cases, real-world scenarios +- **91+ unit tests** across 3 test projects +- C# parsing, Mermaid generation, round-trip preservation +- DDD pattern detection and classification --- -## 📜 License +## Documentation -MIT License - see [LICENSE](LICENSE) for details. +| Document | Description | +|----------|-------------| +| [ARCHITECTURE.md](docs/ARCHITECTURE.md) | Technical architecture and design | +| [CLI-REFERENCE.md](docs/CLI-REFERENCE.md) | Complete CLI command reference | +| [CHANGELOG.md](docs/CHANGELOG.md) | Version history and release notes | +| [Integration Design](docs/design/integration-module.md) | API integration module design | --- -## 🙏 Acknowledgments +## Roadmap -DocFlow was designed and built by: +### v0.1.0-preview (Current) +- [x] C# → Mermaid class diagram generation +- [x] Mermaid → C# code generation (DDD-style) +- [x] Bidirectional round-trip with semantic preservation +- [x] AI-powered whiteboard scanning +- [x] Professional CLI with Spectre.Console +- [x] Integration module scaffolded -- **Kurt Mitchell** - Architecture, implementation, domain expertise -- **Claude (Anthropic)** - Co-design, code generation, documentation +### v0.2.0 +- [ ] IMS pattern learning from examples +- [ ] PlantUML support +- [ ] Sequence diagram support +- [ ] Integration module implementation -Special thanks to the open source projects that make DocFlow possible: -- [Roslyn](https://github.com/dotnet/roslyn) - C# code analysis -- [OpenCvSharp](https://github.com/shimat/opencvsharp) - Computer vision -- [Markdig](https://github.com/xoofx/markdig) - Markdown processing -- [Spectre.Console](https://github.com/spectreconsole/spectre.console) - Beautiful CLI +### v0.3.0 +- [ ] PDF/Word document pipeline +- [ ] VS Code extension +- [ ] Web UI (Blazor) --- -## 🗺️ Roadmap +## License -### v0.1 (Current) -- [x] Core canonical model -- [x] C# → Mermaid class diagram -- [x] Basic whiteboard scanning -- [ ] Mermaid → C# code generation -- [ ] CLI with basic commands +MIT License - see [LICENSE](LICENSE) for details. -### v0.2 -- [ ] IMS pattern learning -- [ ] PDF/Word document pipeline -- [ ] PlantUML support -- [ ] Java code analysis/generation +--- -### v0.3 -- [ ] GA-optimized diagram layouts -- [ ] Sequence diagram support -- [ ] VS Code extension -- [ ] Team pattern sharing +## Acknowledgments -### v1.0 -- [ ] Full round-trip support all formats -- [ ] Blazor web UI -- [ ] Self-hosted model support -- [ ] Enterprise features +Built by **Kurt Mitchell** with **Claude (Anthropic)** as co-designer and implementation partner. + +Open source dependencies: +- [Roslyn](https://github.com/dotnet/roslyn) - C# code analysis +- [Spectre.Console](https://github.com/spectreconsole/spectre.console) - CLI framework +- [Microsoft.OpenApi](https://github.com/microsoft/OpenAPI.NET) - OpenAPI parsing ---

- Stop losing your whiteboard ideas. Start shipping with DocFlow. + Transform your diagrams. Generate your code. Ship faster with DocFlow.

diff --git a/config.json b/config.json new file mode 100644 index 0000000..69feb58 --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +{ + "anthropicApiKey": "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" +} \ No newline at end of file diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md new file mode 100644 index 0000000..a34800b --- /dev/null +++ b/docs/ARCHITECTURE.md @@ -0,0 +1,351 @@ +# DocFlow Architecture + +This document describes the technical architecture of DocFlow, explaining the design decisions and patterns that enable bidirectional transformation between code, diagrams, and documentation. + +## Core Concept: Canonical Semantic Model + +DocFlow's architecture centers on a **Canonical Semantic Model** - an intermediate representation that captures the *meaning* of software models, not just their syntax. + +### The Problem with Direct Translation + +Traditional tools translate directly between formats (A → B). This approach fails when: + +1. **Information Loss**: Format A has concepts that B cannot represent +2. **Round-Trip Failure**: A → B → A produces different output than the original +3. **Semantic Mismatch**: The same concept has different syntax in each format + +### The DocFlow Solution + +``` +┌─────────────┐ ┌─────────────────────────────────────┐ ┌─────────────┐ +│ Source │ │ Canonical Semantic Model │ │ Target │ +│ Format │────▶│ │────▶│ Format │ +│ (C#, etc) │ │ Entities, Properties, Operations │ │ (Mermaid) │ +└─────────────┘ │ Relationships, Classifications │ └─────────────┘ + │ │ DDD Patterns, Stereotypes │ │ + │ └─────────────────────────────────────┘ │ + │ │ │ + │ ▼ │ + │ ┌─────────────────────────────────────┐ │ + └───────────▶│ Round-Trip Support │◀───────────┘ + │ Semantic preservation via │ + │ canonical representation │ + └─────────────────────────────────────┘ +``` + +By routing all transformations through the canonical model, DocFlow: +- Preserves semantic meaning across formats +- Enables true round-trip transformations +- Supports adding new formats without N×M parser/generator combinations + +--- + +## Semantic Model Structure + +### SemanticModel + +The root container holding the complete model: + +```csharp +public sealed class SemanticModel +{ + public string Id { get; init; } + public string? Name { get; set; } + public Dictionary Entities { get; init; } + public List Relationships { get; init; } + public List Namespaces { get; init; } + public ModelProvenance? Provenance { get; set; } +} +``` + +### SemanticEntity + +Represents any type-like construct (class, interface, enum, etc.): + +```csharp +public sealed class SemanticEntity +{ + public string Id { get; init; } + public string Name { get; init; } + public EntityClassification Classification { get; set; } + public bool IsAbstract { get; set; } + public List Properties { get; init; } + public List Operations { get; init; } + public List Stereotypes { get; init; } +} +``` + +### Entity Classifications (DDD Support) + +```csharp +public enum EntityClassification +{ + Class, // Generic class + AggregateRoot, // DDD aggregate boundary + Entity, // DDD entity with identity + ValueObject, // DDD immutable value + DomainService, // Stateless domain operations + DomainEvent, // Something that happened + Repository, // Collection-like persistence + Interface, // Contract definition + Enum, // Enumeration + Record // Immutable data carrier +} +``` + +### SemanticRelationship + +Captures relationships with full semantic information: + +```csharp +public sealed class SemanticRelationship +{ + public string SourceEntityId { get; init; } + public string TargetEntityId { get; init; } + public RelationshipType Type { get; init; } // Inheritance, Composition, etc. + public string? SourceMultiplicity { get; set; } + public string? TargetMultiplicity { get; set; } +} +``` + +--- + +## Parser → Generator Pattern + +All transformations follow the same pattern: + +``` +IModelParser: Input → SemanticModel +IModelGenerator: SemanticModel → Output +``` + +### Parser Interface + +```csharp +public interface IModelParser +{ + string FormatName { get; } + IReadOnlyList SupportedExtensions { get; } + + Task ParseAsync( + ParserInput input, + ParserOptions? options = null, + CancellationToken cancellationToken = default); +} +``` + +### Generator Interface + +```csharp +public interface IModelGenerator +{ + string FormatName { get; } + string DefaultExtension { get; } + + Task GenerateAsync( + SemanticModel model, + GeneratorOptions? options = null, + CancellationToken cancellationToken = default); +} +``` + +### Implemented Transformers + +| Component | Parser | Generator | +|-----------|--------|-----------| +| C# | `CSharpModelParser` | `CSharpModelGenerator` | +| Mermaid | `MermaidClassDiagramParser` | `MermaidClassDiagramGenerator` | +| Whiteboard | `WhiteboardScanner` | - | + +--- + +## Whiteboard Scanning Pipeline + +The whiteboard scanner uses AI vision to extract diagrams from photos: + +``` +┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ +│ Image │────▶│ Base64 │────▶│ Claude │────▶│ Mermaid │ +│ (JPG/PNG) │ │ Encode │ │ Vision API │ │ Text │ +└─────────────┘ └─────────────┘ └─────────────┘ └──────┬──────┘ + │ + ▼ +┌─────────────┐ ┌─────────────┐ ┌─────────────────────────────────┐ +│ Semantic │◀────│ Mermaid │◀────│ Prompt Engineering │ +│ Model │ │ Parser │ │ - Diagram type detection │ +└─────────────┘ └─────────────┘ │ - Entity/relationship extract │ + │ - Mermaid syntax generation │ + └─────────────────────────────────┘ +``` + +### Key Components + +**WhiteboardScanner** (`DocFlow.Vision/WhiteboardScanner.cs`) +- Orchestrates the scanning pipeline +- Handles image loading and format detection +- Manages diagram type detection +- Converts AI output to SemanticModel + +**ClaudeProvider** (`DocFlow.AI/Providers/ClaudeProvider.cs`) +- Implements `IAiProvider` interface +- Handles Claude API communication +- Supports vision (image analysis) and text completion +- Multi-source API key resolution + +### Prompt Engineering + +The whiteboard scanner uses carefully crafted prompts: + +1. **Diagram Type Detection**: Quick classification of diagram type with confidence score +2. **Entity Extraction**: Detailed analysis to extract classes, properties, methods +3. **Relationship Mapping**: Identify inheritance, composition, association patterns +4. **Mermaid Generation**: Output valid Mermaid classDiagram syntax + +--- + +## Integration Module Architecture + +The Integration module (scaffolded, not fully implemented) extends the canonical model pattern to API integrations: + +``` +┌─────────────────────────────────────────────────────────────────────────┐ +│ External API Ecosystem │ +├─────────────────┬─────────────────┬─────────────────┬───────────────────┤ +│ OpenAPI 3.x │ Swagger 2.0 │ GraphQL │ JSON Samples │ +└────────┬────────┴────────┬────────┴────────┬────────┴─────────┬─────────┘ + │ │ │ │ + └─────────────────┴─────────────────┴──────────────────┘ + │ + ▼ + ┌───────────────────────────────┐ + │ Canonical Semantic Model │ + │ (Same as Code/Diagrams!) │ + └───────────────┬───────────────┘ + │ + ┌───────────────┴───────────────┐ + │ CDM Mapper │ + │ (IMS-powered mapping) │ + └───────────────┬───────────────┘ + │ + ▼ + ┌───────────────────────────────┐ + │ Internal Canonical Model │ + │ (Your Domain Model) │ + └───────────────────────────────┘ +``` + +### Pre-built Domain Patterns + +The Integration module includes pre-seeded patterns for common domains: + +**Aviation Domain:** +| External Pattern | Canonical Target | Confidence | +|------------------|------------------|------------| +| `tail_num`, `aircraft_id` | TailNumber | 95% | +| `arr_time`, `eta` | ArrivalDateTime | 93% | +| `pax`, `passenger_count` | PassengerCount | 90% | + +### SLA Validation + +The SlaValidator checks data freshness to catch stale data issues: + +```csharp +var report = await slaValidator.ValidateDataFreshnessAsync(new SlaValidationRequest +{ + EndpointUrl = "https://api.example.com/v1/data", + ExpectedMaxAge = TimeSpan.FromSeconds(30), + SampleCount = 100 +}); +``` + +See [docs/design/integration-module.md](design/integration-module.md) for full design. + +--- + +## Intelligent Mapping Service (IMS) + +The IMS (designed, not fully implemented) learns transformation patterns from examples: + +``` +┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ +│ Observed │────▶│ Pattern │────▶│ Learned │ +│ Transformation│ │ Extraction │ │ Patterns │ +└─────────────────┘ └─────────────────┘ └────────┬────────┘ + │ + ▼ +┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ +│ Suggestions │◀────│ Pattern │◀────│ New Input │ +│ with Confidence│ │ Matching │ │ │ +└─────────────────┘ └─────────────────┘ └─────────────────┘ +``` + +### Key Concepts + +- **LearnedPattern**: A transformation pattern with confidence score +- **PatternMatcher**: Applies patterns to new inputs +- **FeedbackLoop**: User corrections improve future suggestions + +--- + +## Project Dependencies + +``` +DocFlow.CLI +├── DocFlow.Core # Canonical model, abstractions +├── DocFlow.Diagrams # Mermaid parsing & generation +│ └── DocFlow.Core +├── DocFlow.CodeAnalysis # Roslyn-based C# parsing +│ └── DocFlow.Core +├── DocFlow.CodeGen # C# code generation +│ └── DocFlow.Core +├── DocFlow.Vision # Whiteboard scanning +│ ├── DocFlow.Core +│ └── DocFlow.AI +├── DocFlow.AI # AI provider abstraction +│ └── DocFlow.Core +├── DocFlow.IMS # Pattern learning +│ └── DocFlow.Core +├── DocFlow.Ontology # DDD classification +│ └── DocFlow.Core +├── DocFlow.Integration # API integration +│ ├── DocFlow.Core +│ ├── DocFlow.IMS +│ └── DocFlow.CodeGen +├── DocFlow.Documents # Document pipeline (planned) +│ └── DocFlow.Core +└── DocFlow.Web # Web UI (planned) + └── DocFlow.Core +``` + +--- + +## Design Principles + +### 1. Semantic Preservation +All transformations preserve meaning. A class in C# should have the same semantic representation whether it came from source code, a Mermaid diagram, or a whiteboard photo. + +### 2. Extensibility +Adding a new format requires only a parser and/or generator. The canonical model stays unchanged. + +### 3. DDD-First +The model understands Domain-Driven Design patterns natively. Aggregates, entities, and value objects are first-class concepts. + +### 4. Async All the Way +All I/O-bound operations are async with CancellationToken support. + +### 5. Nullable Safety +Nullable reference types are enabled throughout. No `NullReferenceException` surprises. + +--- + +## Technology Stack + +| Layer | Technology | +|-------|------------| +| Runtime | .NET 8.0 | +| Language | C# 12 | +| C# Parsing | Microsoft.CodeAnalysis.CSharp (Roslyn) | +| CLI | System.CommandLine + Spectre.Console | +| AI | Anthropic Claude API | +| OpenAPI | Microsoft.OpenApi.Readers | +| Testing | xUnit + FluentAssertions | diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md new file mode 100644 index 0000000..568a10e --- /dev/null +++ b/docs/CHANGELOG.md @@ -0,0 +1,114 @@ +# Changelog + +All notable changes to DocFlow will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.1.0-preview] - 2025-01-04 + +### Added + +#### Core Pipeline +- **Canonical Semantic Model** - Universal intermediate representation for all transformations +- **SemanticModel** with entities, relationships, and namespaces +- **DDD Classifications** - AggregateRoot, Entity, ValueObject, DomainService, DomainEvent, Repository, Interface, Enum +- **Relationship Types** - Inheritance, Composition, Aggregation, Association, Dependency, Implementation + +#### C# to Mermaid (DocFlow.CodeAnalysis + DocFlow.Diagrams) +- Roslyn-based C# parsing for classes, records, interfaces, enums +- Property extraction with types and visibility modifiers +- Method extraction with parameters and return types +- Inheritance and interface implementation detection +- Composition/aggregation inference from collection properties +- DDD stereotype detection from naming conventions +- Mermaid classDiagram generation with proper syntax + +#### Mermaid to C# (DocFlow.Diagrams + DocFlow.CodeGen) +- Mermaid classDiagram parser with stereotype support +- C# code generator with nullable-enabled output +- Records for ValueObjects, classes for Entities +- XML documentation comment generation +- Proper access modifier mapping (+, -, #) + +#### Round-Trip Support +- Full bidirectional transformation: C# → Mermaid → C# +- Semantic preservation across transformations +- `--compare` flag for diff visualization + +#### Whiteboard Scanner (DocFlow.Vision + DocFlow.AI) +- AI-powered diagram extraction from photos +- Claude Vision API integration (claude-sonnet-4-20250514) +- Diagram type detection with confidence scoring +- Support for JPG, PNG, GIF, WEBP formats +- Context hints for improved accuracy + +#### Claude API Integration (DocFlow.AI) +- `ClaudeProvider` with vision and text completion support +- Multi-source API key resolution: + 1. Environment variable: `ANTHROPIC_API_KEY` + 2. User config: `~/.docflow/config.json` + 3. Project config: `./docflow.json` +- Helpful error messages with configuration instructions + +#### CLI (DocFlow.CLI) +- Professional CLI with System.CommandLine +- Rich output with Spectre.Console (colors, tables, panels) +- ASCII art banner +- Commands: + - `diagram` (alias: `d`) - Generate Mermaid from C# + - `codegen` (alias: `c`) - Generate C# from Mermaid + - `roundtrip` (alias: `r`) - Full round-trip test + - `scan` (alias: `s`) - Whiteboard scanning +- Global options: `--verbose`, `--quiet` + +#### Integration Module (DocFlow.Integration) - Scaffolded +- OpenAPI 3.x parser foundation (`OpenApiParser`) +- CDM mapping engine design (`CdmMapper`) +- SLA validation for data freshness (`SlaValidator`) +- Pre-built aviation domain patterns (`ApiMappingPatterns`) +- Integration specification model (`IntegrationSpec`) + +#### Testing +- 91+ unit tests across 3 test projects +- DocFlow.CodeAnalysis.Tests (20 tests) +- DocFlow.Diagrams.Tests (52 tests) +- DocFlow.CodeGen.Tests (19 tests) + +#### Documentation +- Comprehensive README with feature status +- CLAUDE.md for AI assistant context +- Architecture documentation +- CLI reference +- Integration module design document + +### Technical Details + +- **.NET 8.0** with C# 12 features +- **Nullable reference types** enabled throughout +- **Async/await** with CancellationToken support +- **Records** for immutable types +- **Collection expressions** for clean syntax + +### Dependencies + +- Microsoft.CodeAnalysis.CSharp (Roslyn) - C# parsing +- Spectre.Console - CLI framework +- System.CommandLine - Command parsing +- Microsoft.OpenApi.Readers - OpenAPI parsing +- OpenCvSharp4 - Image preprocessing (Vision) + +--- + +## Unreleased + +### Planned for v0.2.0 +- IMS (Intelligent Mapping Service) pattern learning +- PlantUML support +- Sequence diagram support +- Full Integration module implementation + +### Planned for v0.3.0 +- PDF/Word document pipeline +- VS Code extension +- Web UI (Blazor) diff --git a/docs/CLI-REFERENCE.md b/docs/CLI-REFERENCE.md new file mode 100644 index 0000000..e5682d9 --- /dev/null +++ b/docs/CLI-REFERENCE.md @@ -0,0 +1,327 @@ +# CLI Reference + +Complete documentation for the DocFlow command-line interface. + +## Installation + +```bash +# From source +dotnet run --project src/DocFlow.CLI -- [options] + +# As installed tool +docflow [options] +``` + +## Global Options + +These options are available on all commands: + +| Option | Alias | Description | +|--------|-------|-------------| +| `--verbose` | `-v` | Show detailed output including entity tables and full generated content | +| `--quiet` | `-q` | Minimal output, only errors. Useful for scripting | +| `--help` | `-h`, `-?` | Show help and usage information | + +--- + +## Commands + +### diagram + +Generate a Mermaid class diagram from C# source code. + +**Usage:** +```bash +docflow diagram [options] +docflow d [options] +``` + +**Arguments:** + +| Argument | Description | +|----------|-------------| +| `` | C# source file or directory to parse | + +**Options:** + +| Option | Alias | Description | +|--------|-------|-------------| +| `--output ` | `-o` | Output file path (default: same name with .mmd extension) | +| `--recursive` | `-r` | Process all .cs files in directory recursively | +| `--no-relationships` | | Exclude relationship lines from diagram | + +**Examples:** + +```bash +# Single file +docflow diagram Domain/Order.cs + +# Directory (non-recursive) +docflow diagram Domain/ + +# Directory (recursive) with custom output +docflow diagram src/Domain -r -o architecture.mmd + +# Exclude relationships +docflow diagram Order.cs --no-relationships + +# Verbose output +docflow diagram Order.cs -v +``` + +**Output:** + +- Creates a `.mmd` file with valid Mermaid classDiagram syntax +- Displays entity count and relationship count +- Shows generated Mermaid content (unless `--quiet`) + +--- + +### codegen + +Generate C# code from a Mermaid class diagram. + +**Usage:** +```bash +docflow codegen [options] +docflow c [options] +``` + +**Arguments:** + +| Argument | Description | +|----------|-------------| +| `` | Mermaid diagram file (.mmd) to parse | + +**Options:** + +| Option | Alias | Description | +|--------|-------|-------------| +| `--output ` | `-o` | Output file path (default: same name with .cs extension) | +| `--namespace ` | `-n` | Namespace for generated code (default: derived from filename) | +| `--style