Skip to content

Architectural Patterns โ€‹

Architectural patterns in KIMU provide proven solutions for recurring problems in developing modular and extensible applications.

Overview โ€‹

The patterns implemented in KIMU follow established software engineering principles, adapted to the specific needs of a framework based on Web Components and modular architecture.

Fundamental Patterns โ€‹

Singleton Pattern โ€‹

Ensures a single instance of critical components like stores and managers.

Observer Pattern โ€‹

Implements an event system for communication between components.

Module Pattern โ€‹

Organizes code into independent and reusable modules.

Factory Pattern โ€‹

Creates instances of extensions and components in a controlled manner.

Strategy Pattern โ€‹

Allows changing algorithms and behaviors at runtime.

KIMU-Specific Patterns โ€‹

Extension Pattern โ€‹

The base pattern for creating modular and composable extensions.

Asset Loading Pattern โ€‹

Efficient management and lazy loading of application assets.

State Management Pattern โ€‹

Centralized state management with reactivity.

Component Composition Pattern โ€‹

Composition of complex components from simpler elements.

Documentation Structure โ€‹

Each pattern is documented with:

  • Problem: What problem it solves
  • Solution: How the pattern solves it
  • Implementation: Example code in KIMU
  • Advantages: Benefits of usage
  • Disadvantages: Limitations and trade-offs
  • Use Cases: When to use it
  • Variants: Different implementations
  • Examples: Real-world usage cases

Available Patterns โ€‹

Singleton Pattern โ€‹

Management of unique instances for framework managers and stores.

Observer Pattern โ€‹

Event and notification system for communication between components.

Asset Loading Pattern โ€‹

Efficient management of resource loading.

Design Principles โ€‹

SOLID Principles โ€‹

  • Single Responsibility: Each component has a specific responsibility
  • Open/Closed: Open for extension, closed for modification
  • Liskov Substitution: Implementations are substitutable
  • Interface Segregation: Specific and focused interfaces
  • Dependency Inversion: Dependencies towards abstractions

DRY (Don't Repeat Yourself) โ€‹

Code reuse through patterns and abstraction.

KISS (Keep It Simple, Stupid) โ€‹

Simple and understandable solutions.

YAGNI (You Aren't Gonna Need It) โ€‹

Implementation only of necessary features.

Anti-Patterns to Avoid โ€‹

God Object โ€‹

Avoid components that do too much.

Tight Coupling โ€‹

Maintain low coupling between components.

Magic Numbers/Strings โ€‹

Use named constants instead of hardcoded values.

Deep Inheritance โ€‹

Prefer composition over deep inheritance.

Emerging Patterns โ€‹

As the framework evolves, new patterns emerge specific to advanced use cases:

  • Micro-Frontend Pattern
  • Progressive Enhancement Pattern
  • Offline-First Pattern
  • Performance Optimization Pattern

Practical Usage โ€‹

Patterns are not rigid rules but flexible guidelines. The goal is:

  1. Consistency: Uniform and predictable code
  2. Maintainability: Easy to maintain and extend
  3. Reusability: Reusable components
  4. Testability: Easily testable code
  5. Performance: Efficient solutions

Combination Examples โ€‹

Often patterns combine for more complete solutions:

typescript
// Combination: Singleton + Observer + Factory
export class ExtensionManager {
  private static instance: ExtensionManager;
  private observers: Observer[] = [];
  private factory: ExtensionFactory;

  static getInstance(): ExtensionManager {
    if (!ExtensionManager.instance) {
      ExtensionManager.instance = new ExtensionManager();
    }
    return ExtensionManager.instance;
  }

  private constructor() {
    this.factory = new ExtensionFactory();
  }

  createExtension(type: string, config: any) {
    const extension = this.factory.create(type, config);
    this.notifyObservers('extension-created', extension);
    return extension;
  }
}

References โ€‹

Each pattern has its detailed documentation with practical examples and complete implementations in the context of the KIMU framework.

Released under Creative Commons Attribution 4.0 International (CC BY 4.0)