Skip to main content
The system uses a layered architecture with pluggable components connected through factories, the Builder pattern, and strategy interfaces.

Component Architecture

Core Components

The core components are organized in layers: Configuration (Builder, Factory) → Validators (Syllable, Word, Context) → Algorithms (SymSpell, N-gram, POS, Semantic) → Infrastructure (Segmenter, Provider, Normalizer).

Component Responsibilities

Design Patterns

Builder Pattern

SpellCheckerBuilder provides fluent construction:

Factory Pattern

ComponentFactory creates configured components. It takes only config (not provider) — the provider and segmenter are passed to create_all():
Note: SyntacticRuleChecker is not a separate validator. It is wrapped as a SyntacticValidationStrategy and passed into ContextValidator.strategies. The ContextValidator orchestrates the 12 strategies wired by ComponentFactory: Tone (10), Orthography (15), Syntactic (20), Statistical Confusable (24), Broken Compound (25), POS Sequence (30), Question Structure (40), Homophone (45), Confusable Compound Classifier (47), Confusable Semantic (48), N-gram Context (50), and Semantic (70).

Strategy Pattern

Pluggable components implement common interfaces:

Chain of Responsibility

Validators form a chain, augmented by 38 post-normalization detectors inherited from mixins (see Component Diagram for the full mixin architecture and detection registry):

Provider Architecture

Interface

Implementations

Cython Integration

Wrapper Pattern

Python wrappers with Cython fallback:

Cython Source

Error Handling

Graceful Degradation

Components fail gracefully:

Exception Hierarchy

Thread Safety

Connection Pooling

Performance Considerations

Eager Initialization via ComponentFactory

SpellChecker.__init__ creates all components eagerly via ComponentFactory.create_all(). There are no lazy properties for core components:
Lazy imports are used at the module level (e.g., TYPE_CHECKING guards, deferred import inside methods) to avoid circular imports and heavy dependencies, but component instances are created eagerly during __init__.

Caching

Caching is implemented at the provider level, not the validator level. ComponentFactory creates cached wrapper objects around the provider using LRU caches:
Cache sizes are configured via SpellCheckerConfig.cache (AlgorithmCacheConfig).

Next Steps