# belav/csharpier architecture

> Architecture diagram of the GitHub repository belav/csharpier, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/belav/csharpier
- Repository: https://github.com/belav/csharpier

## Overview

##### Main Components
- Core Formatting Engine – This is the backbone of CSharpier and includes components responsible for parsing C# code (using Roslyn), generating the syntax, applying formatting rules, and then printing the formatted output. It’s represented by modules like “CSharpier”, “CodeFormatter”, “DocPrinter”, “SyntaxPrinter”, and related utility classes.
- CLI Application – Found in Src/CSharpier.Cli and its tests (Src/CSharpier.Cli.Tests). This component provides a command-line interface where a user can invoke “dotnet csharpier” to format code.
- Integration/Extension Projects – These include components for editor integrations such as Visual Studio (Src/CSharpier.VisualStudio), Rider (Src/CSharpier.Rider), and VSCode, as well as integration with MsBuild (Src/CSharpier.MsBuild) and possibly other build tools.
- Playground & Website – The Playground (Src/CSharpier.Playground) and Website (Src/Website) provide user interfaces (often web-based) for demo purposes, documentation, and an online “try-it-out” experience.
- Testing and Code Generation – There are dedicated test projects (in Tests and various Src/CSharpier.Tests directories) as well as generators (e.g., Src/CSharpier.Generators, Src/CSharpier.FakeGenerators) which help validate the formatting rules.
- Build and Infrastructure Scripts – The repository also includes various CI/CD workflows, configuration files (e.g., .github/workflows), Dockerfiles, and helper scripts (in Shell and Scripts directories) which orchestrate automated testing, publishing, and deployment.

##### Relationships and Interactions
- The Playground and Website interact with both the core services and potentially the CLI interfaces in a client-server or web service-like pattern to provide a live demonstration of the formatting.
- Testing components are connected to the core engine and CLI components, ensuring that changes in the formatting logic trigger comprehensive automated tests.
- Code generators and tools (from the Generators folders) interface with the core library or help update/reinforce the compatibility between new Roslyn features and the tool’s formatting output.
- The CI/CD and build scripts (GitHub workflows, Dockerfiles, shell scripts) interact with all the above components to build, test, and deploy the tool and its extensions.

##### Architectural Patterns and Design Principles
- Modularity and Separation of Concerns: The project is structured into separate solutions, projects, and libraries to decouple the engine from the different integration points.
- Reusability: The core formatting library is reused across the CLI, integration projects, and even for generating formatted documentation on the website.
- Automated Testing and CI: Multiple test suites (including integration tests, end-to-end tests, and formatting tests) help ensure the tool maintains a consistent output.
- Consistent Configuration Management: Use of Directory.Build.props/Directory.Packages.props and centralized configuration across the solution that helps maintain consistent dependency versions and build settings.

##### Incorporate Relevant Technologies and Frameworks
- .NET / C# and Roslyn – The primary platform and language; Roslyn is the parsing and code analysis engine.
- Prettier-inspired Printing Engine – While the printing process is evolved from the original prettier, it has been adapted to cater to C# formatting rules.
- Docker, GitHub Actions, and MSBuild – Employed for CI/CD, testing, packaging, and deployment.
- Web Technologies – In the Website and Playground (e.g., use of Docusaurus for documentation and modern front-end frameworks in ClientApp).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Dependency
    E("Roslyn & .NET"):::external

    %% Core Formatting Engine and Modules
    subgraph "Core Formatting"
        CE("Core Formatting Engine"):::core
        DP("DocPrinter"):::module
        SP("SyntaxPrinter"):::module
    end

    %% Consumers / Integration Endpoints
    subgraph "Consumers"
        CLI("CLI Application"):::integration
        VSInt("Visual Studio Integration"):::integration
        Rider("Rider Integration"):::integration
        MsBuild("MsBuild Integration"):::integration
        VSCode("VSCode Integration"):::integration
        PG("Playground"):::integration
        WS("Website"):::integration
    end

    %% Testing and Code Generation
    subgraph "Testing & Code Generation"
        CLIT("CLI Tests"):::testing
        CT("CSharpier Tests"):::testing
        OT("Other Tests"):::testing
        Gen("CSharpier Generators"):::testing
        FG("CSharpier FakeGenerators"):::testing
    end

    %% Build and Infrastructure Scripts
    BCD("Build/CD Scripts"):::build

    %% Relationships
    E -->|"provides"| CE

    CLI -->|"calls"| CE
    VSInt -->|"calls"| CE
    Rider -->|"calls"| CE
    MsBuild -->|"calls"| CE
    VSCode -->|"calls"| CE
    PG -->|"demonstrates"| CE
    WS -->|"demonstrates"| CE

    CLIT -->|"tests"| CLI
    CT -->|"tests"| CE
    OT -->|"tests"| CE

    Gen -->|"updates"| CE
    FG -->|"updates"| CE

    BCD -->|"builds"| CE
    BCD -->|"builds"| CLI
    BCD -->|"builds"| VSInt
    BCD -->|"builds"| Rider
    BCD -->|"builds"| MsBuild
    BCD -->|"builds"| VSCode
    BCD -->|"builds"| PG
    BCD -->|"builds"| WS

    %% Styles
    classDef core fill:#E6E6FA,stroke:#333,stroke-width:2px;
    classDef module fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef integration fill:#FFDAB9,stroke:#333,stroke-width:2px;
    classDef testing fill:#C1FFC1,stroke:#333,stroke-width:2px;
    classDef build fill:#F5DEB3,stroke:#333,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#333,stroke-width:2px;

    %% Click Events
    click CE "https://github.com/belav/csharpier/tree/main/Src/CSharpier"
    click DP "https://github.com/belav/csharpier/tree/main/Src/CSharpier/DocPrinter"
    click SP "https://github.com/belav/csharpier/tree/main/Src/CSharpier/SyntaxPrinter"
    click CLI "https://github.com/belav/csharpier/blob/main/Src/CSharpier.Cli"
    click CLIT "https://github.com/belav/csharpier/blob/main/Src/CSharpier.Cli.Tests"
    click VSInt "https://github.com/belav/csharpier/blob/main/Src/CSharpier.VisualStudio"
    click Rider "https://github.com/belav/csharpier/blob/main/Src/CSharpier.Rider"
    click MsBuild "https://github.com/belav/csharpier/blob/main/Src/CSharpier.MsBuild"
    click VSCode "https://github.com/belav/csharpier/blob/main/Src/CSharpier.VSCode"
    click PG "https://github.com/belav/csharpier/blob/main/Src/CSharpier.Playground"
    click WS "https://github.com/belav/csharpier/tree/main/Src/Website"
    click Gen "https://github.com/belav/csharpier/blob/main/Src/CSharpier.Generators"
    click FG "https://github.com/belav/csharpier/blob/main/Src/CSharpier.FakeGenerators"
    click CT "https://github.com/belav/csharpier/blob/main/Src/CSharpier.Tests"
    click OT "https://github.com/belav/csharpier/tree/main/Tests"
    click BCD "https://github.com/belav/csharpier/blob/main/.github"
```
