# robak86/hardwired architecture

> Architecture diagram of the GitHub repository robak86/hardwired, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/robak86/hardwired
- Repository: https://github.com/robak86/hardwired

## Overview

##### Main Components
- Core Library (packages/core): This is the heart of Hardwired containing the DI container implementation. It includes submodules for configuration, dependency definitions (both function-based and class-based), container internals (e.g., the “Configuration”, “Container”, “Interceptors”, “Strategies”, “Context”, and “Utils” directories), and disposal management.
- React Integration (packages/react): Provides React-specific components, hooks, and context wrappers (e.g., ContainerInitializer, ContainerProvider, ContainerScope, and related tests) for integrating the DI container with React applications.
- Examples (packages/examples): A practical HTTP server example that illustrates how the library is used in a real-world scenario.
- Documentation and Configurations: The “docs” folder with drawio files, configuration files (like tsconfig.json, vitest.config.ts, eslint and prettier configs), and CI-related workflows.

##### Architectural Structure
- Monorepo Organization: The project uses a multi-package structure with a dedicated folder for core functionalities, React-specific integrations, and usage examples.
- Core DI Engine:
- Definitions: The system supports multiple lifetimes—singleton, scoped, and transient—as well as both function-based and class-based definitions. The directories “definitions”, “configuration”, and “container” illustrate these roles.
- Container & Scoping: The container is responsible for both the creation and management of instances along with scoping mechanisms for isolated dependency graphs.
- Interceptors & Strategies: The library includes support for interceptors (logging, dependency graph building, etc.) which decorate or modify the creation process and behavior of the dependency graph.
- Context and Utils: Supporting files (like those under “context” and “utils”) provide runtime mechanisms such as memoization, asynchronous processing, and more.
- React Integration:
- Components: The react package has components for initialization and providing container contexts. It includes tests that validate integration and hooks that ease consumption.
- Testing & Configuration: Broad test coverage across all packages (using vitest) ensures the DI library works as designed in various use cases (type safety, lazy evaluation, etc.).

##### Essential Elements
- Annotations for design choices such as “lazy evaluation”, “singleton vs. scoped vs. transient”, and “child scope creation”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Core DI Engine"
        ConfigDSL["Configuration DSL"]:::core
        Container["Container & Scoping"]:::core
        Interceptors["Interceptors Module"]:::core
        Definitions["Definitions"]:::core
        Context["Context Module"]:::core
        Disposal["Disposal Management"]:::core
        Strategies["Strategies Module"]:::core
        Utilities["Utilities & Patching"]:::core
    end

    subgraph "React Integration Layer"
        ReactComponents["React Components"]:::react
        ReactContext["React Context"]:::react
        ReactHooks["React Hooks"]:::react
        ReactInterceptors["React Interceptors"]:::react
    end

    subgraph "Usage Examples"
        HTTPServer["HTTP Server Example"]:::examples
    end

    subgraph "Documentation & Configurations"
        Docs["Docs & Diagrams"]:::doc
        ConfigFiles["Configuration Files"]:::doc
        CICD["CI/CD Configurations"]:::doc
    end

    %% Core DI Engine Relationships
    Container -->|"creates"| Definitions
    Container -->|"applies"| Interceptors
    Container -->|"uses"| ConfigDSL
    Container -->|"applies"| Strategies
    Container -->|"manages"| Context
    Container -->|"handles"| Disposal
    Container -->|"employs"| Utilities
    Definitions -->|"utilizes"| Utilities

    %% React Integration Relationships
    ReactComponents -->|"providesCtx"| ReactContext
    ReactHooks -->|"consumesCtx"| ReactContext
    ReactComponents -->|"initializes"| Container
    ReactInterceptors -->|"monitors"| Container

    %% Usage Example Relationship
    HTTPServer -->|"injects"| Container

    %% Documentation & Configurations Relationships
    Docs -->|"includes"| ConfigFiles
    Docs -->|"supportedBy"| CICD

    %% Click Events for Core DI Engine
    click ConfigDSL "https://github.com/robak86/hardwired/tree/master/packages/core/src/configuration"
    click Container "https://github.com/robak86/hardwired/tree/master/packages/core/src/container"
    click Interceptors "https://github.com/robak86/hardwired/tree/master/packages/core/src/container/interceptors"
    click Definitions "https://github.com/robak86/hardwired/tree/master/packages/core/src/definitions"
    click Context "https://github.com/robak86/hardwired/tree/master/packages/core/src/context"
    click Disposal "https://github.com/robak86/hardwired/tree/master/packages/core/src/disposable"
    click Strategies "https://github.com/robak86/hardwired/tree/master/packages/core/src/strategies"
    click Utilities "https://github.com/robak86/hardwired/tree/master/packages/core/src/utils"

    %% Click Events for React Integration Layer
    click ReactComponents "https://github.com/robak86/hardwired/tree/master/packages/react/src/components"
    click ReactContext "https://github.com/robak86/hardwired/blob/master/packages/react/src/context/ContainerContext.tsx"
    click ReactHooks "https://github.com/robak86/hardwired/tree/master/packages/react/src/hooks"
    click ReactInterceptors "https://github.com/robak86/hardwired/tree/master/packages/react/src/interceptors"

    %% Click Event for Usage Example
    click HTTPServer "https://github.com/robak86/hardwired/blob/master/packages/examples/src/httpServer.ts"

    %% Click Events for Documentation & Configurations
    click Docs "https://github.com/robak86/hardwired/tree/master/docs"
    click ConfigFiles "https://github.com/robak86/hardwired/blob/master/tsconfig.json"
    click CICD "https://github.com/robak86/hardwired/tree/master/.github/workflows"

    %% Styles
    classDef core fill:#FFD1DC,stroke:#FF69B4,stroke-width:2px;
    classDef react fill:#CFE2F3,stroke:#2185D0,stroke-width:2px;
    classDef examples fill:#D9EAD3,stroke:#6AA84F,stroke-width:2px;
    classDef doc fill:#FFF2CC,stroke:#F1C232,stroke-width:2px;
```
