Sharpitect 0.2.4
dotnet tool install --global Sharpitect --version 0.2.4
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
dotnet tool install --local Sharpitect --version 0.2.4
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=Sharpitect&version=0.2.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
nuke :add-package Sharpitect --version 0.2.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Sharpitect
Sharpitect generates C4 architecture diagrams from annotated C# codebases. It analyzes your code using Roslyn and builds a declaration graph that can be queried and visualized.
Features
- Code Analysis - Extracts declarations (classes, interfaces, methods, properties, etc.) and their relationships using Roslyn
- Declaration Graph - Builds a queryable graph of code elements with containment and reference relationships
- Graph Search - Search for declarations by name with multiple match modes and kind filters
- SQLite Persistence - Persist and query the declaration graph from a SQLite database
- C4 Model Mapping - Maps code elements to C4 architecture model levels
C4 Conventions
Sharpitect maps C# constructs to C4 model elements following these conventions:
Systems
- Systems are solutions (.sln files)
Containers
- Containers are projects that generate an executable
Components
- Components cannot be nested, but they can be grouped by namespaces or projects
- Components may be projects, namespaces, or groups
- Use the
[Component]attribute to mark types as C4 components
Code
- Code elements are automatically extracted class diagrams including classes, interfaces, methods, and properties
Usage
Analyzing a Solution
using Sharpitect.Analysis.Analyzers;
using Sharpitect.Analysis.Persistence;
// Create repository
var repository = new SqliteGraphRepository("architecture.db");
await repository.InitializeAsync();
// Analyze solution
var analyzer = new GraphSolutionAnalyzer(repository);
await analyzer.AnalyzeAsync("path/to/solution.sln");
Searching the Graph
using Sharpitect.Analysis.Graph;
using Sharpitect.Analysis.Search;
// Create search service with in-memory source
var graph = new DeclarationGraph();
var source = new InMemoryGraphSource(graph);
var searchService = new GraphSearchService(source);
// Search for classes containing "Service"
var query = new SearchQuery
{
SearchText = "Service",
MatchMode = SearchMatchMode.Contains,
KindFilter = [DeclarationKind.Class]
};
var results = await searchService.SearchAsync(query);
Search Options
- SearchText - The text to search for in Name and FullyQualifiedName
- MatchMode - How to match:
Contains,StartsWith,EndsWith, orExact - KindFilter - Optional filter by declaration kind (Class, Interface, Method, etc.)
- CaseSensitive - Whether the search is case-sensitive (default: false)
Project Structure
- Sharpitect.Tool - Command-line tool entry point
- Sharpitect.Analysis - Analysis engine with graph, persistence, search, and analyzers
- Sharpitect.Attributes - Attributes for annotating code (targets .NET Framework 4.8 for broad compatibility)
- Sharpitect.Analysis.Test - Unit tests
Installation
Installing as a Global Tool
dotnet tool install -g Sharpitect.Tool
If the sharpitect command is not found after installation, you need to add the .NET tools directory to your PATH. Add the following line to your shell configuration file (~/.bashrc, ~/.bash_profile, or ~/.zshrc):
export PATH="$PATH:$HOME/.dotnet/tools"
Then reload your shell configuration:
source ~/.bashrc # or ~/.bash_profile or ~/.zshrc
Alternatively, you can run this one-liner to add it permanently:
echo 'export PATH="$PATH:$HOME/.dotnet/tools"' >> ~/.bashrc && source ~/.bashrc
Building
dotnet build Sharpitect.sln
Testing
dotnet test Sharpitect.sln
License
See LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.