# facebookresearch/kats architecture

> Architecture diagram of the GitHub repository facebookresearch/kats, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/facebookresearch/kats
- Repository: https://github.com/facebookresearch/kats

## Overview

##### Main Components Identification
The system should be divided into these major components:

a) Core Components:
- Time Series Data Handler (kats/consts.py)
- Data Management Layer (kats/data/)
- Compatibility Layer (kats/compat/)

b) Functional Modules:
- Detectors Module
- Models Module
- TSFeatures Module
- Utils Module
- Graphics Module
- Evaluation Module

**┌─────────────────────────────────────────────────────────┐**
- Client Applications                    │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Kats Core Layer                      │
- ┌─────────────┐  ┌──────────────┐  ┌──────────────┐   │
- TimeSeriesData│  │Data Manager  │  │Compatibility │   │
- ┘  └──────────────┘  └──────────────┘   │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Analysis Modules                       │
- ┌──────────┐ ┌────────┐ ┌──────────┐ ┌──────────────┐  │
- Detectors │ │Models  │ │TSFeatures│ │Evaluation    │  │
- ┘ └────────┘ └──────────┘ └──────────────┘  │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Support Modules                        │
- ┌──────────┐    ┌───────────┐    ┌──────────────┐    │
- Graphics  │    │Utils      │    │Metrics       │    │
- ┘    └───────────┘    └──────────────┘    │
- ┘

##### Component Details

- Core Components (Blue rectangles)
- TimeSeriesData: Central data structure
- Data Manager: Handles data I/O and validation
- Compatibility Layer: Manages dependencies

- Analysis Modules (Green rectangles)
- Detectors: Anomaly and changepoint detection
- Models: Forecasting models (Prophet, ARIMA, etc.)
- TSFeatures: Feature extraction
- Evaluation: Performance metrics

- Support Modules (Orange rectangles)
- Graphics: Visualization tools
- Utils: Helper functions
- Metrics: Measurement tools

##### Integration Points

External integration with:
- Prophet
- Scikit-learn
- Pandas
- StatsModels

##### Notes Section

Notes about:
- Minimal installation options
- Key dependencies
- Extension points
- Testing framework integration

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef core fill:#b3d1ff,stroke:#333,stroke-width:2px
    classDef analysis fill:#b3ffb3,stroke:#333,stroke-width:2px
    classDef support fill:#ffd9b3,stroke:#333,stroke-width:2px
    classDef client fill:#f2f2f2,stroke:#333,stroke-width:2px
    classDef external fill:#e6e6e6,stroke:#333,stroke-width:2px

    %% Client Layer
    subgraph ClientLayer
        Client["Client Applications"]
    end

    %% Core Layer
    subgraph CoreLayer
        TSData["Time Series Data Handler"]
        DataMgr["Data Management Layer"]
        Compat["Compatibility Layer"]
    end

    %% Analysis Layer
    subgraph AnalysisLayer
        Detect["Detectors Module"]
        Models["Models Module"]
        TSFeat["TSFeatures Module"]
        Eval["Evaluation Module"]

        %% Model Subcomponents
        MetaLearn["Meta-learning"]
        Ensemble["Ensemble Models"]
        Global["Global Models"]
    end

    %% Support Layer
    subgraph SupportLayer
        Graphics["Graphics Module"]
        Utils["Utils Module"]
        Metrics["Metrics Module"]
    end

    %% External Dependencies
    subgraph ExternalDeps
        Prophet["Prophet"]
        SKLearn["Scikit-learn"]
        Pandas["Pandas"]
        Stats["StatsModels"]
    end

    %% Relationships
    Client --> TSData
    TSData --> DataMgr
    DataMgr --> Compat

    TSData --> Detect
    TSData --> Models
    TSData --> TSFeat
    
    Models --> MetaLearn
    Models --> Ensemble
    Models --> Global
    
    Detect --> Eval
    Models --> Eval
    TSFeat --> Eval
    
    Eval --> Graphics
    Eval --> Metrics
    
    Compat -.-> Prophet
    Compat -.-> SKLearn
    Compat -.-> Pandas
    Compat -.-> Stats
    
    Utils --> Detect
    Utils --> Models
    Utils --> TSFeat

    %% Click Events
    click TSData "https://github.com/facebookresearch/Kats/blob/main/kats/consts.py"
    click DataMgr "https://github.com/facebookresearch/Kats/tree/main/kats/data/"
    click Compat "https://github.com/facebookresearch/Kats/tree/main/kats/compat/"
    click Detect "https://github.com/facebookresearch/Kats/tree/main/kats/detectors/"
    click Models "https://github.com/facebookresearch/Kats/tree/main/kats/models/"
    click TSFeat "https://github.com/facebookresearch/Kats/tree/main/kats/tsfeatures/"
    click Utils "https://github.com/facebookresearch/Kats/tree/main/kats/utils/"
    click Graphics "https://github.com/facebookresearch/Kats/tree/main/kats/graphics/"
    click Eval "https://github.com/facebookresearch/Kats/tree/main/kats/evaluation/"
    click MetaLearn "https://github.com/facebookresearch/Kats/tree/main/kats/models/metalearner/"
    click Ensemble "https://github.com/facebookresearch/Kats/tree/main/kats/models/ensemble/"
    click Global "https://github.com/facebookresearch/Kats/tree/main/kats/models/globalmodel/"
    click Metrics "https://github.com/facebookresearch/Kats/tree/main/kats/metrics/"

    %% Style Applications
    class Client client
    class TSData,DataMgr,Compat core
    class Detect,Models,TSFeat,Eval,MetaLearn,Ensemble,Global analysis
    class Graphics,Utils,Metrics support
    class Prophet,SKLearn,Pandas,Stats external
```
