ajhahn.de
← eeco
Go 64 lines
package projecttype

// vote is one category's weighted score contribution from a matched
// marker file or conventional directory.
type vote struct {
	cat    Category
	weight float64
}

// markerRules maps a root-level marker file to the categories its
// presence votes for. A key containing a glob metacharacter (* ? [) is
// matched with filepath.Glob against the repo root; any other key is an
// exact filename. Weights are heuristic and tuned against the tests in
// this package — a single ecosystem marker rarely settles a category on
// its own, so the conventional-directory signals below usually decide
// the winner.
var markerRules = map[string][]vote{
	"go.mod":            {{CLI, 0.4}, {Library, 0.25}, {WebAPI, 0.25}, {Fullstack, 0.2}},
	"Cargo.toml":        {{CLI, 0.4}, {Library, 0.3}, {Embedded, 0.3}},
	"package.json":      {{WebApp, 0.4}, {Fullstack, 0.3}, {Library, 0.2}, {CLI, 0.15}},
	"pyproject.toml":    {{CLI, 0.3}, {Library, 0.3}, {ML, 0.3}},
	"setup.py":          {{CLI, 0.3}, {Library, 0.3}, {ML, 0.3}},
	"requirements*.txt": {{ML, 0.4}, {WebAPI, 0.25}},
	"pubspec.yaml":      {{Mobile, 0.8}},
	"build.zig":         {{Embedded, 0.4}, {CLI, 0.3}, {GameDev, 0.2}},
	"*.csproj":          {{CLI, 0.3}, {WebApp, 0.25}, {Fullstack, 0.25}, {GameDev, 0.25}},
	"*.sln":             {{CLI, 0.3}, {WebApp, 0.25}, {Fullstack, 0.25}, {GameDev, 0.25}},
	"Dockerfile":        {{Infra, 0.2}, {WebAPI, 0.2}},
	"*.tf":              {{Infra, 0.8}},
	"Gemfile":           {{WebApp, 0.35}, {WebAPI, 0.35}},
	"pom.xml":           {{WebAPI, 0.35}, {Fullstack, 0.25}, {Mobile, 0.2}},
	"build.gradle":      {{WebAPI, 0.3}, {Fullstack, 0.25}, {Mobile, 0.3}},
	"CMakeLists.txt":    {{Embedded, 0.35}, {CLI, 0.25}, {GameDev, 0.25}},
}

// signalRules maps a root-level conventional directory to the categories
// its presence confirms. These are the layer-2 disambiguators that lift
// a clear winner above the layer-1 marker noise.
var signalRules = map[string][]vote{
	"cmd":          {{CLI, 0.4}},
	"internal":     {{CLI, 0.2}, {WebAPI, 0.15}},
	"pkg":          {{Library, 0.3}},
	"frontend":     {{Fullstack, 0.6}, {WebApp, 0.2}},
	"backend":      {{Fullstack, 0.6}, {WebAPI, 0.2}},
	"src":          {{WebApp, 0.15}, {Library, 0.1}},
	"public":       {{WebApp, 0.25}},
	"firmware":     {{Embedded, 0.6}},
	"drivers":      {{Embedded, 0.4}},
	"hardware":     {{Embedded, 0.4}},
	"assets":       {{GameDev, 0.4}},
	"levels":       {{GameDev, 0.6}},
	"scenes":       {{GameDev, 0.4}},
	"notebooks":    {{ML, 0.5}},
	"data":         {{ML, 0.25}},
	"models":       {{ML, 0.3}, {WebAPI, 0.15}},
	"terraform":    {{Infra, 0.6}},
	"modules":      {{Infra, 0.3}},
	"environments": {{Infra, 0.4}},
	"api":          {{WebAPI, 0.3}},
	"ios":          {{Mobile, 0.6}},
	"android":      {{Mobile, 0.6}},
	"screens":      {{Mobile, 0.3}},
}