.claude/skills/architecture/SKILL.md
Use when refactoring, cleaning up, or enhancing the lib-electronic-components codebase. Provides guidance on architecture patterns, known issues, duplication hotspots, and recommended improvements.
npx skillsauth add Cantara/lib-electronic-components architectureInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill provides architectural guidance for enhancing and cleaning up the lib-electronic-components library.
┌─────────────────────────────────────────────────────────────────┐
│ ComponentType (Enum) │
│ ~200 component types │
│ Base types (RESISTOR) + Specific (RESISTOR_CHIP_VISHAY) │
└────────────────────────┬────────────────────────────────────────┘
│ matched by
▼
┌─────────────────────────────────────────────────────────────────┐
│ ComponentManufacturer (Enum) │
│ 50+ manufacturers │
│ Each holds: regex pattern + ManufacturerHandler │
└────────────────────────┬────────────────────────────────────────┘
│ delegates to
▼
┌─────────────────────────────────────────────────────────────────┐
│ ManufacturerHandler (Interface) │
│ 50+ implementations │
│ initializePatterns(), extractPackageCode(), extractSeries() │
└────────────────────────┬────────────────────────────────────────┘
│ populates
▼
┌─────────────────────────────────────────────────────────────────┐
│ PatternRegistry (Class) │
│ Map<ComponentType, Map<Class<?>, Set<Pattern>>> │
│ Multi-handler pattern storage │
└────────────────────────┬────────────────────────────────────────┘
│ used by
▼
┌─────────────────────────────────────────────────────────────────┐
│ ComponentSimilarityCalculator (Interface) │
│ 20+ implementations │
│ Per-component-type similarity strategies │
└─────────────────────────────────────────────────────────────────┘
| Pattern | Implementation | Location |
|---------|---------------|----------|
| Registry | PatternRegistry | Stores patterns by type and handler |
| Factory | ManufacturerHandlerFactory | Dynamic handler discovery |
| Strategy | ComponentSimilarityCalculator | Different algorithms per type |
| Enum Dispatch | ComponentManufacturer | Enum + handler association |
| Template Method | ManufacturerHandler.matches() | Default with override |
The following issues have been fixed:
TIHandler Pattern Duplication - FIXED
No Base Handler Class - FIXED
AbstractManufacturerHandler with shared helper methodsextractSuffixAfterHyphen(), extractTrailingSuffix(), findFirstDigitIndex(), findLastDigitIndex()Package Code Duplication - FIXED
PackageCodeRegistry with centralized mappingsFlaky Tests - FIXED
ManufacturerHandlerFactory from HashSet to TreeSet with deterministic orderingComponentType.getManufacturer() Fragile - FIXED
MANUFACTURER_SUFFIX_MAP for special cases (ON→ON_SEMI, AD→ANALOG_DEVICES)valueOf() lookup for standard casesTIHandlerPatterns.java Unused - FIXED (deleted)
The PackageCodeRegistry class has been created to centralize package code mappings:
// Usage in handlers:
String resolvedCode = PackageCodeRegistry.resolve("PU"); // Returns "PDIP"
boolean isKnown = PackageCodeRegistry.isKnownCode("N"); // Returns true
boolean isPower = PackageCodeRegistry.isPowerPackage("TO-220"); // Returns true
Supported codes include:
Next step: Migrate existing handlers to use the registry instead of inline maps.
| Area | Files | With Tests | Gap | Priority | |------|-------|------------|-----|----------| | Handlers | 56 | 40 (71.4%) | 16 handlers | HIGH | | Similarity Calculators | 20 | 0 (0%) | All untested | HIGH | | PatternRegistry | 1 | 0 | No tests | MEDIUM | | ManufacturerHandlerFactory | 1 | 0 | No tests | LOW |
Handlers WITHOUT Tests (16): Abracon, AKM, Cree, DiodesInc, Epson, Fairchild, IQD, LG, LogicIC, Lumileds, NDK, Nexteria, OSRAM, Qualcomm, Spansion, Unknown
Similarity Calculators (ALL untested): CapacitorSimilarityCalculator, ConnectorSimilarityCalculator, DiodeSimilarityCalculator, LEDSimilarityCalculator, MCUSimilarityCalculator, MemorySimilarityCalculator, MosfetSimilarityCalculator, OpAmpSimilarityCalculator, ResistorSimilarityCalculator, SensorSimilarityCalculator, TransistorSimilarityCalculator, VoltageRegulatorSimilarityCalculator, MicrocontrollerSimilarityCalculator, DefaultSimilarityCalculator, PassiveComponentCalculator, LevenshteinCalculator
Priority tests to add:
Handler tests - For each handler:
@Test void shouldDetectComponentType()
@Test void shouldExtractPackageCode()
@Test void shouldExtractSeries()
@Test void shouldIdentifyReplacements()
Pattern conflict tests:
@Test void noTwoHandlersShouldClaimSameMPN()
Similarity calculator tests:
@Test void resistorsSameValueShouldBeHighSimilarity()
@Test void differentComponentTypesShouldBeLowSimilarity()
Migrate handlers to use AbstractManufacturerHandler
*Handler.java in manufacturers/Migrate handlers to use PackageCodeRegistry
*Handler.java in manufacturers/~~Delete TIHandlerPatterns.java~~ - DONE
Add Handler Unit Tests
*HandlerTest.java~~Fix ComponentType.getManufacturer()~~ - DONE
Add Similarity Calculator Tests
*SimilarityCalculatorTest.javamanufacturers/| File | Count | Notes | |------|-------|-------| | MPNUtils.java | 35 | Heaviest concentration | | ManufacturerHandlerFactory.java | 17 | Also has 8 printStackTrace() | | ComponentTypeDetector.java | 17 | | | ConnectorSimilarityCalculator.java | 16 | | | Similarity calculators (combined) | 97 | All 13 calculators affected |
Action: Replace with SLF4J logging framework.
| File | Lines | |------|-------| | ManufacturerHandlerFactory.java | 56, 66, 110, 123, 149, 155, 186, 191 | | MPNUtils.java | 298 |
Action: Replace with logger.error("message", exception).
| Pattern | Count | Handlers | |---------|-------|----------| | Set.of() (modern) | 28 | AtmelHandler, STHandler, TIHandler, BoschHandler, HiroseHandler, JSTHandler, MolexHandler, EspressifHandler, LogicICHandler, MaximHandler, PanasonicHandler, VishayHandler, etc. | | new HashSet() (legacy) | 29 | CreeHandler, AbraconHandler, LGHandler, NordicHandler, etc. |
Action: Standardize all to Set.of() for immutability and conciseness. Note: 5 handlers fixed in PR #89: EspressifHandler, LogicICHandler, MaximHandler, PanasonicHandler, VishayHandler
| Handler | Issue | Status | |---------|-------|--------| | MaximHandler | Declared INTERFACE_IC_MAXIM, RTC_MAXIM, BATTERY_MANAGEMENT_MAXIM without patterns | ✅ FIXED (PR #89) | | EspressifHandler | Declared ESP8266_SOC, ESP32_SOC, all module types but only registered MICROCONTROLLER | ✅ FIXED (PR #89) | | PanasonicHandler | Declared capacitor/inductor types but no patterns registered | ✅ FIXED (PR #89) |
Impact: matches() returns false for declared types because patterns aren't registered.
Fix pattern: When adding a type to getSupportedTypes(), MUST also add patterns in initializePatterns().
| File | Issue | Line(s) | Status | |------|-------|---------|--------| | LogicICHandler.java | Debug System.out.println in production code | 70, 75, 84, 85 | ✅ FIXED (PR #89) | | EspressifHandler.java | NPE risk - substring without indexOf check | 153-154 | ✅ FIXED (PR #89) | | InfineonHandler.java | Commented-out code blocks | 44, 49, 51 | Open |
All similarity calculators use hardcoded weights:
// Varies by calculator - no consistent values!
HIGH_SIMILARITY = 0.9
MEDIUM_SIMILARITY = 0.5-0.7 // Inconsistent!
LOW_SIMILARITY = 0.3
// Scoring increments vary wildly
valueMatch = 0.3-0.5
packageMatch = 0.2-0.4
Action: Extract to configurable SimilarityWeights constants class.
When reviewing code, watch for:
| Smell | Example | Fix |
|-------|---------|-----|
| Duplicate Map.put() | Same key added twice | Remove duplicate |
| Hardcoded package codes | return "TO-220" | Use PackageCodeRegistry |
| Copy-pasted regex | Same pattern in 3 handlers | Extract to constant |
| Giant switch statement | 50+ cases | Use Map lookup |
| Unused ComponentSeriesInfo | Defined but never queried | Remove or use |
| Task | Primary Files |
|------|---------------|
| Add manufacturer | ComponentManufacturer.java, new *Handler.java |
| Add component type | ComponentType.java, handler initializePatterns() |
| Fix pattern matching | Handler's matches() method |
| Add similarity logic | New *SimilarityCalculator.java, register in MPNUtils |
| Debug MPN detection | ComponentManufacturer.fromMPN(), handler patterns |
ComponentManufacturer enum tightly couples manufacturer identity with handler - this is intentional for performance (single lookup)PatternRegistry supports multi-handler per type but this feature is largely unusedMPNUtils static initializer (lines 34-48)Handler Ordering (PR #75):
ManufacturerHandlerFactory MUST use TreeSet with deterministic comparatorHashSet caused flaky tests because iteration order varied between runsgetManufacturerHandler() - order is critical!Type Detection Specificity (PR #74):
MPNUtils.getComponentType() uses specificity scoring via getTypeSpecificityScore()ComponentType.getBaseType() Completeness:
default -> this (returns self, not base type)ComponentType.getManufacturer() Mapping (PR #76):
MANUFACTURER_SUFFIX_MAP for special cases (ON→ON_SEMI, AD→ANALOG_DEVICES, SILABS→SILICON_LABS, DIODES→DIODES_INC)ComponentManufacturer.valueOf(suffix) for standard casesCross-Handler Pattern Matching (PR #90 - CRITICAL FIX):
ManufacturerHandler.matches() was using PatternRegistry.getPattern(type) which returned the first pattern from ANY handlermatchesForCurrentHandler() to PatternRegistry that only checks patterns for the current handlermatches() overrides with the same bug (using patterns.getPattern(type) as fallback):
patterns.matchesForCurrentHandler()ComponentManufacturer affects detection priority for ambiguous MPNspatterns.matchesForCurrentHandler() NOT patterns.getPattern(type) for fallback matchingComponentManufacturer.java lines 45-53) - unclear if deprecated or WIP/handler-pattern-design - Handler patterns, anti-patterns, and cleanup checklists/similarity-calculator-architecture - Calculator ordering and architectural patterns/component-type-detection-hierarchy - Type system architecture and specificity/manufacturer-detection-from-mpn - Manufacturer detection patterns and orderingdata-ai
Cost-effective task delegation strategy using Haiku model for straightforward work. Use when planning how to approach simple, pattern-following tasks to minimize costs.
tools
Use when working with component similarity calculations - comparing MPNs, finding equivalent parts, implementing new similarity calculators, or understanding how component matching works.
testing
Use when working with transistor similarity calculations - comparing BJT MPNs, understanding NPN/PNP polarity matching, equivalent groups like 2N2222/PN2222, or transistor-specific similarity logic.
testing
Use when working with sensor similarity calculations - comparing temperature/accelerometer/humidity sensor MPNs, understanding sensor families, equivalent parts, or sensor-specific similarity logic.