# betzamica/lib_bi architecture

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

- Interactive diagram: https://gitdiagram.com/betzamica/lib_bi
- Repository: https://github.com/betzamica/lib_bi

## Overview

##### Project type and purpose
- From the file tree and absence of a detailed README, we see this is a Python library (“lib_bi”) designed to provide a unified set of “handlers” for Business‐Intelligence–related operations: interacting with BigQuery, email, local files, FTP/SFTP, Google Sheets, and data replication tasks.
- It is not a full‐stack app but an integration/ETL toolkit intended to be imported into customer scripts or pipelines.

##### File structure
- Top‐level:
- .gitignore, .python-version, pyproject.toml, requirements.txt → standard Python project configuration
- src/lib_bi → single package containing all handler modules
- Inside lib_bi:
- bq_handler.py
- email_sender.py
- file_handler.py
- ftp_handler.py
- stfp_handler.py (SFTP)
- sheet_handler.py
- replica_handler.py
- py.typed → indicates type‐hint support
- No database or web server code; each module is a connector to an external service.

##### Key architectural insights
- Modular pattern: each handler encapsulates one external service or functionality
- Single‐package library with clear separation of concerns
- Designed for dependency injection into a higher‐level orchestration or pipeline (e.g., Airflow, Prefect, custom scripts)

a. Main components:
- lib_bi Package (central)
– BQHandler
– EmailSender
– FileHandler
– FTPHandler
– SFTPHandler
– SheetHandler
– ReplicaHandler
- External Services:
– Google BigQuery
– SMTP/IMAP or SendGrid (Email)
– Local/File System
– FTP Server
– SFTP Server
– Google Sheets API
– (Optionally) Upstream Data Sources or Downstream Consumers
b. Relationships and interactions:
- From each handler → corresponding external service.
- ReplicaHandler may orchestrate multiple handlers (e.g., pull from BigQuery → write to file → push via FTP).
c. Architectural patterns & principles:
- Separation of Concerns: one module per service
- Dependency Injection: callers supply credentials/config to handlers
- Adapter/Facade pattern: each handler adapts an external API into a uniform interface
d. Technologies & frameworks:
- Python 3.x
- Google Cloud BigQuery client library
- smtplib or transactional email API
- ftplib / paramiko
- google‐api‐python‐client for Sheets
- Standard pathlib / file I/O

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Orchestrator
    EO["ETL Orchestrator"]:::orchestrator

    %% lib_bi Package
    subgraph "lib_bi Package"
        direction TB
        BQ["BQHandler"]:::internal
        ES["EmailSender"]:::email
        FH["FileHandler"]:::internal
        FTPH["FTPHandler"]:::internal
        SFTPH["SFTPHandler"]:::internal
        SH["SheetHandler"]:::internal
        RH["ReplicaHandler"]:::internal
        TYP["py.typed"]:::typed
        INIT["__init__.py"]:::internal
    end

    %% External Services
    GBQ["Google BigQuery"]:::data
    EMAIL["Email Service (SMTP/API)"]:::email
    LOCAL["Local File System"]:::external
    FTPS["FTP Server"]:::external
    SFTPS["SFTP Server"]:::external
    SHEETS["Google Sheets API"]:::data

    %% Connections from Orchestrator to handlers
    EO --> BQ
    EO --> ES
    EO --> FH
    EO --> FTPH
    EO --> SFTPH
    EO --> SH
    EO --> RH

    %% Handler to Service connections
    BQ -->|"REST/Client"| GBQ
    ES -->|"SMTP/API"| EMAIL
    FH -->|"Filesystem I/O"| LOCAL
    FTPH -->|"FTP"| FTPS
    SFTPH -->|"SFTP"| SFTPS
    SH -->|"REST/API"| SHEETS

    %% Replica orchestration
    RH --> BQ
    RH --> FH
    RH --> FTPH

    %% Click Events
    click BQ "https://github.com/betzamica/lib_bi/blob/main/src/lib_bi/bq_handler.py"
    click ES "https://github.com/betzamica/lib_bi/blob/main/src/lib_bi/email_sender.py"
    click FH "https://github.com/betzamica/lib_bi/blob/main/src/lib_bi/file_handler.py"
    click FTPH "https://github.com/betzamica/lib_bi/blob/main/src/lib_bi/ftp_handler.py"
    click SFTPH "https://github.com/betzamica/lib_bi/blob/main/src/lib_bi/stfp_handler.py"
    click SH "https://github.com/betzamica/lib_bi/blob/main/src/lib_bi/sheet_handler.py"
    click RH "https://github.com/betzamica/lib_bi/blob/main/src/lib_bi/replica_handler.py"
    click TYP "https://github.com/betzamica/lib_bi/blob/main/src/lib_bi/py.typed"
    click INIT "https://github.com/betzamica/lib_bi/blob/main/src/lib_bi/__init__.py"
    click EO "https://github.com/betzamica/lib_bi/tree/main/src/lib_bi/"

    %% Styles
    classDef internal fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef external fill:#F2F2F2,stroke:#888888,color:#333333;
    classDef data fill:#E6FFEA,stroke:#2C662D,color:#2C662D;
    classDef email fill:#FFF5CC,stroke:#CCA700,color:#805700;
    classDef orchestrator fill:#FFE0E6,stroke:#D62739,color:#D62739;
    classDef typed fill:#EDEDED,stroke:#BBBBBB,color:#555555;
```
