{"modulePath":"github.com/memcode-ai/memcode","version":"v0.56.16","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package structure\n\nPackage structure derives a repository's topology — its subsystems and the dependencies between them — from language-agnostic, deterministic signals: the directory tree, dependency manifests, ownership and change history. It deliberately does NOT parse code. Symbol-level detail is a later, per-language drill-down; the top-down model is what humans actually navigate.\n\n## Constants\n\n```go\nconst (\n\tEcoNode   = \"node\"\n\tEcoGo     = \"go\"\n\tEcoRust   = \"rust\"\n\tEcoPython = \"python\"\n\tEcoJava   = \"java\"\n)\n```\nEcosystem labels the package manager / language family a subsystem belongs to. These abstractions are language-agnostic on purpose — a subsystem is a subsystem whether it's Go, Node, Rust, Python or Java.\n\n## Functions\n\n```go\nfunc BuildSymbolMap(ctx context.Context, root string, opts MapOptions) (string, error)\n```\nBuildSymbolMap builds the ranked symbol digest for the repo at root: Go via AST, TS/JS/Python via the injected LSP lister (absent language servers degrade to a note, never an error).\n\n```go\nfunc PageRank(n int, refs map[int]map[int]float64, personal map[int]float64) []float64\n```\nPageRank returns one score per symbol. personal maps symbol index → EXTRA teleport weight, blended on top of a uniform base (p\\[i] ∝ 1 + personal\\[i]): seeds zoom the map without erasing the global structure — an exclusive teleport vector would rank a dirty scratch file above the repo's real hubs. Empty/nil personal = plain uniform PageRank.\n\n```go\nfunc ResolvePath(root, target string) (rel string, isPath bool)\n```\nResolvePath reports whether target names an existing path (relative to the working directory or the repo root) and returns its slash path relative to root. Shared by the context compiler and the provenance command.\n\n```go\nfunc SubsystemKey(id string) string\n```\nSubsystemKey strips the \"subsystem:\" prefix from an entity id.\n\n## Types\n\n```go\ntype Dependency struct {\n\tFrom string `json:\"from\"`\n\tTo   string `json:\"to\"`\n}\n```\nDependency is a directed edge between two subsystems (by key).\n\n```go\ntype ExternLister func(ctx context.Context, absPath string) ([]ExternSymbol, bool)\n```\nExternLister returns a file's declarations, or ok=false when no server serves the file's language.\n\n```go\ntype ExternSymbol struct {\n\tName    string `json:\"name\"`\n\tKind    int    `json:\"kind\"` // LSP SymbolKind\n\tLine    int    `json:\"line\"`\n\tEndLine int    `json:\"end_line\"`\n\tSelLine int    `json:\"sel_line\"`\n\tDepth   int    `json:\"depth\"`\n}\n```\nExternSymbol is one declaration reported by an external (LSP) lister.\n\n```go\ntype MapOptions struct {\n\tFocus  []string     // paths or symbol names to center the map on (personalization seeds)\n\tBudget int          // token budget for the digest (0 = default)\n\tStore  store.Store  // optional: persists the extern (LSP) symbol cache\n\tExtern ExternLister // optional: TS/JS/Python declarations (LSP documentSymbol)\n}\n```\nMapOptions steers one repo-map build.\n\n```go\ntype Result struct {\n\tRoot        string       `json:\"root\"`\n\tGeneratedAt time.Time    `json:\"generated_at\"`\n\tSubsystems  []Subsystem  `json:\"subsystems\"`\n\tDeps        []Dependency `json:\"dependencies\"`\n\tDocs        []string     `json:\"docs,omitempty\"` // repo-level docs (README, CLAUDE.md, …)\n}\n```\nResult is the topology produced by a scan.\n\n```go\nfunc Load(ctx context.Context, s store.Store) (Result, error)\n```\nLoad reconstructs the topology from the materialized projection (the subsystem entities and depends\\_on edges), plus repo-level metadata from the structural state snapshot. Read-only — it does not re-scan the filesystem.\n\n```go\nfunc Scan(ctx context.Context, s store.Store, root string) (Result, error)\n```\nScan builds the topology for the repo at root, persists it (subsystem entities, depends\\_on edges, and the structural current\\_state for scope \"repo\") and returns it for display.\n\n```go\ntype Subsystem struct {\n\tKey       string   `json:\"key\"`       // path relative to repo root\n\tName      string   `json:\"name\"`      // human label (package name or dir name)\n\tEcosystem string   `json:\"ecosystem\"` // node | go | rust | python | java\n\tPackage   string   `json:\"package,omitempty\"`\n\tManifest  string   `json:\"manifest\"`       // manifest filename\n\tDocs      []string `json:\"docs,omitempty\"` // doc files in this subsystem\n\tCommits   int      `json:\"commits\"`        // all-time commits touching this subsystem\n\tRecent    int      `json:\"recent_commits\"` // commits in the recent window\n\t// Churn-weighted hotspot signals over the recent window. Commit COUNT alone is\n\t// a weak \"where's the work\" proxy — many tiny commits in one area drown out\n\t// fewer, deeper changes elsewhere. Lines changed + active days capture depth\n\t// and sustained effort; Hotness blends them (normalized across subsystems).\n\tRecentChurn int      `json:\"recent_churn,omitempty\"` // added+deleted lines in the recent window\n\tRecentDays  int      `json:\"recent_days,omitempty\"`  // distinct days with a commit in the window\n\tHotness     float64  `json:\"hotness,omitempty\"`      // blended recent-activity score (0..1)\n\tOwners      []string `json:\"owners,omitempty\"`\n}\n```\nSubsystem is a bounded implementation unit (a Go module, an npm package, a Cargo crate, …) — the \"where\" of the system.\n\n```go\nfunc ByHotness(subs []Subsystem) []Subsystem\n```\nByHotness returns a copy of subs ranked by recent-activity hotness (churn + commits + active days, last 30d), with all-time commits and key as stable tiebreakers. This is the canonical \"where is the work now\" ordering.\n\n```go\nfunc ContainingSubsystem(subs []Subsystem, rel string) (Subsystem, bool)\n```\nContainingSubsystem returns the subsystem whose key is the longest prefix of rel (the most specific enclosing subsystem).\n\n```go\ntype Symbol struct {\n\tName     string `json:\"name\"`           // bare identifier (methods too — matching is by name)\n\tRecv     string `json:\"recv,omitempty\"` // method receiver type, for display\n\tKind     string `json:\"kind\"`           // func | method | type | const | var | class | …\n\tLang     string `json:\"lang\"`           // go | ts | py — reference matching stays within a language group\n\tPath     string `json:\"path\"`           // file, relative to the repo root\n\tLine     int    `json:\"line\"`\n\tEndLine  int    `json:\"end_line,omitempty\"` // full-range end (extern symbols; enclosing-attribution)\n\tDecl     string `json:\"decl\"`               // the declaration's first source line, trimmed\n\tExported bool   `json:\"exported\"`\n}\n```\nSymbol is one top-level declaration (Go via AST; TS/JS/Python via LSP).\n\n```go\ntype SymbolGraph struct {\n\tSymbols []Symbol\n\t// Refs[from][to] = reference count: the body of Symbols[from] mentions the\n\t// name of Symbols[to]. Name-collision targets split weight (see extractRefs).\n\tRefs map[int]map[int]float64\n\t// FileRefs counts references INTO each symbol from other files' top level\n\t// (var initializers etc.) — kept per-symbol, feeds in-degree display.\n\tInDeg []float64\n}\n```\nSymbolGraph is the repo-wide symbol reference graph.\n\n```go\nfunc ExtractGoSymbols(ctx context.Context, root string, files []string) SymbolGraph\n```\nExtractGoSymbols parses every non-test Go file under root (repo-tracked, vendored trees dropped) and returns the symbol reference graph. Parse errors skip the file — a broken working-tree file must not break orientation.\n\nReference resolution exploits Go's visibility rules instead of guessing: a BARE identifier can only reference a symbol in the SAME package (dir), and a cross-package reference is always an import selector (pkg.Name) — resolved exactly via the module path from go.mod. Selectors on non-package values (x.Method()) can't be typed without a checker, so they match METHOD symbols by name repo-wide with the weight split across candidates.\n\n","path":"github.com/memcode-ai/memcode/internal/structure","name":"structure","synopsis":"Package structure derives a repository's topology — its subsystems and the dependencies between them — from language-agnostic, deterministic signals: the directory tree, dependency manifests, ownership and change history.","isRedistributable":true}
