How bhushan-thinkitive-ac/influx_crud works
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]