How ankurgajurel/nepse-cli works
Project Type and Purpose
• The project is a CLI tool that provides real-time data and analytics (like index values, company profiles, price details, top movers, etc.) for the NEPSE (Nepal Stock Exchange) market.
• It also has an additional RESTful API implemented using Flask, allowing users to query company names and scrip data through HTTP endpoints.
• A Dockerfile is present for containerization, and several dependency files (requirements.txt and req.py) manage the environment setup. Unit tests are included via test_all_data.py.
File Structure
• Top-level files include .gitignore, Dockerfile, README.md (and README_OLD.md), and main Python scripts (nepse.py, req.py, requirements.txt). This indicates primary entry points and environment configuration.
• The “api” directory holds the API implementation files (nepse_api.py for running the Flask service and all_data.py for data handling) along with its own requirements.txt file. This separation shows a distinct module for serving HTTP requests.
• A test file (test_all_data.py) is available to validate at least part of the project’s functionality.
• The file organization suggests a layered architecture where the CLI component and API component are separate but share underlying data retrieval logic.
README for Additional Insights
• The README clearly documents command-line usage including various commands (nepse, all-scrips, company-profile, price, news, top, index) along with their options and parameters.
• Instructions for running the Flask API (located in the “api” folder) are well-detailed, showing endpoints such as /companies and /scrip/<scrip_name>.
• Dependency installation is handled either manually via pip or automatically by running the req.py script.
a. Main Components:
• CLI Component: Represented by nepse.py—the central entry point for invoking commands.
• Command Modules / Data Retrieval: Code segments handling different functionalities (e.g., all_data.py, functions within nepse.py).
• Flask API Component: Runs independently on port 3322 (as defined in nepse_api.py) that exposes HTTP endpoints like /companies and /scrip/<scrip_name>.
• Dependency Management: req.py and requirements.txt files ensure that both CLI and API have the necessary dependencies.
• Testing Component: Test suites such as test_all_data.py ensure quality and correctness.
• Deployment/Containerization: Dockerfile indicates that the project can be containerized.
b. Relationships and Interactions:
• User Input flows into the CLI Component (through commands like “python3 nepse.py …”). Depending on the command, this component calls internal functions (possibly defined in modules like all_data.py) to access and process NEPSE data.
• When running the Flask API, the system starts the API component which listens on a specified port, processing HTTP requests and returning JSON or formatted responses.
• Both CLI and API components share underlying data-fetching and data processing logic to ensure consistency.
• The dependency installation process (via req.py or pip install commands) is a preparatory step that supports both CLI and API execution.
c. Architectural Patterns & Design Principles:
• Modular Design: Use distinct modules for different tasks (data fetching, processing, CLI parsing, API serving).
• Extensibility: The project design allows for adding extra endpoints to the API or additional CLI commands with minimal friction.
d. Relevant Technologies and Frameworks:
• Python (core language)
• Flask (for the API)
• Docker (as indicated by the Dockerfile for containerized deployment)
• Pip (for dependency management, as seen in requirements.txt and req.py)
• Testing Frameworks (used in test_all_data.py)
• Incorporate Notes on Interactions: Explain that the CLI and API share common data retrieval mechanisms and that the Dockerfile encapsulates the entire runtime environment ensuring consistency across deployments.