# bhushan-thinkitive-ac/influx_crud architecture

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

- Interactive diagram: https://gitdiagram.com/bhushan-thinkitive-ac/influx_crud
- Repository: https://github.com/bhushan-thinkitive-ac/influx_crud

## Overview

##### Project Type and Purpose
- This is a lightweight command-line tool (open-source utility) for performing CRUD operations on stock price data in InfluxDB, with built-in logging of each operation to a local file.

##### Main Components
a. CLI Orchestrator (main.py)
- Handles user prompts and dispatches Create, Read, Update, Delete commands.
- Loads environment variables (`URL`, `TOKEN`, `ORG`, `BUCKET`).
b. Data Access Layer (influx_client.py)
- Encapsulates all interactions with the InfluxDB Python client.
- Exposes functions: `create_point()`, `query_data()`, `update_point()`, `delete_data()`.
c. Logging Subsystem (built-in python logging)
- Configured in `main.py` or `influx_client.py` to write to `logs.txt`.
- Records INFO, ERROR messages for every operation.
d. Configuration (.env & environment variables)
- Holds InfluxDB connection details.
e. External Service (InfluxDB)
- The time-series database running at `URL`/`PORT`, storing stock price measurements.
f. Persistence for Logs (`logs.txt`)
- Local file of historical CRUD operation logs.

##### Relationships and Data Flow
- User → CLI Orchestrator (main.py)
- Inputs operation type & parameters
- CLI Orchestrator → Data Access Layer (influx_client.py)
- Calls the appropriate CRUD function
- Data Access Layer ↔ InfluxDB
- Sends/write or query/delete points
- Receives query results or status codes
- CLI Orchestrator/Data Access Layer → Logging Subsystem
- Emits log entries (INFO/ERROR)
- Logging Subsystem → logs.txt
- Appends timestamped entries

##### Architectural Patterns & Design Principles
- Separation of Concerns:
- main.py handles orchestration and user I/O
- influx_client.py handles data persistence logic
- logging is centralized via Python’s logging module
- Single Responsibility: Each module does one thing
- Configuration via Environment Variables: Decouples sensitive settings from code
- Layered Architecture:
1. Presentation (CLI)
2. Domain/Service (CRUD API)
3. Persistence (InfluxDB)
4. Logging (cross-cutting)

[User Terminal]
|
v
[CLI Orchestrator: main.py]
|— loads env vars (.env)
|
v
[Data Access: influx_client.py] ↔ [InfluxDB (External)]
|
v
[Logging Subsystem] → [logs.txt]

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User and Presentation Layer
    UT["User Terminal"]:::app

    %% Configuration and Documentation
    subgraph "Configuration & Docs"
        ENV[".env\n(env vars)"]:::config
        REQ["requirements.txt"]:::file
        DOC["README.md"]:::file
    end

    %% Application Modules
    CLI["CLI Orchestrator\nmain.py"]:::app
    click CLI "https://github.com/bhushan-thinkitive-ac/influx_crud/blob/master/main.py"
    DAL["Data Access Layer\ninflux_client.py"]:::app
    click DAL "https://github.com/bhushan-thinkitive-ac/influx_crud/blob/master/influx_client.py"
    LOGSYS["Logging Subsystem"]:::app

    %% External Services and Persistence
    INXDB["InfluxDB\n(External Service)"]:::external
    LOGFILE["logs.txt"]:::file
    click LOGFILE "https://github.com/bhushan-thinkitive-ac/influx_crud/blob/master/logs.txt"

    %% Flow
    UT -->|"inputs operation & params"| CLI
    CLI -->|"loads env vars"| ENV
    CLI -->|"calls CRUD functions"| DAL
    DAL -->|"write/query/delete point"| INXDB
    INXDB -->|"query results/status"| DAL
    CLI -.->|"log INFO/ERROR"| LOGSYS
    DAL -.->|"log INFO/ERROR"| LOGSYS
    LOGSYS -->|"append entries"| LOGFILE

    %% Legend
    Legend["Legend:\nBlue = App Modules\nGreen = External Services\nOrange = Files\nYellow = Configuration"]:::legend

    %% Styles
    classDef app fill:#D0E8FF,stroke:#004085,color:#000;
    classDef external fill:#D4EDDA,stroke:#155724,color:#000;
    classDef file fill:#FFF3CD,stroke:#856404,color:#000;
    classDef config fill:#FFFAE5,stroke:#B49700,color:#000;
    classDef legend fill:none,stroke:none,color:#000,font-size:12px;
```
