# pradyrk/betterpython architecture

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

- Interactive diagram: https://gitdiagram.com/pradyrk/betterpython
- Repository: https://github.com/pradyrk/betterpython

## Overview

##### Project type and purpose
- This is not a running web service or microservice platform but an educational code‐example library. Each top‐level folder (named “1 – coupling and cohesion”, “2 – dependency inversion”, etc.) holds before/after Python scripts illustrating a specific coding principle or design pattern. The README confirms it’s companion material for a “Write Better Python Code” video series.

##### File structure
- Top-level directories (1–10 and “9 – solid”) each correspond to a numbered lesson/topic.
- Root has configuration files (`.gitignore`, `requirements.txt`), the `README.md`, and a `LICENSE`.
- There’s no single entrypoint or runtime orchestration—each lesson is standalone.

##### README for additional insights
- Confirms the repo is a packaged set of examples for a YouTube playlist.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Pattern Library Repository"
        direction TB
        subgraph "Tier 1: Fundamentals"
            direction TB
            subgraph "1 - Coupling & Cohesion Module" 
                direction TB
                CC_BEFORE["coupling-cohesion-before.py"]:::before
                CC_AFTER["coupling-cohesion-after.py"]:::after
            end
            subgraph "2 - Dependency Inversion Module"
                direction TB
                DI_BEFORE["dependency-inversion-before.py"]:::before
                DI_AFTER["dependency-inversion-after.py"]:::after
            end
            subgraph "9 - SOLID Principles Module"
                direction TB
                SR_BEFORE["single-responsibility-before.py"]:::before
                SR_AFTER["single-responsibility-after.py"]:::after
                OC_BEFORE["open-closed-before.py"]:::before
                OC_AFTER["open-closed-after.py"]:::after
                LS_BEFORE["Liskov-substitution-before.py"]:::before
                LS_AFTER["liskov-substitution-after.py"]:::after
                IS_BEFORE["interface-segregation-before.py"]:::before
                IS_AFTER["interface-segregation-after.py"]:::after
                IS_COMP["interface-segregation-after-comp.py"]:::after
                DI2_BEFORE["dependency-inversion-before.py"]:::before
                DI2_AFTER["dependency-inversion-after.py"]:::after
            end
        end

        subgraph "Tier 2: Behavioral Patterns"
            direction TB
            subgraph "3 - Strategy Pattern Module"
                direction TB
                SP_BEFORE["strategy-before.py"]:::before
                SP_AFTER1["strategy-after.py"]:::after
                SP_AFTER2["strategy-after-fn.py"]:::after
            end
            subgraph "4 - Observer Pattern Module"
                direction TB
                OBS_BEFORE["observer-before.py"]:::before
                OBS_AFTER["observer-after.py"]:::after
                subgraph "API v1"
                    direction TB
                    API1_INIT["api/__init__.py"]:::module
                    API1_PLAN["api/plan.py"]:::module
                    API1_USER["api/user.py"]:::module
                end
                subgraph "API v2"
                    direction TB
                    API2_INIT["api_v2/__init__.py"]:::module
                    API2_EVT["api_v2/event.py"]:::module
                    API2_PLAN["api_v2/plan.py"]:::module
                    API2_USER["api_v2/user.py"]:::module
                    API2_EMAIL["api_v2/email_listener.py"]:::module
                    API2_SLACK["api_v2/slack_listener.py"]:::module
                    API2_LOG["api_v2/log_listener.py"]:::module
                end
                subgraph "Shared Utility Library"
                    direction TB
                    LIB_INIT["lib/__init__.py"]:::module
                    LIB_DB["lib/db.py"]:::module
                    LIB_EMAIL["lib/email.py"]:::module
                    LIB_LOG["lib/log.py"]:::module
                    LIB_SLACK["lib/slack.py"]:::module
                    LIB_STR["lib/stringtools.py"]:::module
                end
                API2_EVT -->|emits| API2_EMAIL
                API2_EVT -->|emits| API2_SLACK
                API2_EVT -->|emits| API2_LOG
                API2_EMAIL --> LIB_EMAIL
                API2_SLACK --> LIB_SLACK
                API2_LOG --> LIB_LOG
            end
            subgraph "6 - Template Method & Bridge Module"
                direction TB
                TM_BEFORE["trading-before.py"]:::before
                TM_AFTER["trading-after.py"]:::after
                TM_BRIDGE["with-bridge.py"]:::after
            end
            subgraph "8 - MVC Module"
                direction TB
                MVC_BEFORE["mvc-before.py"]:::before
                MVC_AFTER["mvc-after.py"]:::after
                MVC_STRAT["mvc-after-strategy.py"]:::after
            end
        end

        subgraph "Tier 3: Quality & Testing"
            direction TB
            subgraph "5 - Unit Testing Module"
                direction TB
                UT_BEFORE["vehicle_info_before.py"]:::before
                UT_AFTER["vehicle_info_after.py"]:::after
                UT_TEST["vehicle_info_test.py"]:::test
            end
            subgraph "7 - Error Handling Module"
                direction TB
                EH_BEF_APP["before/app.py"]:::before
                EH_BEF_DB["before/db.py"]:::before
                EH_AFT_APP["after/app.py"]:::after
                EH_AFT_CONTEXT["after-context/error-handling-context.py"]:::after
                subgraph "Advanced Decorators"
                    direction TB
                    AD_LOG["advanced/logging-decorator.py"]:::module
                    AD_RETRY["advanced/retry-decorator.py"]:::module
                end
                subgraph "Monadic Error Handling"
                    direction TB
                    MON_EX["monadic-error-handling/example.py"]:::module
                end
            end
        end

        subgraph "Configuration & Metadata"
            direction TB
            GITIGNORE[".gitignore"]:::config
            README["README.md"]:::config
            REQ["requirements.txt"]:::config
            LICENSE["LICENSE"]:::config
        end
    end

    classDef before fill:#f8d7da,stroke:#721c24,color:#721c24;
    classDef after fill:#d4edda,stroke:#155724,color:#155724;
    classDef module fill:#cce5ff,stroke:#004085,color:#004085;
    classDef test fill:#fff3cd,stroke:#856404,color:#856404;
    classDef config fill:#e2e3e5,stroke:#6c757d,color:#6c757d;

    %% Click Events
    click CC_BEFORE "https://github.com/pradyrk/betterpython/blob/main/1 - coupling and cohesion/coupling-cohesion-before.py"
    click CC_AFTER "https://github.com/pradyrk/betterpython/blob/main/1 - coupling and cohesion/coupling-cohesion-after.py"
    click DI_BEFORE "https://github.com/pradyrk/betterpython/blob/main/2 - dependency inversion/dependency-inversion-before.py"
    click DI_AFTER "https://github.com/pradyrk/betterpython/blob/main/2 - dependency inversion/dependency-inversion-after.py"
    click SP_BEFORE "https://github.com/pradyrk/betterpython/blob/main/3 - strategy pattern/strategy-before.py"
    click SP_AFTER1 "https://github.com/pradyrk/betterpython/blob/main/3 - strategy pattern/strategy-after.py"
    click SP_AFTER2 "https://github.com/pradyrk/betterpython/blob/main/3 - strategy pattern/strategy-after-fn.py"
    click OBS_BEFORE "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/observer-before.py"
    click OBS_AFTER "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/observer-after.py"
    click API1_INIT "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/api/__init__.py"
    click API1_PLAN "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/api/plan.py"
    click API1_USER "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/api/user.py"
    click API2_INIT "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/api_v2/__init__.py"
    click API2_EVT "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/api_v2/event.py"
    click API2_PLAN "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/api_v2/plan.py"
    click API2_USER "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/api_v2/user.py"
    click API2_EMAIL "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/api_v2/email_listener.py"
    click API2_SLACK "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/api_v2/slack_listener.py"
    click API2_LOG "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/api_v2/log_listener.py"
    click LIB_INIT "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/lib/__init__.py"
    click LIB_DB "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/lib/db.py"
    click LIB_EMAIL "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/lib/email.py"
    click LIB_LOG "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/lib/log.py"
    click LIB_SLACK "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/lib/slack.py"
    click LIB_STR "https://github.com/pradyrk/betterpython/blob/main/4 - observer pattern/lib/stringtools.py"
    click UT_BEFORE "https://github.com/pradyrk/betterpython/blob/main/5 - unit testing/vehicle_info_before.py"
    click UT_AFTER "https://github.com/pradyrk/betterpython/blob/main/5 - unit testing/vehicle_info_after.py"
    click UT_TEST "https://github.com/pradyrk/betterpython/blob/main/5 - unit testing/vehicle_info_test.py"
    click TM_BEFORE "https://github.com/pradyrk/betterpython/blob/main/6 - template method & bridge/trading-before.py"
    click TM_AFTER "https://github.com/pradyrk/betterpython/blob/main/6 - template method & bridge/trading-after.py"
    click TM_BRIDGE "https://github.com/pradyrk/betterpython/blob/main/6 - template method & bridge/with-bridge.py"
    click EH_BEF_APP "https://github.com/pradyrk/betterpython/blob/main/7 - dealing with errors/before/app.py"
    click EH_BEF_DB "https://github.com/pradyrk/betterpython/blob/main/7 - dealing with errors/before/db.py"
    click EH_AFT_APP "https://github.com/pradyrk/betterpython/blob/main/7 - dealing with errors/after/app.py"
    click EH_AFT_CONTEXT "https://github.com/pradyrk/betterpython/blob/main/7 - dealing with errors/after-context/error-handling-context.py"
    click AD_LOG "https://github.com/pradyrk/betterpython/blob/main/7 - dealing with errors/advanced/logging-decorator.py"
    click AD_RETRY "https://github.com/pradyrk/betterpython/blob/main/7 - dealing with errors/advanced/retry-decorator.py"
    click MON_EX "https://github.com/pradyrk/betterpython/blob/main/7 - dealing with errors/monadic-error-handling/example.py"
```
