detector

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheDir      = ".haft"
	ProfileFile   = "profile.json"
	ChecksumFile  = "checksum"
	DefaultMaxAge = 24 * time.Hour
)
View Source
const (
	ConfidenceHigh      = 0.85
	ConfidenceThreshold = 0.70
	ConfidenceMedium    = 0.50
	ConfidenceLow       = 0.30
)
View Source
const (
	WeightSignalStrength = 0.40
	WeightSampleSize     = 0.30
	WeightConsistency    = 0.30
)
View Source
const (
	MinSampleSize       = 3
	OptimalSampleSize   = 10
	MaxSampleMultiplier = 1.0
)
View Source
const (
	DefaultCacheMaxAge = 24 * time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ArchitectureType

type ArchitectureType string
const (
	ArchLayered   ArchitectureType = "layered"
	ArchFeature   ArchitectureType = "feature"
	ArchHexagonal ArchitectureType = "hexagonal"
	ArchClean     ArchitectureType = "clean"
	ArchModular   ArchitectureType = "modular"
	ArchFlat      ArchitectureType = "flat"
	ArchUnknown   ArchitectureType = "unknown"
)

func ParseArchitectureType

func ParseArchitectureType(s string) ArchitectureType

func (ArchitectureType) IsValid

func (dt ArchitectureType) IsValid() bool

func (ArchitectureType) String

func (dt ArchitectureType) String() string

type BaseClassInfo

type BaseClassInfo struct {
	Name       string  `json:"name"`
	Package    string  `json:"package"`
	FullPath   string  `json:"full_path"`
	Fields     []Field `json:"fields,omitempty"`
	IDType     string  `json:"id_type,omitempty"`
	IDStrategy string  `json:"id_strategy,omitempty"`
}

type ConfidenceCalculator

type ConfidenceCalculator struct{}

func NewConfidenceCalculator

func NewConfidenceCalculator() *ConfidenceCalculator

func (*ConfidenceCalculator) Calculate

func (c *ConfidenceCalculator) Calculate(signalStrength float64, sampleSize int, consistency float64) float64

func (*ConfidenceCalculator) CalculateArchitectureConfidence

func (c *ConfidenceCalculator) CalculateArchitectureConfidence(
	matchingFiles, totalFiles int,
	hasDistinctiveMarkers bool,
	ambiguityScore float64,
) float64

func (*ConfidenceCalculator) CalculateFromCounts

func (c *ConfidenceCalculator) CalculateFromCounts(matchCount, totalCount int) float64

func (*ConfidenceCalculator) CalculatePatternConfidence

func (c *ConfidenceCalculator) CalculatePatternConfidence(
	occurrences int,
	sampleSize int,
	patternVariations int,
) float64

func (*ConfidenceCalculator) CombineConfidences

func (c *ConfidenceCalculator) CombineConfidences(confidences ...float64) float64

func (*ConfidenceCalculator) CompareDetections

func (c *ConfidenceCalculator) CompareDetections(first, second float64) int

func (*ConfidenceCalculator) FormatPercentage

func (c *ConfidenceCalculator) FormatPercentage(confidence float64) int

func (*ConfidenceCalculator) GetConfidenceLevel

func (c *ConfidenceCalculator) GetConfidenceLevel(confidence float64) string

func (*ConfidenceCalculator) IsHighConfidence

func (c *ConfidenceCalculator) IsHighConfidence(confidence float64) bool

func (*ConfidenceCalculator) IsTooLow

func (c *ConfidenceCalculator) IsTooLow(confidence float64) bool

func (*ConfidenceCalculator) MeetsThreshold

func (c *ConfidenceCalculator) MeetsThreshold(confidence float64) bool

func (*ConfidenceCalculator) NeedsUserConfirmation

func (c *ConfidenceCalculator) NeedsUserConfirmation(confidence float64) bool

func (*ConfidenceCalculator) WeightedCombine

func (c *ConfidenceCalculator) WeightedCombine(values []float64, weights []float64) float64

type DTONamingStyle

type DTONamingStyle string
const (
	DTONamingRequestResponse DTONamingStyle = "request_response"
	DTONamingDTOUpper        DTONamingStyle = "dto_upper"
	DTONamingDTOLower        DTONamingStyle = "dto_lower"
	DTONamingUnknown         DTONamingStyle = "unknown"
)

func ParseDTONamingStyle

func ParseDTONamingStyle(s string) DTONamingStyle

func (DTONamingStyle) String

func (dt DTONamingStyle) String() string

type DatabaseType

type DatabaseType string
const (
	DatabaseJPA       DatabaseType = "jpa"
	DatabaseCassandra DatabaseType = "cassandra"
	DatabaseMongo     DatabaseType = "mongo"
	DatabaseR2DBC     DatabaseType = "r2dbc"
	DatabaseMulti     DatabaseType = "multi"
	DatabaseUnknown   DatabaseType = "unknown"
)

func ParseDatabaseType

func ParseDatabaseType(s string) DatabaseType

func (DatabaseType) String

func (dt DatabaseType) String() string

type DetectionResult

type DetectionResult struct {
	Value      interface{}
	Confidence float64
	Evidence   []string
}

type Detector

type Detector struct {
	// contains filtered or unexported fields
}

func NewDetector

func NewDetector(projectDir string, opts ...DetectorOption) *Detector

func (*Detector) Detect

func (d *Detector) Detect() (*ProjectProfile, error)

func (*Detector) GetConfidenceCalculator

func (d *Detector) GetConfidenceCalculator() *ConfidenceCalculator

func (*Detector) GetScanner

func (d *Detector) GetScanner() *Scanner

type DetectorOption

type DetectorOption func(*Detector)

func WithCacheMaxAge

func WithCacheMaxAge(maxAge time.Duration) DetectorOption

func WithFileSystem

func WithFileSystem(fs afero.Fs) DetectorOption

type ExceptionInfo

type ExceptionInfo struct {
	Name    string `json:"name"`
	Package string `json:"package"`
}

type ExceptionProfile

type ExceptionProfile struct {
	HasGlobalHandler bool            `json:"has_global_handler"`
	HandlerPackage   string          `json:"handler_package,omitempty"`
	CustomExceptions []ExceptionInfo `json:"custom_exceptions,omitempty"`
}

type FeatureStyle

type FeatureStyle string
const (
	FeatureStyleFlat   FeatureStyle = "flat"
	FeatureStyleNested FeatureStyle = "nested"
)

type Field

type Field struct {
	Name        string   `json:"name"`
	Type        string   `json:"type"`
	Annotations []string `json:"annotations,omitempty"`
}

type JavaFile

type JavaFile struct {
	Path                 string
	Package              string
	ClassName            string
	FileType             JavaFileType
	Annotations          []string
	ExtendsClass         string
	ImplementsInterfaces []string
	Imports              []string
	IsAbstract           bool
	IsInterface          bool
}

type JavaFileType

type JavaFileType string
const (
	FileTypeController JavaFileType = "controller"
	FileTypeService    JavaFileType = "service"
	FileTypeRepository JavaFileType = "repository"
	FileTypeEntity     JavaFileType = "entity"
	FileTypeDTO        JavaFileType = "dto"
	FileTypeMapper     JavaFileType = "mapper"
	FileTypeException  JavaFileType = "exception"
	FileTypeConfig     JavaFileType = "config"
	FileTypeTest       JavaFileType = "test"
	FileTypeUnknown    JavaFileType = "unknown"
)

type LombokProfile

type LombokProfile struct {
	Detected        bool `json:"detected"`
	UseData         bool `json:"use_data"`
	UseBuilder      bool `json:"use_builder"`
	UseAccessors    bool `json:"use_accessors"`
	UseSlf4j        bool `json:"use_slf4j"`
	UseRequiredArgs bool `json:"use_required_args"`
	UseAllArgs      bool `json:"use_all_args"`
	UseNoArgs       bool `json:"use_no_args"`
}

type MapperType

type MapperType string
const (
	MapperMapStruct   MapperType = "mapstruct"
	MapperModelMapper MapperType = "modelmapper"
	MapperManual      MapperType = "manual"
	MapperNone        MapperType = "none"
)

func ParseMapperType

func ParseMapperType(s string) MapperType

func (MapperType) String

func (mt MapperType) String() string

type ProfileCache

type ProfileCache struct {
	// contains filtered or unexported fields
}

func NewProfileCache

func NewProfileCache(projectDir string) *ProfileCache

func NewProfileCacheWithFs

func NewProfileCacheWithFs(fs afero.Fs, projectDir string) *ProfileCache

func (*ProfileCache) Clear

func (c *ProfileCache) Clear() error

func (*ProfileCache) Exists

func (c *ProfileCache) Exists() bool

func (*ProfileCache) IsValid

func (c *ProfileCache) IsValid() bool

func (*ProfileCache) Load

func (c *ProfileCache) Load() (*ProjectProfile, error)

func (*ProfileCache) Save

func (c *ProfileCache) Save(profile *ProjectProfile) error

func (*ProfileCache) SetMaxAge

func (c *ProfileCache) SetMaxAge(maxAge time.Duration)

type ProjectProfile

type ProjectProfile struct {
	DetectedAt  time.Time `json:"detected_at"`
	ProjectRoot string    `json:"project_root"`

	Architecture   ArchitectureType `json:"architecture"`
	ArchConfidence float64          `json:"arch_confidence"`
	ArchLocked     bool             `json:"arch_locked"`
	FeatureStyle   FeatureStyle     `json:"feature_style"`

	BasePackage string `json:"base_package"`
	SourceRoot  string `json:"source_root"`
	TestRoot    string `json:"test_root"`

	BaseEntity     *BaseClassInfo `json:"base_entity,omitempty"`
	BaseRepository *BaseClassInfo `json:"base_repository,omitempty"`
	BaseService    *BaseClassInfo `json:"base_service,omitempty"`

	ResponseWrapper *WrapperInfo `json:"response_wrapper,omitempty"`
	PageWrapper     *WrapperInfo `json:"page_wrapper,omitempty"`

	DTONaming        DTONamingStyle `json:"dto_naming"`
	DTONamingLocked  bool           `json:"dto_naming_locked"`
	ControllerSuffix string         `json:"controller_suffix"`
	ServiceSuffix    string         `json:"service_suffix"`

	IDType       string `json:"id_type"`
	IDAnnotation string `json:"id_annotation"`
	IDLocked     bool   `json:"id_locked"`

	Mapper       MapperType `json:"mapper"`
	MapperLocked bool       `json:"mapper_locked"`

	Exceptions ExceptionProfile `json:"exceptions"`

	Lombok LombokProfile `json:"lombok"`

	HasSwagger   bool         `json:"has_swagger"`
	SwaggerStyle SwaggerStyle `json:"swagger_style"`

	HasValidation   bool            `json:"has_validation"`
	ValidationStyle ValidationStyle `json:"validation_style"`

	Testing TestProfile `json:"testing"`

	Database       DatabaseType `json:"database"`
	DatabaseLocked bool         `json:"database_locked"`

	FeatureModules []string `json:"feature_modules,omitempty"`

	LockedFields []string `json:"locked_fields,omitempty"`
}

func NewDefaultProfile

func NewDefaultProfile() *ProjectProfile

func NewEmptyProfile

func NewEmptyProfile() *ProjectProfile

func (*ProjectProfile) GetBaseEntityImport

func (p *ProjectProfile) GetBaseEntityImport() string

func (*ProjectProfile) GetControllerPackage

func (p *ProjectProfile) GetControllerPackage(resourceName string) string

func (*ProjectProfile) GetDTOPackage

func (p *ProjectProfile) GetDTOPackage(resourceName string) string

func (*ProjectProfile) GetDTORequestSuffix

func (p *ProjectProfile) GetDTORequestSuffix() string

func (*ProjectProfile) GetDTOResponseSuffix

func (p *ProjectProfile) GetDTOResponseSuffix() string

func (*ProjectProfile) GetEntityPackage

func (p *ProjectProfile) GetEntityPackage(resourceName string) string

func (*ProjectProfile) GetIDImport

func (p *ProjectProfile) GetIDImport() string

func (*ProjectProfile) GetMapperPackage

func (p *ProjectProfile) GetMapperPackage(resourceName string) string

func (*ProjectProfile) GetRepositoryPackage

func (p *ProjectProfile) GetRepositoryPackage(resourceName string) string

func (*ProjectProfile) GetResponseWrapperImport

func (p *ProjectProfile) GetResponseWrapperImport() string

func (*ProjectProfile) GetServicePackage

func (p *ProjectProfile) GetServicePackage(resourceName string) string

func (*ProjectProfile) IsFieldLocked

func (p *ProjectProfile) IsFieldLocked(fieldName string) bool

func (*ProjectProfile) IsStale

func (p *ProjectProfile) IsStale(maxAge time.Duration) bool

func (*ProjectProfile) IsValid

func (p *ProjectProfile) IsValid() bool

func (*ProjectProfile) LockField

func (p *ProjectProfile) LockField(fieldName string)

func (*ProjectProfile) NeedsBaseEntityImport

func (p *ProjectProfile) NeedsBaseEntityImport() bool

func (*ProjectProfile) NeedsResponseWrapperImport

func (p *ProjectProfile) NeedsResponseWrapperImport() bool

func (*ProjectProfile) UnlockField

func (p *ProjectProfile) UnlockField(fieldName string)

type ScanResult

type ScanResult struct {
	SourceFiles []*JavaFile
	TestFiles   []*JavaFile
	BasePackage string
	SourceRoot  string
	TestRoot    string
	BuildTool   string
	HasGradle   bool
	HasMaven    bool
}

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

func NewScanner

func NewScanner(fs afero.Fs, projectDir string) *Scanner

func (*Scanner) GetFilesByAnnotation

func (s *Scanner) GetFilesByAnnotation(files []*JavaFile, annotation string) []*JavaFile

func (*Scanner) GetFilesByType

func (s *Scanner) GetFilesByType(files []*JavaFile, fileType JavaFileType) []*JavaFile

func (*Scanner) GetFilesExtending

func (s *Scanner) GetFilesExtending(files []*JavaFile, parentClass string) []*JavaFile

func (*Scanner) GetUniquePackages

func (s *Scanner) GetUniquePackages(files []*JavaFile) []string

func (*Scanner) GroupFilesByPackage

func (s *Scanner) GroupFilesByPackage(files []*JavaFile) map[string][]*JavaFile

func (*Scanner) Scan

func (s *Scanner) Scan() (*ScanResult, error)

type SwaggerStyle

type SwaggerStyle string
const (
	SwaggerOpenAPI3 SwaggerStyle = "openapi3"
	SwaggerV2       SwaggerStyle = "swagger2"
	SwaggerNone     SwaggerStyle = "none"
)

type TestProfile

type TestProfile struct {
	Framework         string `json:"framework"`
	HasMockito        bool   `json:"has_mockito"`
	HasTestcontainers bool   `json:"has_testcontainers"`
	HasRestAssured    bool   `json:"has_rest_assured"`
	StructureMirror   bool   `json:"structure_mirror"`
}

type ValidationStyle

type ValidationStyle string
const (
	ValidationJakarta ValidationStyle = "jakarta"
	ValidationJavax   ValidationStyle = "javax"
	ValidationNone    ValidationStyle = "none"
)

type WrapperInfo

type WrapperInfo struct {
	Name           string   `json:"name"`
	Package        string   `json:"package"`
	FullPath       string   `json:"full_path"`
	IsGeneric      bool     `json:"is_generic"`
	Fields         []string `json:"fields,omitempty"`
	FactoryMethods []string `json:"factory_methods,omitempty"`
}

Jump to

Keyboard shortcuts

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