# Product Requirements

## **`ConfigBuddy`**  

### **Purpose:**  
A lightweight tool for easily managing, comparing, and merging configuration files (Config) in complex projects.

---

### **Project Overview**  
`ConfigBuddy` is a lightweight CLI and library that can read various configuration file formats (JSON, YAML, INI, etc.) and **compare or merge their structures**.  
It is designed for developers and teams working with complex configuration files, making it easy to visualize changes and resolve conflicts.

---

### **Key Features**  

1. **Configuration File Reading and Structure Visualization**  
   - Read and visualize the structure of various configuration file formats including JSON, YAML, INI.  
   - Output configuration values in tree format via CLI.  
     ```bash
     configbuddy visualize config.yaml
     ```

2. **Configuration Comparison**  
   - Compare two or more configuration files to show **differences and duplicates**.  
     ```bash
     configbuddy diff config1.json config2.yaml
     ```

3. **Merging and Conflict Resolution**  
   - Merge configuration files, with manual conflict resolution or default value application when conflicts occur.  
     ```bash
     configbuddy merge config1.yaml config2.json --output merged_config.yaml
     ```

4. **Validation**  
   - Validate configuration files against predefined schemas (e.g., JSON Schema).  
     ```bash
     configbuddy validate config.yaml --schema schema.json
     ```

5. **Comment Preservation** *(Optional)*  
   - Preserve and modify comments in YAML and INI files.

---

### **Use Cases**  

1. **Configuration Management in Team Collaboration**  
   - Manage and compare configuration files across different environments (dev, staging, production).  

2. **Developer Workflow Improvement**  
   - Simplify merging and conflict resolution for complex configuration files.  

3. **DevOps and CI/CD Pipeline**  
   - Automatically validate configuration files to prevent errors before deployment.  

4. **Data Science Projects**  
   - Manage and compare experiment configuration versions.

---

### **Technology Stack**  

1. **Backend**: Python  
   - File I/O: `pyyaml`, `json`, `configparser`  
   - CLI Support: `jsonargparse` or `argparse`  

2. **Optional**: Web UI  
   - Simple configuration comparison and merge dashboard based on Flask or FastAPI.

---

### **Differentiating Points**  

1. **Simplicity and Lightweight**  
   - Lightweight design for easy use in small projects, unlike complex configuration management tools (Airflow, Ansible, etc.).  

2. **Multiple Format Support**  
   - Supports various configuration file formats (JSON, YAML, INI), allowing users to work seamlessly in mixed environments.  

3. **Comment Preservation**  
   - Unlike most configuration file management tools that ignore comments, `ConfigBuddy` preserves and allows modification of comments.

---

### **Extensibility**  

1. **Git Integration**  
   - Integrate with Git for easy resolution of configuration file change history and merge conflicts.  

2. **CLI Extension**  
   - Support for more file formats (XML, etc.) and integration with scripts.  

3. **Real-time Web Dashboard**  
   - Simple web app for real-time configuration file comparison and merging.  

---

## **Detailed Feature Specification**

### **1. Project Overview**  
`ConfigBuddy` is a lightweight CLI and library tool for comparing, merging, visualizing, and validating various configuration files (JSON, YAML, INI, etc.).  

---

### **2. Key Requirements**  

#### **2.1 File Reading and Processing**
- **Supported Formats**: JSON, YAML, INI
- **Features**: 
  - File reading and writing
  - Store configuration key-value pairs in tree structure
  - Comment preservation (YAML, INI) *(implement as option if possible)*

---

#### **2.2 CLI Interface**  
- **Command Structure**:  
  Call functions using commands in CLI:
  ```bash
  configbuddy <command> [options]
  ```

- **Supported Commands**:  
  1. **`visualize`**:  
     Output configuration file structure in tree format.  
     ```bash
     configbuddy visualize config.yaml
     ```
     - Output Example:
       ```
       config.yaml:
       ├── database:
       │   ├── host: localhost
       │   ├── port: 5432
       ├── logging:
           ├── level: debug
           ├── format: "%(asctime)s - %(message)s"
       ```

  2. **`diff`**:  
     Compare two configuration files and show differences.  
     ```bash
     configbuddy diff config1.json config2.yaml
     ```
     - Options:  
       - `--output-format` (select text, JSON, YAML format)  

  3. **`merge`**:  
     Merge two or more configuration files.  
     ```bash
     configbuddy merge config1.yaml config2.json --output merged_config.yaml
     ```
     - Resolve conflicts using default values or user input.  

  4. **`validate`**:  
     Validate configuration files.  
     ```bash
     configbuddy validate config.yaml --schema schema.json
     ```

---

#### **2.3 Internal Library Functions**
1. **File Parsing and Data Conversion**:
   - Convert JSON, YAML, INI files to Python dictionary format.
   - Include comment preservation logic *(optional)*.

2. **Structure Comparison**:
   - Compare two or more dictionaries to return differences and commonalities.

3. **Merge Logic**:
   - Resolve conflicts through user selection or default merge rules.

4. **Validation**:
   - Validate data format based on JSON Schema.

5. **Logging and Error Handling**:
   - Detailed logging of errors occurring during each operation.

---

#### **2.4 Installation and Deployment**
1. **Packaging**:
   - Deploy to PyPI using `pyproject.toml`.
   - Dependencies: `pyyaml`, `configparser`, `jsonschema`, `jsonargparse`(for CLI implementation).

2. **Installation Command**:
   ```bash
   pip install configbuddy
   ```

---

#### **2.5 Documentation and Examples**
- **README.md**: Project overview, key features, installation method, usage examples.  
- **Help Command**:
  ```bash
  configbuddy --help
  ```

---

### **3. Extensibility**  

#### **3.1 Additional File Formats**
- Support for additional formats like XML, TOML.  

#### **3.2 Git Integration**
- Integration with Git history: Compare configuration file changes with Git.  

#### **3.3 Web UI** *(Extension Phase)*  
- Develop web application based on Flask or FastAPI for uploading, visualizing, merging, and validating configuration files.  

#### **3.4 Plugin System**
- Support plugins allowing users to write custom parsers for specific configuration formats.
