arch

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChangeAdded   = "added"
	ChangeRemoved = "removed"
)

APIChange values for APIDiff.Change.

View Source
const AbiHashVersion uint32 = 1

AbiHashVersion is mixed into the hash input. Bump when the canonical signature encoding changes so consumers invalidate cached hashes on krit upgrade.

Variables

This section is empty.

Functions

func ExpectedPackage

func ExpectedPackage(filePath string, sourceRoot string) string

ExpectedPackage derives the expected Kotlin/Java package name from a file's path relative to a source root. For example:

filePath="/project/app/src/main/kotlin/com/example/feature/Foo.kt"
sourceRoot="/project/app/src/main/kotlin"
returns "com.example.feature"

func FormatSurface

func FormatSurface(entries []APIEntry) string

FormatSurface produces a deterministic text representation of an API surface. Entries should already be sorted (ExtractSurface guarantees this); if passed arbitrary input, callers should sort first.

func HashAbiSignatures

func HashAbiSignatures(sigs []AbiSignature) string

HashAbiSignatures returns the 16-character hex hash described in the abi-hash spec (first 8 bytes of SHA-256 over the canonical form, salted by AbiHashVersion).

func ImportBreadth

func ImportBreadth(file *scanner.File) int

ImportBreadth counts the number of distinct packages imported by a file. It parses the file's Lines for "import" declarations and extracts parent packages.

func SymbolFanIn

func SymbolFanIn(index *scanner.CodeIndex) map[string]int

SymbolFanIn computes the fan-in (number of distinct files referencing) for each declared symbol in the index. The declaring file is excluded from the count, so a symbol only referenced in its own file has fan-in 0.

Types

type APIDiff

type APIDiff struct {
	Change string // one of ChangeAdded, ChangeRemoved
	Entry  APIEntry
}

APIDiff represents a change between two API surfaces.

func DiffSurfaces

func DiffSurfaces(old, newEntries []APIEntry) []APIDiff

DiffSurfaces compares old and new API surfaces, returning additions and removals.

type APIEntry

type APIEntry struct {
	Kind      string // "class", "interface", "object", "function", "property"
	Name      string // fully qualified or simple name
	Signature string // e.g., "fun getUser(id: String): User"
	File      string
	Line      int
}

APIEntry represents a single public API element.

func ExtractSurface

func ExtractSurface(symbols []scanner.Symbol) []APIEntry

ExtractSurface extracts the public API surface from parsed files. Returns public/protected declarations sorted by kind+name for determinism.

func ParseSurface

func ParseSurface(text string) []APIEntry

ParseSurface parses a text surface (produced by FormatSurface) back into entries.

type AbiParam

type AbiParam struct {
	Type       string
	HasDefault bool
}

AbiParam captures parameter type and default-presence; names and default values are intentionally excluded.

type AbiSignature

type AbiSignature struct {
	Kind        string   // class | interface | object | function | property
	FQN         string   // package + container chain + name
	Modifiers   []string // sorted, ABI-relevant modifiers only
	TypeParams  []string // raw text per type parameter, in declaration order
	Params      []AbiParam
	ReturnType  string
	Annotations []string // sorted, allowlisted annotation names only
}

AbiSignature is one declaration's normalized contribution to the ABI.

func ExtractAbiSignatures

func ExtractAbiSignatures(files []*scanner.File) []AbiSignature

ExtractAbiSignatures walks the public/protected declarations in files and returns deterministic, name-keyed signature records.

type BroadFile

type BroadFile struct {
	Path         string
	PackageCount int
}

BroadFile represents a file with high import breadth.

func FindBroadFiles

func FindBroadFiles(files []*scanner.File, threshold int) []BroadFile

FindBroadFiles returns files whose import breadth exceeds the threshold, sorted by package count descending.

type Drift

type Drift struct {
	FilePath string
	Declared string
	Expected string
	Line     int
}

Drift represents a mismatch between a file's declared package and its expected package.

func PackageNameDrift

func PackageNameDrift(file *scanner.File, sourceRoot string) *Drift

PackageNameDrift checks if a file's declared package matches the expected package derived from its path. Returns nil if they match or if the file has no package declaration.

type Hotspot

type Hotspot struct {
	Name  string
	Kind  string // "class", "function", etc.
	FanIn int    // count of distinct files referencing this symbol
	File  string
	Line  int
}

Hotspot represents a symbol with high fan-in.

func FilterHotspots

func FilterHotspots(index *scanner.CodeIndex, fanIn map[string]int, threshold int) []Hotspot

FilterHotspots returns symbols whose fan-in exceeds the threshold, sorted by fan-in descending. When multiple symbols share a name, only the first declaration is included.

type Layer

type Layer struct {
	Name    string
	Modules []string // glob patterns like ":feature-*"
}

Layer represents a named architectural layer with module glob patterns.

type LayerConfig

type LayerConfig struct {
	Layers  []Layer
	Allowed map[string][]string // layer name -> allowed dependency layers
}

LayerConfig holds the full layer dependency configuration.

func ParseLayerConfig

func ParseLayerConfig(cfg *config.Config) *LayerConfig

ParseLayerConfig extracts layer configuration from a krit Config. The config structure is nested under architecture.LayerDependencyViolation. Returns nil if no layer config is present.

func (*LayerConfig) LayerForModule

func (lc *LayerConfig) LayerForModule(modulePath string) string

LayerForModule returns the layer name for a given module path, or "" if the module doesn't match any layer.

type LayerViolation

type LayerViolation struct {
	SourceModule string
	TargetModule string
	SourceLayer  string
	TargetLayer  string
}

LayerViolation represents a dependency that crosses an unauthorized layer boundary.

func ValidateLayers

func ValidateLayers(cfg *LayerConfig, graph *module.Graph) []LayerViolation

ValidateLayers checks all module dependencies against the layer config. Returns violations where a module in one layer depends on a module in a layer that is not in the allowed list.

type LeakyClass

type LeakyClass struct {
	ClassName         string
	WrappedType       string
	Line              int
	DelegationRatio   float64 // 0.0-1.0, fraction of methods that delegate
	TotalMethods      int
	DelegatingMethods int
}

LeakyClass represents a public class that appears to be a thin wrapper.

func DetectLeakyAbstractions

func DetectLeakyAbstractions(lines []string, threshold float64) []LeakyClass

DetectLeakyAbstractions scans a file for public classes that are thin wrappers delegating to a single private/internal field.

Heuristic: 1. Find public class declarations with a single constructor parameter 2. Check if the parameter is stored as a private/internal property 3. Count public methods that are single-expression delegations to that property 4. If delegation ratio > threshold, flag as leaky

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL