Home / Function/ main() — graph2md Function Reference

main() — graph2md Function Reference

Architecture documentation for the main() function in main.go from the graph2md codebase.

Entity Profile

Dependency Diagram

graph TD
  b8c81770_53e9_c49f_8a64_ee57b9b3bb27["main()"]
  19d7285e_2dbf_69a0_6ada_b2031521fd4e["main.go"]
  b8c81770_53e9_c49f_8a64_ee57b9b3bb27 -->|defined in| 19d7285e_2dbf_69a0_6ada_b2031521fd4e
  38f2edb8_56a8_afe2_8475_0a20030eb7b1["loadGraph()"]
  b8c81770_53e9_c49f_8a64_ee57b9b3bb27 -->|calls| 38f2edb8_56a8_afe2_8475_0a20030eb7b1
  1a1d5ca6_82ee_dda2_e5fa_33bf55491e75["getStr()"]
  b8c81770_53e9_c49f_8a64_ee57b9b3bb27 -->|calls| 1a1d5ca6_82ee_dda2_e5fa_33bf55491e75
  80c44f8a_e7e7_c7a2_a444_7ffd708b9405["hasLabel()"]
  b8c81770_53e9_c49f_8a64_ee57b9b3bb27 -->|calls| 80c44f8a_e7e7_c7a2_a444_7ffd708b9405
  cb1308f3_ccc9_2add_e151_a235170fc89b["generateSlug()"]
  b8c81770_53e9_c49f_8a64_ee57b9b3bb27 -->|calls| cb1308f3_ccc9_2add_e151_a235170fc89b
  style b8c81770_53e9_c49f_8a64_ee57b9b3bb27 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

main.go lines 92–442

func main() {
	inputFiles := flag.String("input", "", "Comma-separated paths to graph JSON file(s)")
	outputDir := flag.String("output", "data", "Output directory for markdown files")
	repoName := flag.String("repo", "supermodel-public-api", "Repository name")
	repoURL := flag.String("repo-url", "https://github.com/supermodeltools/supermodel-public-api", "Repository URL")
	flag.Parse()

	if *inputFiles == "" {
		log.Fatal("--input is required (comma-separated paths to graph JSON files)")
	}

	if err := os.MkdirAll(*outputDir, 0755); err != nil {
		log.Fatalf("creating output dir: %v", err)
	}

	// Load and merge all graphs
	var allNodes []Node
	var allRels []Relationship
	nodeMap := make(map[string]bool)

	for _, path := range strings.Split(*inputFiles, ",") {
		path = strings.TrimSpace(path)
		if path == "" {
			continue
		}
		log.Printf("Loading graph from %s...", path)
		nodes, rels, err := loadGraph(path)
		if err != nil {
			log.Printf("Warning: failed to load %s: %v", path, err)
			continue
		}
		for _, n := range nodes {
			if !nodeMap[n.ID] {
				nodeMap[n.ID] = true
				allNodes = append(allNodes, n)
			}
		}
		allRels = append(allRels, rels...)
		log.Printf("  Loaded %d nodes, %d relationships", len(nodes), len(rels))
	}

	log.Printf("Total: %d unique nodes, %d relationships", len(allNodes), len(allRels))

	// Build node lookup: id -> node
	nodeLookup := make(map[string]*Node)
	for i := range allNodes {
		nodeLookup[allNodes[i].ID] = &allNodes[i]
	}

	// Build relationship indices
	imports := make(map[string][]string)
	importedBy := make(map[string][]string)
	callsRel := make(map[string][]string)
	calledByRel := make(map[string][]string)
	containsFile := make(map[string][]string)   // directory -> files
	definesFunc := make(map[string][]string)     // file -> functions
	declaresClass := make(map[string][]string)   // file -> classes
	definesType := make(map[string][]string)     // file -> types
	childDir := make(map[string][]string)        // directory -> subdirectories
	belongsToDomain := make(map[string]string)   // node -> domain name
	belongsToSubdomain := make(map[string]string) // node -> subdomain name
	partOfDomain := make(map[string]string)      // subdomain node ID -> domain name
	extendsRel := make(map[string][]string)      // class -> parent classes

	// Reverse lookups for "Defined In"
	fileOfFunc := make(map[string]string)        // function nodeID -> file nodeID
	fileOfClass := make(map[string]string)       // class nodeID -> file nodeID
	fileOfType := make(map[string]string)        // type nodeID -> file nodeID

	// Domain/subdomain node lookups by name
	domainNodeByName := make(map[string]string)    // domain name -> domain node ID
	subdomainNodeByName := make(map[string]string) // subdomain name -> subdomain node ID

	// Domain -> subdomain mappings
	domainSubdomains := make(map[string][]string) // domain name -> subdomain node IDs

	// Subdomain -> functions/classes
	subdomainFuncs := make(map[string][]string)   // subdomain name -> function node IDs
	subdomainClasses := make(map[string][]string) // subdomain name -> class node IDs

	for _, rel := range allRels {

Subdomains

Defined In

Frequently Asked Questions

What does main() do?
main() is a function in the graph2md codebase, defined in main.go.
Where is main() defined?
main() is defined in main.go at line 92.
What does main() call?
main() calls 4 function(s): generateSlug, getStr, hasLabel, loadGraph.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free