### YAML View Configuration Example Source: https://context7.com/krzysztofreczek/go-structurizr/llms.txt An example of a YAML configuration file used by `view.NewViewFromConfigFile` to define view properties. It specifies the diagram title, line color, styles for different component tags (including background color, font color, border color, and shape), component tags to include, and root component tags to start the diagram from. ```yaml view: title: "MyApp Architecture - Component Diagram" line_color: 000000ff styles: - id: SERVICE background_color: 1a4577ff font_color: ffffffff border_color: 000000ff - id: HANDLER background_color: 2d69b7ff font_color: ffffffff border_color: 000000ff - id: DATABASE background_color: 4a904aff font_color: ffffffff border_color: 000000ff shape: database - id: EXTERNAL background_color: c8c8c8ff font_color: 000000ff border_color: 000000ff # Only include components with these tags component_tags: - SERVICE - HANDLER - DATABASE - EXTERNAL # Start diagram from components with these tags root_component_tags: - SERVICE ``` -------------------------------- ### Complete YAML Example for Scraper and View in Go Source: https://context7.com/krzysztofreczek/go-structurizr/llms.txt Demonstrates loading both scraper and view configurations from a single YAML file. This approach allows for externalizing architecture definitions and styles, making them version-controllable and modifiable without code changes. It requires the 'go-structurizr/pkg/scraper' and 'go-structurizr/pkg/view' packages. ```go package main import ( "os" "github.com/krzysztofreczek/go-structurizr/pkg/scraper" "github.com/krzysztofreczek/go-structurizr/pkg/view" ) func main() { // Load scraper from YAML s, err := scraper.NewScraperFromConfigFile("./config.yaml") if err != nil { panic(err) } // Scrape your application structure := s.Scrape(myApplication) // Load view from same YAML v, err := view.NewViewFromConfigFile("./config.yaml") if err != nil { panic(err) } // Render to file f, _ := os.Create("architecture.plantuml") defer f.Close() v.RenderStructureTo(structure, f) } ``` -------------------------------- ### Go Structurizr: Full Pipeline Example Source: https://context7.com/krzysztofreczek/go-structurizr/llms.txt This Go code demonstrates a complete pipeline for go-structurizr. It configures a scraper with rules for different component types (Service, Repository, Cache, External, Client), scrapes a sample application structure, defines view styles for these components, and finally renders the structure to a PlantUML file. Dependencies include the go-structurizr library. Inputs are the application's Go types and the scraper configuration. Outputs are a PlantUML file representing the architecture. ```go package main import ( "image/color" "os" "github.com/krzysztofreczek/go-structurizr/pkg/model" "github.com/krzysztofreczek/go-structurizr/pkg/scraper" "github.com/krzysztofreczek/go-structurizr/pkg/view" ) // Application structure to be scraped type Application struct { UserService *UserService OrderService *OrderService PaymentGateway *PaymentGateway } type UserService struct { repo *UserRepository cache *RedisCache } type OrderService struct { repo *OrderRepository userClient *UserServiceClient } type UserRepository struct{} type OrderRepository struct{} type RedisCache struct{} type PaymentGateway struct{} type UserServiceClient struct{} func main() { // 1. Configure and build scraper config := scraper.NewConfiguration( "github.com/myorg/myapp", ) s := scraper.NewScraper(config) // Register rules for different component types serviceRule, _ := scraper.NewRule(). WithPkgRegexps(".*"). WithNameRegexp(".*Service$"). WithApplyFunc(func(name string, groups ...string) model.Info { return model.ComponentInfo(name, "Business logic service", "Go", "SERVICE") }). Build() s.RegisterRule(serviceRule) repoRule, _ := scraper.NewRule(). WithPkgRegexps(".*"). WithNameRegexp(".*Repository$"). WithApplyFunc(func(name string, groups ...string) model.Info { return model.ComponentInfo(name, "Data access layer", "PostgreSQL", "REPOSITORY") }). Build() s.RegisterRule(repoRule) cacheRule, _ := scraper.NewRule(). WithPkgRegexps(".*"). WithNameRegexp(".*Cache$"). WithApplyFunc(func(name string, groups ...string) model.Info { return model.ComponentInfo(name, "Caching layer", "Redis", "CACHE") }). Build() s.RegisterRule(cacheRule) gatewayRule, _ := scraper.NewRule(). WithPkgRegexps(".*"). WithNameRegexp(".*Gateway$"). WithApplyFunc(func(name string, groups ...string) model.Info { return model.ComponentInfo(name, "External gateway", "HTTP", "EXTERNAL") }). Build() s.RegisterRule(gatewayRule) clientRule, _ := scraper.NewRule(). WithPkgRegexps(".*"). WithNameRegexp(".*Client$"). WithApplyFunc(func(name string, groups ...string) model.Info { return model.ComponentInfo(name, "Service client", "gRPC", "CLIENT") }). Build() s.RegisterRule(clientRule) // 2. Scrape application structure app := &Application{ UserService: &UserService{ repo: &UserRepository{}, cache: &RedisCache{}, }, OrderService: &OrderService{ repo: &OrderRepository{}, userClient: &UserServiceClient{}, }, PaymentGateway: &PaymentGateway{}, } structure := s.Scrape(app) // 3. Configure and build view v := view.NewView(). WithTitle("MyApp - C4 Component Diagram"). WithComponentStyle( view.NewComponentStyle("SERVICE"). WithBackgroundColor(color.RGBA{R: 0x1a, G: 0x45, B: 0x77, A: 0xff}). WithFontColor(color.White). Build(), ). WithComponentStyle( view.NewComponentStyle("REPOSITORY"). WithBackgroundColor(color.RGBA{R: 0x4a, G: 0x90, B: 0x4a, A: 0xff}). WithFontColor(color.White). WithShape("database"). Build(), ). WithComponentStyle( view.NewComponentStyle("CACHE"). WithBackgroundColor(color.RGBA{R: 0xff, G: 0x99, B: 0x00, A: 0xff}). WithFontColor(color.Black). WithShape("database"). Build(), ). WithComponentStyle( view.NewComponentStyle("EXTERNAL"). WithBackgroundColor(color.RGBA{R: 0xc8, G: 0xc8, B: 0xc8, A: 0xff}). WithFontColor(color.Black). Build(), ). WithComponentStyle( view.NewComponentStyle("CLIENT"). WithBackgroundColor(color.RGBA{R: 0x99, G: 0xcc, B: 0xff, A: 0xff}). WithFontColor(color.Black). Build(), ). WithRootComponentTag("SERVICE"). Build() // 4. Render to PlantUML file os.MkdirAll(".out", 0755) f, err := os.Create(".out/architecture.plantuml") if err != nil { panic(err) } defer f.Close() if err := v.RenderStructureTo(structure, f); err != nil { panic(err) } } ``` -------------------------------- ### View Configuration from YAML Source: https://github.com/krzysztofreczek/go-structurizr/blob/master/README.md Example YAML configuration for defining a view. This includes title, line color, styles, root component tags, and component tags. ```yaml # go-structurizr.yml view: title: "Title" line_color: 000000ff styles: - id: TAG background_color: ffffffff font_color: 000000ff border_color: 000000ff shape: database root_component_tags: - ROOT component_tags: - TAG ``` -------------------------------- ### Instantiate Scraper from YAML Configuration in Go Source: https://github.com/krzysztofreczek/go-structurizr/blob/master/README.md This Go code shows how to initialize the scraper using a YAML configuration file. The file defines package prefixes and rules for component identification, simplifying scraper setup. ```go s, err := scraper.NewScraperFromConfigFile("./go-structurizr.yml") ``` -------------------------------- ### Register Rule with Named Groups in Go Source: https://github.com/krzysztofreczek/go-structurizr/blob/master/README.md This Go example illustrates registering a rule that utilizes named groups from a regular expression to dynamically construct component information. The apply function can access these matched groups to provide more context. ```go r, err := scraper.NewRule(). WithPkgRegexps("github.com/org/pkg/foo/.*", "github.com/org/pkg/bar/.*"). WithNameRegexp(`^(\w*)\.(\w*)Client$`). WithApplyFunc( func(_ string, groups ...string) model.Info { // Perform checks on the groups, then: n := fmt.Sprintf("Client of external %s service", groups[1]) return model.ComponentInfo(n, "foo client", "gRPC", "TAG") }). Build() err = s.RegisterRule(r) ``` -------------------------------- ### Create View From Configuration File Source: https://context7.com/krzysztofreczek/go-structurizr/llms.txt Initializes a view builder from a YAML configuration file, allowing externalized styling and filtering rules. This simplifies managing complex view configurations. Requires the 'github.com/krzysztofreczek/go-structurizr/pkg/view' package and standard Go libraries for file operations. The YAML file defines view properties like title, line color, component styles, and tag filtering. ```go package main import ( "os" "github.com/krzysztofreczek/go-structurizr/pkg/view" ) func main() { v, err := view.NewViewFromConfigFile("./go-structurizr.yaml") if err != nil { panic(err) } f, _ := os.Create("architecture.plantuml") defer f.Close() err = v.RenderStructureTo(structure, f) if err != nil { panic(err) } } ``` -------------------------------- ### Create Component Detection Rules with Go Structurizr Source: https://context7.com/krzysztofreczek/go-structurizr/llms.txt Demonstrates how to programmatically create component detection rules using `scraper.NewRule()`. Rules can match types based on package and name regular expressions, and apply a function to generate component information. This is useful for defining custom component detection logic within your Go application. ```go package main import ( "fmt" "github.com/krzysztofreczek/go-structurizr/pkg/model" "github.com/krzysztofreczek/go-structurizr/pkg/scraper" ) func main() { config := scraper.NewConfiguration("github.com/myorg/myapp") s := scraper.NewScraper(config) // Rule 1: Match all types ending with "Handler" in handler packages handlerRule, err := scraper.NewRule(). WithPkgRegexps("github.com/myorg/myapp/handlers.*", "github.com/myorg/myapp/api.*"). WithNameRegexp(".*Handler$"). WithApplyFunc(func(name string, groups ...string) model.Info { return model.ComponentInfo(name, "HTTP request handler", "HTTP", "HANDLER") }). Build() if err != nil { panic(err) } s.RegisterRule(handlerRule) // Rule 2: Match all types ending with "Repository" and extract domain name repoRule, err := scraper.NewRule(). WithPkgRegexps("github.com/myorg/myapp/repositories.*", "github.com/myorg/myapp/store.*"). WithNameRegexp(`^(\w+)Repository$`) .WithApplyFunc(func(name string, groups ...string) model.Info { domain := "Unknown" if len(groups) > 0 { domain = groups[0] } desc := fmt.Sprintf("Manages %s persistence", domain) return model.ComponentInfo(name, desc, "PostgreSQL", "REPOSITORY", "DATA") }). Build() if err != nil { panic(err) } s.RegisterRule(repoRule) // Rule 3: Match gRPC clients across all packages grpcRule, err := scraper.NewRule(). WithPkgRegexps(".*"). // Any package WithNameRegexp(".*Client$"). WithApplyFunc(func(name string, groups ...string) model.Info { return model.ComponentInfo(name, "External service client", "gRPC", "CLIENT", "EXTERNAL") }). Build() if err != nil { panic(err) } s.RegisterRule(grpcRule) } ``` -------------------------------- ### Instantiate Scraper with Configuration in Go Source: https://github.com/krzysztofreczek/go-structurizr/blob/master/README.md This Go code demonstrates how to instantiate a scraper with a configuration that specifies package prefixes to reflect. Types not matching these prefixes will be ignored during the scraping process. ```go config := scraper.NewConfiguration( "github.com/org/pkg", ) s := scraper.NewScraper(config) ``` -------------------------------- ### Create Scraper from YAML Configuration with Go Structurizr Source: https://context7.com/krzysztofreczek/go-structurizr/llms.txt Shows how to initialize a `scraper.Scraper` from a YAML configuration file using `scraper.NewScraperFromConfigFile()`. This allows externalizing the configuration of package prefixes and detection rules, making the application more flexible. The YAML file defines rules using regular expressions for package and type matching, and specifies component details. ```go package main import ( "fmt" "github.com/krzysztofreczek/go-structurizr/pkg/scraper" ) func main() { s, err := scraper.NewScraperFromConfigFile("./go-structurizr.yaml") if err != nil { panic(fmt.Errorf("failed to load scraper config: %w", err)) } // Scrape your application structure structure := s.Scrape(myApplication) fmt.Printf("Found %d components\n", len(structure.Components)) } ``` ```yaml configuration: pkgs: - "github.com/myorg/myapp" - "github.com/myorg/myapp/pkg" - "net/http" rules: # Match Handler types in handler packages - name_regexp: ".*Handler$" pkg_regexps: - "github.com/myorg/myapp/handlers.*" component: description: "HTTP request handler" technology: "HTTP" tags: - HANDLER # Match Repository types with regex group extraction - name_regexp: "(\w+)Repository$" pkg_regexps: - "github.com/myorg/myapp/repositories.*" component: name: "{1} Repository" # Uses captured group description: "Data persistence layer" technology: "PostgreSQL" tags: - REPOSITORY - DATA # Match Service types - name_regexp: ".*Service$" pkg_regexps: - "github.com/myorg/myapp/services.*" component: description: "Business logic service" technology: "Go" tags: - SERVICE # Match all gRPC clients - name_regexp: ".*Client$" pkg_regexps: - ".*" component: description: "External service client" technology: "gRPC" tags: - CLIENT - EXTERNAL ``` -------------------------------- ### Create Component Information Metadata with model.ComponentInfo Source: https://context7.com/krzysztofreczek/go-structurizr/llms.txt Creates component information metadata for a C4 diagram component. The function accepts variadic string arguments that are mapped to Name, Description, Technology, and Tags in order. It returns a model.Info object and can be checked for zero values using IsZero(). ```go package main import ( "fmt" "github.com/krzysztofreczek/go-structurizr/pkg/model" ) func main() { // Create component info with name, description, technology, and tags info := model.ComponentInfo( "UserService", // Name "Handles user operations", // Description "Go/gRPC", // Technology "SERVICE", // Tag 1 "CORE", // Tag 2 ) fmt.Printf("Name: %s\n", info.Name) fmt.Printf("Description: %s\n", info.Description) fmt.Printf("Technology: %s\n", info.Technology) fmt.Printf("Tags: %v\n", info.Tags) fmt.Printf("Is Empty: %v\n", info.IsZero()) // Output: // Name: UserService // Description: Handles user operations // Technology: Go/gRPC // Tags: [SERVICE CORE] // Is Empty: false } ``` -------------------------------- ### Create View Builder Programmatically Source: https://context7.com/krzysztofreczek/go-structurizr/llms.txt Constructs a view builder to configure how scraped software structures are rendered to PlantUML. Allows customization of the diagram's title, component styles (background, font, border colors, shape), filtering tags, root component tags, and line colors. Requires the 'github.com/krzysztofreczek/go-structurizr/pkg/view' package and standard Go libraries for color and file operations. ```go package main import ( "image/color" "os" "github.com/krzysztofreczek/go-structurizr/pkg/view" ) func main() { // Define custom colors serviceColor := color.RGBA{R: 0x1a, G: 0x45, B: 0x77, A: 0xff} handlerColor := color.RGBA{R: 0x2d, G: 0x69, B: 0xb7, A: 0xff} dbColor := color.RGBA{R: 0x4a, G: 0x90, B: 0x4a, A: 0xff} externalColor := color.RGBA{R: 0xc8, G: 0xc8, B: 0xc8, A: 0xff} v := view.NewView(). WithTitle("MyApp Architecture - Component Diagram"). // Style for SERVICE tagged components WithComponentStyle( view.NewComponentStyle("SERVICE"). WithBackgroundColor(serviceColor). WithFontColor(color.White). WithBorderColor(color.Black). Build(), ). // Style for HANDLER tagged components WithComponentStyle( view.NewComponentStyle("HANDLER"). WithBackgroundColor(handlerColor). WithFontColor(color.White). WithBorderColor(color.Black). Build(), ). // Style for DATABASE tagged components with database shape WithComponentStyle( view.NewComponentStyle("DATABASE"). WithBackgroundColor(dbColor). WithFontColor(color.White). WithBorderColor(color.Black). WithShape("database"). Build(), ). // Style for EXTERNAL tagged components WithComponentStyle( view.NewComponentStyle("EXTERNAL"). WithBackgroundColor(externalColor). WithFontColor(color.Black). WithBorderColor(color.Black). Build(), ). // Only show components with these tags WithComponentTag("SERVICE"). WithComponentTag("HANDLER"). WithComponentTag("DATABASE"). // Start rendering from SERVICE components WithRootComponentTag("SERVICE"). // Set connection line color WithLineColor(color.Black). Build() // Render to file f, _ := os.Create("architecture.plantuml") defer f.Close() // structure is obtained from scraper.Scrape() err := v.RenderStructureTo(structure, f) if err != nil { panic(err) } } ``` -------------------------------- ### Configure Scraper Package Prefixes with scraper.NewConfiguration Source: https://context7.com/krzysztofreczek/go-structurizr/llms.txt Creates a scraper configuration specifying which package prefixes should be processed. Only types from packages matching these prefixes will be scraped; all other packages are ignored. This helps in focusing the scraping process on relevant parts of the codebase. ```go package main import ( "github.com/krzysztofreczek/go-structurizr/pkg/scraper" ) func main() { // Configure scraper to process specific package prefixes config := scraper.NewConfiguration( "github.com/myorg/myapp", // Main application packages "github.com/myorg/myapp/pkg", // Library packages "net/http", // Standard library HTTP "database/sql", // Standard library SQL ) s := scraper.NewScraper(config) // Register rules and scrape... } ``` -------------------------------- ### Instantiate Default View (Go) Source: https://github.com/krzysztofreczek/go-structurizr/blob/master/README.md Instantiates a default view using the view builder. This provides a basic view configuration that can be further customized. ```go v := view.NewView().Build() ``` -------------------------------- ### Instantiate Customized View (Go) Source: https://github.com/krzysztofreczek/go-structurizr/blob/master/README.md Instantiates a customized view using the view builder. Allows setting title, component styles, component tags, and root component tags. ```go v := view.NewView(). WithTitle("Title"). WithComponentStyle( view.NewComponentStyle("TAG"). WithBackgroundColor(color.White). WithFontColor(color.Black). WithBorderColor(color.Black). WithShape("database"). Build(), ). WithComponentTag("TAG"). WithRootComponentTag("ROOT"). Build() ``` -------------------------------- ### Instantiate View from Config File (Go) Source: https://github.com/krzysztofreczek/go-structurizr/blob/master/README.md Loads and instantiates a view from a specified YAML configuration file. Handles potential errors during file loading and parsing. ```go v, err := view.NewViewFromConfigFile("./go-structurizr.yml") ``` -------------------------------- ### Inspecting Structure API in Go Source: https://context7.com/krzysztofreczek/go-structurizr/llms.txt This Go code snippet demonstrates how to use the `model.Structure` API to access and inspect scraped components and their relationships. It shows how to iterate through components, print their details (ID, name, kind, description, technology, tags), list relationships between components, and compute a checksum for change detection. This API is useful for programmatic analysis of the application's architecture. ```go package main import ( "fmt" "github.com/krzysztofreczek/go-structurizr/pkg/model" "github.com/krzysztofreczek/go-structurizr/pkg/scraper" ) func main() { config := scraper.NewConfiguration("github.com/myorg/myapp") s := scraper.NewScraper(config) // ... register rules ... structure := s.Scrape(myApplication) // Iterate over all components for id, component := range structure.Components { fmt.Printf("Component ID: %s\n", id) fmt.Printf(" Name: %s\n", component.Name) fmt.Printf(" Kind: %s\n", component.Kind) fmt.Printf(" Description: %s\n", component.Description) fmt.Printf(" Technology: %s\n", component.Technology) fmt.Printf(" Tags: %v\n", component.Tags) } // Check relationships between components for sourceID, targets := range structure.Relations { for targetID := range targets { fmt.Printf("Relation: %s -> %s\n", sourceID, targetID) } } // Compute checksum for change detection checksum, err := structure.Checksum() if err != nil { panic(err) } fmt.Printf("Structure checksum: %s\n", checksum) } ``` -------------------------------- ### Enabling Debug Logging in Go Source: https://context7.com/krzysztofreczek/go-structurizr/llms.txt This section explains how to enable detailed logging for go-structurizr, which is useful for understanding scraping decisions and view rendering processes. Debug logging can be activated by setting the `LOG_LEVEL` environment variable to `debug`, either globally or inline with the command execution. ```bash # Enable debug logging export LOG_LEVEL=debug # Or inline with command LOG_LEVEL=debug go run main.go ``` -------------------------------- ### YAML Configuration for go-structurizr Source: https://context7.com/krzysztofreczek/go-structurizr/llms.txt This YAML configuration defines packages to be scraped, rules for component identification and mapping, and styling for the generated C4 diagrams. It allows customization of component descriptions, technologies, tags, and visual styles, including shapes and colors. The 'view' section specifies the overall diagram title and root component tags. ```yaml configuration: pkgs: - "github.com/myorg/myapp" - "net/http" - "database/sql" rules: - name_regexp: ".*Handler.*" pkg_regexps: - ".*/handlers.*" component: description: "HTTP handler" technology: "HTTP" tags: - HANDLER - name_regexp: ".*Service$" pkg_regexps: - ".*/services.*" component: description: "Business service" technology: "Go" tags: - SERVICE - name_regexp: ".*Repository$" pkg_regexps: - ".*/repositories.*" component: description: "Data repository" technology: "PostgreSQL" tags: - REPOSITORY - name_regexp: ".*(Server|Logger)$" pkg_regexps: - ".*" component: description: "Infrastructure component" tags: - INFRASTRUCTURE view: title: "System Architecture" line_color: 000000ff styles: - id: SERVICE background_color: 1a4577ff font_color: ffffffff border_color: 000000ff - id: HANDLER background_color: 2d69b7ff font_color: ffffffff border_color: 000000ff - id: REPOSITORY background_color: 4a904aff font_color: ffffffff border_color: 000000ff shape: database - id: INFRASTRUCTURE background_color: c8c8c8ff font_color: 000000ff border_color: 000000ff root_component_tags: - SERVICE ``` -------------------------------- ### Scrape Go Structures into Components with scraper.NewScraper Source: https://context7.com/krzysztofreczek/go-structurizr/llms.txt Creates a new Scraper instance using the provided Configuration. The scraper uses reflection to traverse Go structures and identify components based on registered rules and the HasInfo interface. The Scrape method returns a structure containing the identified components. ```go package main import ( "fmt" "github.com/krzysztofreczek/go-structurizr/pkg/model" "github.com/krzysztofreczek/go-structurizr/pkg/scraper" ) type Application struct { DB *DatabaseClient Handler *HTTPHandler } type DatabaseClient struct{} func (d *DatabaseClient) Info() model.Info { return model.ComponentInfo("DB Client", "Database connection", "PostgreSQL", "DB") } type HTTPHandler struct{} func (h *HTTPHandler) Info() model.Info { return model.ComponentInfo("HTTP Handler", "API endpoints", "HTTP", "HANDLER") } func main() { config := scraper.NewConfiguration("github.com/myorg/myapp") s := scraper.NewScraper(config) app := &Application{ DB: &DatabaseClient{}, Handler: &HTTPHandler{}, } structure := s.Scrape(app) fmt.Printf("Components found: %d\n", len(structure.Components)) for id, comp := range structure.Components { fmt.Printf(" %s: %s (%s)\n", id[:8], comp.Name, comp.Kind) } } ``` -------------------------------- ### Implement HasInfo Interface for Custom Component Information Source: https://context7.com/krzysztofreczek/go-structurizr/llms.txt Implement the model.HasInfo interface on your types to provide custom component information during scraping. Types implementing HasInfo are automatically detected by the scraper without requiring explicit rules. The Info() method should return a model.Info object. ```go package main import ( "github.com/krzysztofreczek/go-structurizr/pkg/model" ) // DatabaseClient implements model.HasInfo for automatic detection type DatabaseClient struct { host string port int } func (d *DatabaseClient) Info() model.Info { return model.ComponentInfo( "Database Client", "PostgreSQL connection pool", "PostgreSQL", "DATABASE", "INFRASTRUCTURE", ) } // HTTPHandler implements model.HasInfo type HTTPHandler struct { routes []string } func (h *HTTPHandler) Info() model.Info { return model.ComponentInfo( "HTTP Handler", "REST API endpoints", "HTTP/JSON", "HANDLER", "API", ) } ``` -------------------------------- ### YAML Configuration for Scraper Rules Source: https://github.com/krzysztofreczek/go-structurizr/blob/master/README.md This YAML snippet defines the configuration for the go-structurizr scraper. It includes package prefixes and rules, specifying package regular expressions, name regular expressions, and component details like description, technology, and tags. ```yaml # go-structurizr.yml configuration: pkgs: - "github.com/org/pkg" rules: - name_regexp: "^.*Client$" pkg_regexps: - "github.com/org/pkg/foo/.*" component: description: "foo client" technology: "gRPC" tags: - TAG ``` -------------------------------- ### Register Rule with Apply Function in Go Source: https://github.com/krzysztofreczek/go-structurizr/blob/master/README.md This Go snippet shows how to create and register a rule for the scraper. The rule uses package and name regular expressions to identify components and an apply function to generate `model.Info` for matching types. ```go r, err := scraper.NewRule(). WithPkgRegexps("github.com/org/pkg/foo/.*", "github.com/org/pkg/bar/.*"). WithNameRegexp("^.*Client$"). WithApplyFunc( func(name string, _ ...string) model.Info { return model.ComponentInfo(name, "foo client", "gRPC", "TAG") }). Build() err = s.RegisterRule(r) ``` -------------------------------- ### Scrape Go Structure with Scraper in Go Source: https://github.com/krzysztofreczek/go-structurizr/blob/master/README.md After the scraper is instantiated and configured, this Go code demonstrates how to use it to scrape a given Go structure. The result is a `model.Structure` object representing the components found. ```go structure := s.Scrape(app) ``` -------------------------------- ### YAML Rule with Named Groups for Component Name Source: https://github.com/krzysztofreczek/go-structurizr/blob/master/README.md This YAML configuration demonstrates how to use named regular expression groups within a rule definition. The `{1}` placeholder in the `name` field allows dynamic generation of the component's name based on captured groups from the `name_regexp`. ```yaml rules: - name_regexp: "(\w*)\.(\w*)Client$" pkg_regexps: - "github.com/org/pkg/foo/.*" component: name: "Client of external {1} service" description: "foo client" technology: "gRPC" tags: - TAG ``` -------------------------------- ### Render Structure to PlantUML (Go) Source: https://github.com/krzysztofreczek/go-structurizr/blob/master/README.md Renders the provided structure into a PlantUML diagram and writes it to an output file. Ensures the output file is closed after rendering. ```go outFile, _ := os.Create("c4.plantuml") defer func() { _ = outFile.Close() }() err = v.RenderStructureTo(structure, outFile) ``` -------------------------------- ### Define Component Info Structure in Go Source: https://github.com/krzysztofreczek/go-structurizr/blob/master/README.md The `model.Info` struct defines the properties of a component to be scraped, including its kind, name, description, technology, and tags. This structure is fundamental for representing components within the C4 model. ```go type Info struct { Kind string // kind of scraped component Name string // component name Description string // component description Technology string // technology used within the component Tags []string // tags used to match view styles to component } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.