# olufemithompson/multibeanconfig architecture

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

- Interactive diagram: https://gitdiagram.com/olufemithompson/multibeanconfig
- Repository: https://github.com/olufemithompson/multibeanconfig

## Overview

##### Project Overview and Purpose
- The project is a lightweight Spring library that enables registering, configuring, and managing multiple instances (“beans”) of the same class with individual configurations.
- It integrates with Spring’s dependency injection system and the auto-configuration mechanism (as indicated by the presence of spring auto-configuration files in src/main/resources) to simplify bean management.
- The library leverages annotation scanning (via the custom @MultiBean annotation) and configuration property injection (by supporting constructor, @Autowired, and @Value injection techniques).

##### Main Architectural Components to Highlight
A. Core Library Components:
- MultiBean Annotation – Marks a service class for multi-bean configuration.
- Post-Processors:
- BeanPropertyPostProcessor – Likely responsible for processing bean properties and applying configurations.
- ConfigurationPropertyPostProcessor – Handles the retrieval of default and bean-specific configuration properties.
- MultiBeanDefinitionPostProcessor – Potentially intercepts bean definition registration to handle multiple bean instantiation.
- MultiBeanConfigRegistry – Maintains a registry of all the configured beans and their settings.
- Utility Functions (Utils.java, Constants.java) – Provide common helper methods and static configuration constants.

B. Spring Integration:
- Auto Configuration:
- The presence of a file under META-INF/spring (AutoConfiguration.imports) indicates that the library plugs into Spring Boot’s auto-configuration mechanism.
- Integration with Spring’s Dependency Injection:
- Components are set up either by constructor injection, @Autowired, or using @Value for individual properties.
- Configuration Properties Binding – The library works with configuration files (application.yml/properties) providing default and bean-specific configurations.

C. Supporting Elements:
- Maven Build Configuration (pom.xml) – Establishes dependencies and build plugins, which is especially important for Spring and Maven-based projects.
- GitHub workflows and metadata files (LICENSE, .gitignore) – Though not part of the runtime architecture, they indicate the CI/CD integration and open-source guidelines.

##### How the Components Interact
- Configuration Input:
- The end developer defines default configuration and multiple bean-specific settings in application.yml.
- Spring reads these properties during startup.
- Annotation & Post-Processing:
- @MultiBean annotation signals that the corresponding bean should be processed by the library.
- MultiBeanDefinitionPostProcessor intercepts bean creation, using the properties configuration to instantiate each bean with its specified setup.
- BeanPropertyPostProcessor and ConfigurationPropertyPostProcessor further customize or inject properties into the bean instances.
- Bean Registration & Lookup:
- MultiBeanConfigRegistry maintains the registrations so that dependent services (like ConfiguredService as seen in the README) can retrieve the appropriate bean instances via dependency injection.
- Auto Configuration:
- The spring auto-configuration mechanism, via the file inside META-INF/spring, ensures that these post-processors and registry components are automatically loaded during application startup.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration Input
    configInput["Configuration Input (application.yml)"]:::config

    %% External Annotation
    multiBeanAnno["@MultiBean Annotation"]:::bean

    %% Auto Configuration Integration
    autoConfig["Spring Auto-Configuration Integration"]:::spring

    %% Bean Post-Processors Subgraph
    subgraph "Bean Post-Processors"
        beanPP["BeanPropertyPostProcessor"]:::bean
        configPropPP["ConfigurationPropertyPostProcessor"]:::bean
        multiBeanDefPP["MultiBeanDefinitionPostProcessor"]:::bean
    end

    %% Core Registry
    configRegistry["MultiBeanConfigRegistry"]:::bean

    %% Application Bean Consumer
    consumer["Configured Service (Bean Consumer)"]:::spring

    %% Utilities Subgraph
    subgraph "Utilities"
        utils["Utils.java"]:::support
        constants["Constants.java"]:::support
    end

    %% Supporting Build Element
    maven["Maven Build Configuration (pom.xml)"]:::support

    %% Relationships
    configInput -->|"suppliesProperties"| configPropPP
    configInput -->|"suppliesProperties"| multiBeanDefPP
    multiBeanAnno -->|"marksBean"| multiBeanDefPP
    
    autoConfig -->|"loads"| beanPP
    autoConfig -->|"loads"| configPropPP
    autoConfig -->|"loads"| multiBeanDefPP
    autoConfig -->|"registers"| configRegistry

    beanPP -->|"processesBean"| configRegistry
    configPropPP -->|"injectsProperties"| configRegistry
    multiBeanDefPP -->|"instantiatesBeans"| configRegistry

    configRegistry -->|"injectsBeans"| consumer

    %% Styles
    classDef config fill:#B3E5FC,stroke:#0277BD,stroke-width:2px;
    classDef bean fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef spring fill:#FFECB3,stroke:#FBC02D,stroke-width:2px;
    classDef support fill:#D1C4E9,stroke:#7E57C2,stroke-width:2px;

    %% Click Events
    click multiBeanAnno "https://github.com/olufemithompson/multibeanconfig/blob/main/src/main/java/io/github/olufemithompson/multibeanconfig/MultiBean.java"
    click beanPP "https://github.com/olufemithompson/multibeanconfig/blob/main/src/main/java/io/github/olufemithompson/multibeanconfig/BeanPropertyPostProcessor.java"
    click configPropPP "https://github.com/olufemithompson/multibeanconfig/blob/main/src/main/java/io/github/olufemithompson/multibeanconfig/ConfigurationPropertyPostProcessor.java"
    click multiBeanDefPP "https://github.com/olufemithompson/multibeanconfig/blob/main/src/main/java/io/github/olufemithompson/multibeanconfig/MultiBeanDefinitionPostProcessor.java"
    click configRegistry "https://github.com/olufemithompson/multibeanconfig/blob/main/src/main/java/io/github/olufemithompson/multibeanconfig/MultiBeanConfigRegistry.java"
    click utils "https://github.com/olufemithompson/multibeanconfig/blob/main/src/main/java/io/github/olufemithompson/multibeanconfig/Utils.java"
    click constants "https://github.com/olufemithompson/multibeanconfig/blob/main/src/main/java/io/github/olufemithompson/multibeanconfig/Constants.java"
    click autoConfig "https://github.com/olufemithompson/multibeanconfig/blob/main/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports"
    click maven "https://github.com/olufemithompson/multibeanconfig/blob/main/pom.xml"
```
