# feature-engine/feature_engine architecture

> Architecture diagram of the GitHub repository feature-engine/feature_engine, 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/feature-engine/feature_engine
- Repository: https://github.com/feature-engine/feature_engine

## Overview

##### Main Components
- Library Core – The heart of the package lies in the “feature_engine” directory. It contains modules for various feature engineering functionality:
- Data Transformation/Creation (e.g., math_features, relative_features, cyclical_features, decision_tree_features)
- Preprocessing (e.g., imputation, encoding, discretisation, outlier handling, transformation, scaling)
- Feature Selection (e.g., drop features, correlated features, recursive elimination, and more)
- Datetime processing and Time Series features
- Wrappers and pipelines for integrating with Scikit-learn
- Base Classes and Shared Functionalities – Look at the “_base_transformers”, “_check_init_parameters” and “_docstrings” modules that establish common behaviors across transformers.
- Testing Suite – The “tests” directory holds many detailed unit and integration tests. It is critical to show how testing is related to every component to maintain robustness.
- Documentation Infrastructure – The “docs” folder (with Sphinx-specific files and custom extensions) defines how the documentation is built and hosted on Read the Docs.
- CI/CD and Contribution Tools – Directories like “.circleci”, “.github”, configuration files (pytest.ini, tox.ini, etc.), and setup scripts indicate continuous integration, testing, and deployment workflows.
- External Resources – The README links to online courses, notebooks, and external dependencies (like Scikit-learn) implying that user examples and training materials are an important part of the ecosystem.

##### Relationships and Interactions
- The library is built around a common design pattern based on fit/transform methods, similar to Scikit-learn. Illustrate how each transformer (in encoding, imputation, discretisation, etc.) inherits or builds upon the base classes.
- How the Pipeline (and make_pipeline) integrates multiple transformers into a sequential processing flow.
- Flow from raw input data → preprocessing → transformation/encoding → feature selection → final modelling (conceptually, even if the library itself does not provide a full modelling layer).
- Testing layer that runs against each of these components, ensuring that each module complies with expected behavior.
- Documentation build process and CI/CD pipelines as part of the extended “ecosystem” that ensures quality and maintainability.

##### Architectural Patterns and Design Principles
- Modular Design: The project is clearly divided into functional modules (e.g., encoding, imputation, discretisation) allowing independent development and testing.
- Layered Architecture: Core logic (the transformers) is isolated from the user interface (documentation and usage examples) and deployment/integration (CI/CD configurations).
- Adherence to Interfaces: The project follows the Scikit-learn transformer paradigm (fit/transform), so showing how each module conforms to these standards is imperative.
- Emphasis on Reusability: Many submodules like the mixins, base classes, and common documentation modules are aimed at reusability across feature engineering components.

##### Relevant Technologies, Frameworks, and Tools
- Python and Scikit-learn APIs.
- Sphinx for documentation.
- Pytest for unit testing.
- CI/CD tools (CircleCI, GitHub Actions) and related configuration files.
- Packaging components (setup.py, requirements.txt) that outline dependency management and installation.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Inputs & Dependencies
    external1["User Data & External Dependencies (Scikit-learn,Online Courses)"]:::external
    external2["External Resources (README,CONTRIBUTING,CODE_OF_CONDUCT,LICENSE)"]:::external

    %% Support Ecosystem Nodes
    id_testing["Testing Suite (tests)"]:::support
    id_docs["Documentation Infrastructure (docs)"]:::support
    id_ci["CI/CD & Contribution Tools (.circleci, .github,pytest.ini,tox.ini,setup.py)"]:::support

    %% Data Flow Nodes
    rawData["Raw Input Data"]:::data
    processedData["Processed Data"]:::data

    %% Core Library and its Submodules
    core["Core Library (feature_engine)"]:::core
    creation["Data Transformation/Creation"]:::coreSub
    preprocessing["Preprocessing"]:::coreSub
    selection["Feature Selection"]:::coreSub
    datetime["Datetime Processing"]:::coreSub
    wrappers["Wrappers & Pipeline Integration"]:::coreSub
    pipeline["Pipeline"]:::coreSub
    base["Base Classes & Shared Functionalities"]:::coreSub
    base_transformers["Base Transformers"]:::coreSub
    parameter_check["Parameter Checking"]:::coreSub
    docstrings["Shared Docstrings"]:::coreSub

    %% Data Flow
    rawData -->|"preprocesses"| preprocessing
    preprocessing -->|"transforms"| creation
    creation -->|"selects features"| selection
    selection -->|"wraps into"| wrappers
    wrappers -->|"integrates as"| pipeline
    pipeline -->|"outputs"| processedData

    %% Core Library Internal Relationships
    core --> creation
    core --> preprocessing
    core --> selection
    core --> datetime
    core --> wrappers
    core --> base

    base --> base_transformers
    base --> parameter_check
    base --> docstrings

    %% External and Support Relationships
    external1 -->|"supplies data to"| core
    external2 -->|"provides metadata to"| id_docs
    id_testing -->|"validates"| core
    id_docs -->|"documents"| core
    id_ci -->|"automates testing/docs"| id_testing
    id_ci --> id_docs

    %% Click Events for Component Mapping
    click core "https://github.com/feature-engine/feature_engine/tree/main/feature_engine/"
    click creation "https://github.com/feature-engine/feature_engine/tree/main/feature_engine/creation/"
    click preprocessing "https://github.com/feature-engine/feature_engine/tree/main/feature_engine/preprocessing/"
    click selection "https://github.com/feature-engine/feature_engine/tree/main/feature_engine/selection/"
    click datetime "https://github.com/feature-engine/feature_engine/tree/main/feature_engine/datetime/"
    click wrappers "https://github.com/feature-engine/feature_engine/tree/main/feature_engine/wrappers/"
    click pipeline "https://github.com/feature-engine/feature_engine/tree/main/feature_engine/pipeline/"
    click base_transformers "https://github.com/feature-engine/feature_engine/tree/main/feature_engine/_base_transformers/"
    click parameter_check "https://github.com/feature-engine/feature_engine/tree/main/feature_engine/_check_init_parameters/"
    click docstrings "https://github.com/feature-engine/feature_engine/tree/main/feature_engine/_docstrings/"
    click id_testing "https://github.com/feature-engine/feature_engine/tree/main/tests/"
    click id_docs "https://github.com/feature-engine/feature_engine/tree/main/docs/"
    click id_ci "https://github.com/feature-engine/feature_engine/tree/main/.circleci/"
    click external2 "https://github.com/feature-engine/feature_engine/blob/main/README.md"

    %% Class Styles
    classDef external fill:#f9c,stroke:#333,stroke-width:2px;
    classDef core fill:#bbf,stroke:#333,stroke-width:2px;
    classDef coreSub fill:#ddf,stroke:#333,stroke-width:1px;
    classDef support fill:#cfc,stroke:#333,stroke-width:2px;
    classDef data fill:#ffc,stroke:#333,stroke-width:2px;
```
