# lanesket/painy architecture

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

- Interactive diagram: https://gitdiagram.com/lanesket/painy
- Repository: https://github.com/lanesket/painy

## Overview

##### Project type and purpose
- Painy is a standalone Python command-line tool for generating Git commit messages by leveraging the OpenAI API.
- It integrates with Git (including notebook diffing via nbdime), applies configurable rules, and optionally adapts to the style of past commits.

##### File structure
- Top level:
- setup.py, requirements.txt – packaging and dependencies
- README.md, LICENSE, .gitignore
- .github/workflows/python-publish.yml – CI/CD pipeline for publishing to PyPI
- “painy/” package:
- main.py – CLI entrypoint
- chat.py – OpenAI API client adapter
- git.py – Git interaction and diff extraction (including nbdime for .ipynb)
- comment.py & managers.py – core logic for “comment” and “commit” commands, rule application
- settings/ – configuration files (JSON prompts, extension lists, rule definitions)
- enums.py, utils.py – shared types and helper functions
- errors/ – custom exception hierarchy

##### README for additional insights
- Commands: “painy comment”, “painy commit”, “painy config”, “painy rules”
- Interactive (-i) mode, “--check-all” flag, style-history toggles
- Relies on OpenAI API key and optional model selection via env vars

##### Detail
- Where exceptions may be thrown (errors/*.py)
- Call out configuration file names (rules.json, prompt_comment_base.txt, etc.)
- Optional branches for interactive mode and history-style prompts

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "CLI Layer"
        CLI["main.py\n(CLI Layer)"]:::module
    end

    subgraph "Managers Layer"
        CommentMgr["comment.py\n(Rule Engine Logic)"]:::module
        Managers["managers.py\n(Command Managers)"]:::module
    end

    subgraph "Adapters Layer"
        GitAdapter["git.py\n(Git Adapter)"]:::module
        ChatAdapter["chat.py\n(Chat API Adapter)"]:::module
    end

    subgraph "Settings & Rule Engine"
        ConfigJSON["config.json"]:::config
        ExtList["p_extensions.txt"]:::config
        PromptComment["prompt_comment_base.txt"]:::config
        PromptStyle["prompt_commit_style.txt"]:::config
        RulesJSON["rules.json"]:::config
    end

    subgraph "Domain & Utils"
        Enums["enums.py\n(Enums & Models)"]:::module
        Utils["utils.py\n(Utilities)"]:::module
        Errors["errors/\n(Custom Exceptions)"]:::module
    end

    subgraph "External Services"
        OpenAI["OpenAI API"]:::external
        Nbdime["nbdime\n(Jupyter diff lib)"]:::external
        GitRepo["Git Repo"]:::external
    end

    CLI -->|"invoke command"| Managers
    Managers -->|"fetch diffs"| GitAdapter
    GitRepo -->|"repo state"| GitAdapter
    Nbdime -->|"notebook diffing"| GitAdapter
    GitAdapter -->|"staged diffs"| Managers

    Managers -->|"load configs"| ConfigJSON
    Managers -->|"load configs"| ExtList
    Managers -->|"load base prompt"| PromptComment
    Managers -->|"load style prompts"| PromptStyle
    Managers -->|"load rule definitions"| RulesJSON

    Managers -->|"assemble prompt"| CommentMgr
    CommentMgr --> Managers

    Managers -->|"send prompt + rules"| ChatAdapter
    ChatAdapter -->|"API call"| OpenAI
    OpenAI -->|"response message"| ChatAdapter
    ChatAdapter -->|"generated message"| Managers

    Managers -->|"return message"| CLI

    Managers -->|"git commit"| GitAdapter
    GitAdapter -->|"executes commit"| GitRepo

    Managers -->|"throw exceptions"| Errors
    CLI -->|"handle exceptions"| Errors

    classDef module fill:#ACE,stroke:#036,stroke-width:1px
    classDef config fill:#FFF,stroke-dasharray:5 5,stroke:#088,stroke-width:1px
    classDef external fill:#FAF,stroke:#C36,stroke-width:1px

    click CLI "https://github.com/lanesket/painy/blob/main/painy/main.py"
    click Managers "https://github.com/lanesket/painy/blob/main/painy/managers.py"
    click CommentMgr "https://github.com/lanesket/painy/blob/main/painy/comment.py"
    click GitAdapter "https://github.com/lanesket/painy/blob/main/painy/git.py"
    click ChatAdapter "https://github.com/lanesket/painy/blob/main/painy/chat.py"
    click ConfigJSON "https://github.com/lanesket/painy/blob/main/painy/settings/config.json"
    click ExtList "https://github.com/lanesket/painy/blob/main/painy/settings/p_extensions.txt"
    click PromptComment "https://github.com/lanesket/painy/blob/main/painy/settings/prompt_comment_base.txt"
    click PromptStyle "https://github.com/lanesket/painy/blob/main/painy/settings/prompt_commit_style.txt"
    click RulesJSON "https://github.com/lanesket/painy/blob/main/painy/settings/rules.json"
    click Enums "https://github.com/lanesket/painy/blob/main/painy/enums.py"
    click Utils "https://github.com/lanesket/painy/blob/main/painy/utils.py"
    click Errors "https://github.com/lanesket/painy/blob/main/painy/errors/__init__.py"
```
