# vpatel95/decision-tree-classifier architecture

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

- Interactive diagram: https://gitdiagram.com/vpatel95/decision-tree-classifier
- Repository: https://github.com/vpatel95/decision-tree-classifier

## Overview

##### Project type and purpose
- This is an open-source command-line tool (C++ and Python) that implements a Decision Tree Classifier and Random Forest/Boosted Forest Classifier to predict room occupancy from sensor data.
- It uses data preprocessing, configurable model parameters, training on UCI sensor datasets, and evaluation via a Python test harness.

##### File structure
- Top-level:
- .gitignore, README.md, bitbucket-pipelines.yml (CI config)
- src/ (all source code)
- src/:
- Makefile (build scripts)
- classifier.cpp, decision_tree.cpp (core C++ implementations)
- includes/json.hpp (header-only JSON parser)
- includes/decision_tree.hpp (public API for tree structures)
- configs/config.json (model/configuration parameters)
- data/ (raw and split datasets + preprocessing script)
– data_preprocessing.py (cleaning/extracting features)
– test.txt, training.txt, validate.txt, validation.txt
- run_test.py (Python harness to invoke the compiled binary on datasets)
- Patterns:
- Modular separation: data preprocessing, core algorithms, config, test harness
- Single binary (appears to be “app” or classifier executable) invoked by Python

##### Key insights from README
- Configurable pipeline driven by JSON: choose model type, feature set, train/test/validation paths, bagging/boosting parameters.
- Build via Makefile or direct g++ command.
- Usage: run the binary with config, then inspect output or trees.
- Dependencies: g++, Python 3.x, UCI datasets.

##### Main components
a. Data Sources
- Raw sensor files (training.txt, test.txt, validation.txt)
b. Data Preprocessing Module (Python)
- data_preprocessing.py: cleans raw data, extracts features → writes extracted files
c. Configuration Module
- configs/config.json: holds all pipeline parameters
d. Core Classifier (C++ Binary)
- classifier.cpp & decision_tree.cpp: build Decision Tree, Random Forest, Boosted Forest
- json.hpp: parse config.json at runtime
e. Test Harness (Python)
- run_test.py: invokes the C++ binary with various configs and data splits, collects metrics
f. Build & CI
- src/Makefile: compile steps
- bitbucket-pipelines.yml: CI build/test definitions

##### Relationships & interactions
- (1) Data Preprocessor reads raw sensor files → outputs preprocessed feature files.
- (2) C++ binary at startup reads configs/config.json via json.hpp.
- (3) C++ binary loads extracted data, instantiates model (Decision Tree or Random Forest), trains on training set.
- (4) C++ binary writes predictions & optionally tree visualizations.
- (5) run_test.py orchestrates multiple runs: calls the binary, captures accuracy, logs results.
- (6) Makefile ties together build; CI definition kicks off Make and run_test.py.

##### Architectural patterns and design principles
- Single Responsibility: each module (preprocessing, configuration, training, testing) does one job.
- Config-driven pipeline: change behavior by editing JSON.
- Modular C++ code: public API (decision_tree.hpp) vs implementation.
- Extensibility: can add new classifiers or metrics by extending source and config schema.

##### Technologies & frameworks to annotate
- C++11 (g++): core algorithms.
- Python 3.x: data preprocessing & test harness.
- JSON.hpp: config parsing.
- Make & CI (Bitbucket Pipelines)

##### Detail
- File paths (e.g., src/data/, src/configs/, src/includes/).
- JSON parsing step inside the binary.
- Optional paths (e.g., validation vs test).
- Do not overcrowd: group similar elements but keep them distinct.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Sources
    subgraph "Data Sources\n(src/data/)" 
        direction TB
        TS["test.txt"]:::data
        TR["training.txt"]:::data
        VA1["validate.txt"]:::data
        VA2["validation.txt"]:::data
    end
    click TS "https://github.com/vpatel95/decision-tree-classifier/blob/master/src/data/test.txt"
    click TR "https://github.com/vpatel95/decision-tree-classifier/blob/master/src/data/training.txt"
    click VA1 "https://github.com/vpatel95/decision-tree-classifier/blob/master/src/data/validate.txt"
    click VA2 "https://github.com/vpatel95/decision-tree-classifier/blob/master/src/data/validation.txt"

    %% Preprocessing
    Pre["Preprocessing Module\n(data_preprocessing.py)"]:::python
    click Pre "https://github.com/vpatel95/decision-tree-classifier/blob/master/src/data/data_preprocessing.py"

    %% Extracted Data
    ED["Extracted Feature Files"]:::data

    %% Configuration
    CFG["Configuration\n(configs/config.json)"]:::config
    click CFG "https://github.com/vpatel95/decision-tree-classifier/blob/master/src/configs/config.json"

    %% Classifier Engine
    subgraph "Classifier Engine\n(C++ Binary)" 
        direction TB
        C1["classifier.cpp"]:::cxx
        C2["decision_tree.cpp"]:::cxx
        H1["json.hpp"]:::cxx
        H2["decision_tree.hpp"]:::cxx
    end
    click C1 "https://github.com/vpatel95/decision-tree-classifier/blob/master/src/classifier.cpp"
    click C2 "https://github.com/vpatel95/decision-tree-classifier/blob/master/src/decision_tree.cpp"
    click H1 "https://github.com/vpatel95/decision-tree-classifier/blob/master/src/includes/json.hpp"
    click H2 "https://github.com/vpatel95/decision-tree-classifier/blob/master/src/includes/decision_tree.hpp"

    %% Test Harness
    TH["Test Harness\n(run_test.py)"]:::python
    click TH "https://github.com/vpatel95/decision-tree-classifier/blob/master/src/run_test.py"

    %% Metrics
    M["Metrics & Reports"]:::data

    %% Build & CI
    subgraph "Build & CI"
        direction TB
        MF["Makefile"]:::config
        CI["Pipelines\n(bitbucket-pipelines.yml)"]:::config
    end
    click MF "https://github.com/vpatel95/decision-tree-classifier/tree/master/src/Makefile"
    click CI "https://github.com/vpatel95/decision-tree-classifier/blob/master/bitbucket-pipelines.yml"

    %% Flow
    TS --> Pre
    TR --> Pre
    VA1 --> Pre
    VA2 --> Pre
    Pre --> ED
    ED -->|"input data"| C1
    CFG -->|"configures"| C1
    C1 --> TH
    TH --> M

    MF -->|"builds"| C1
    CI --> MF
    CI --> TH

    %% Styles
    classDef python fill:#D0E6FF,stroke:#333,stroke-width:1px
    classDef cxx fill:#D0FFD0,stroke:#333,stroke-width:1px
    classDef data fill:#FFF5BA,stroke:#333,stroke-width:1px
    classDef config fill:#FFD8A8,stroke:#333,stroke-width:1px
```
