|
| 1 | +<h1 align="center">GraphCSharp</h1> |
| 2 | + |
| 3 | +<p align="center"> |
| 4 | + <strong>Visualize any C# codebase as an interactive D3 graph — drop one GitHub Action into your repo.</strong> |
| 5 | +</p> |
| 6 | + |
| 7 | +<p align="center"> |
| 8 | + <a href="https://github.com/TheSmallPixel/GraphCSharp/actions/workflows/ci.yml"><img src="https://github.com/TheSmallPixel/GraphCSharp/actions/workflows/ci.yml/badge.svg" alt="CI"></a> |
| 9 | + <a href="https://github.com/TheSmallPixel/GraphCSharp/releases/latest"><img src="https://img.shields.io/github/v/release/TheSmallPixel/GraphCSharp" alt="Release"></a> |
| 10 | + <a href="LICENSE"><img src="https://img.shields.io/github/license/TheSmallPixel/GraphCSharp" alt="License"></a> |
| 11 | + <img src="https://img.shields.io/badge/.NET-8.0-512BD4" alt=".NET 8"> |
| 12 | + <a href="https://github.com/TheSmallPixel/GraphCSharp/stargazers"><img src="https://img.shields.io/github/stars/TheSmallPixel/GraphCSharp?style=social" alt="Stars"></a> |
| 13 | +</p> |
| 14 | + |
| 15 | +<p align="center"> |
| 16 | + <a href="https://thesmallpixel.github.io/GraphCSharp/"><strong>→ Open the live demo</strong></a> |
| 17 | +</p> |
| 18 | + |
| 19 | +<!-- TODO(media): replace with docs/demo.gif showing the interactive graph in action --> |
| 20 | + |
| 21 | + |
| 22 | +## What it does |
| 23 | + |
| 24 | +Reading C# architecture from a folder tree is slow. Roslyn can extract the real call graph, but wiring it up — analyzer, JSON schema, D3 layout, GitHub Pages — is a side-project of its own. **GraphCSharp is that side-project, packaged as a single GitHub Action so any repo gets an interactive graph on every push.** |
| 25 | + |
| 26 | +## 30-second example |
| 27 | + |
| 28 | +Add `.github/workflows/code-graph.yml` to your repo: |
| 29 | + |
| 30 | +```yaml |
| 31 | +name: Generate Code Graph |
| 32 | +on: |
| 33 | + push: |
| 34 | + branches: [main] |
| 35 | + |
| 36 | +permissions: |
| 37 | + contents: write |
| 38 | + |
| 39 | +jobs: |
| 40 | + graph: |
| 41 | + runs-on: ubuntu-latest |
| 42 | + steps: |
| 43 | + - uses: TheSmallPixel/GraphCSharp@v1 |
| 44 | + with: |
| 45 | + source-path: ./src |
| 46 | + docs-dir: docs |
| 47 | + commit-changes: 'true' |
| 48 | +``` |
| 49 | +
|
| 50 | +Then enable GitHub Pages on the `docs/` folder. Your live graph appears at `https://<user>.github.io/<repo>/`. |
| 51 | + |
| 52 | +## Inputs |
| 53 | + |
| 54 | +| Name | Default | Description | |
| 55 | +| --- | --- | --- | |
| 56 | +| `source-path` | `./src` | Directory scanned recursively for `.cs` files. | |
| 57 | +| `docs-dir` | `docs` | Where `graph.json` and `index.html` are written. | |
| 58 | +| `index-file` | `index.html` | Visualizer HTML filename. Copied from this action if missing. | |
| 59 | +| `commit-changes` | `false` | When `true`, commits the generated graph back to your repo. | |
| 60 | + |
| 61 | +## Links |
| 62 | + |
| 63 | +- **Live demo:** https://thesmallpixel.github.io/GraphCSharp/ |
| 64 | +- **Changelog:** [CHANGELOG.md](CHANGELOG.md) |
| 65 | +- **Contributing:** [CONTRIBUTING.md](CONTRIBUTING.md) |
| 66 | +- **License:** [LICENSE](LICENSE) |
| 67 | + |
| 68 | +## How it works |
| 69 | + |
| 70 | +1. The action checks out your repo and provisions .NET 8. |
| 71 | +2. Builds the Roslyn-based analyzer in `tools/CodeAnalysisTool`. |
| 72 | +3. Walks every `.cs` file under `source-path`, emitting nodes (namespaces, classes, methods, properties) and links (containment, calls, inheritance, type usage) as `docs/graph.json`. |
| 73 | +4. Drops a D3 visualizer into `docs/index.html` if one isn't already there. |
| 74 | +5. Optionally commits both files back so GitHub Pages serves a fresh graph on every push. |
| 75 | + |
| 76 | +## Development |
| 77 | + |
| 78 | +Requires the .NET 8 SDK. |
| 79 | + |
| 80 | +```bash |
| 81 | +git clone https://github.com/TheSmallPixel/GraphCSharp |
| 82 | +cd GraphCSharp |
| 83 | +dotnet test tools/CodeAnalysisTool.Tests/CodeAnalysisTool.Tests.csproj |
| 84 | +``` |
| 85 | + |
| 86 | +To run the analyzer against any folder of `.cs` files: |
| 87 | + |
| 88 | +```bash |
| 89 | +dotnet run --project tools/CodeAnalysisTool -- <source-path> ./docs |
| 90 | +``` |
| 91 | + |
| 92 | +Open `docs/index.html` to inspect the result locally. |
| 93 | + |
| 94 | +## License |
| 95 | + |
| 96 | +MIT — see [LICENSE](LICENSE). |
0 commit comments