# ankurgajurel/nepse-cli architecture

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

- Interactive diagram: https://gitdiagram.com/ankurgajurel/nepse-cli
- Repository: https://github.com/ankurgajurel/nepse-cli

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    U["User/Client"]:::user

    subgraph "Interface Layer"
        CLI["CLI (nepse.py)"]:::cli
        API["Flask API (nepse_api.py)"]:::api
    end

    U -->|"CLIcommands"| CLI
    U -->|"HTTPrequests"| API

    subgraph "Core Processing"
        Shared["Data Retrieval (all_data.py)"]:::shared
    end

    CLI -->|"calls"| Shared
    API -->|"queries"| Shared

    subgraph "Support"
        Req["Dependency (req.py)"]:::dep
        ReqFile["Dependency (requirements.txt)"]:::dep
        APIReq["API Dependency (api/requirements.txt)"]:::dep
        Test["Testing (test_all_data.py)"]:::test
    end

    Req --- CLI
    ReqFile --- CLI
    APIReq --- API
    Test --- Shared

    Docker["Docker Container (Dockerfile)"]:::docker

    CLI ---|"packaged"| Docker
    API ---|"packaged"| Docker
    Shared ---|"packaged"| Docker
    Req ---|"packaged"| Docker
    ReqFile ---|"packaged"| Docker
    APIReq ---|"packaged"| Docker
    Test ---|"verified"| Docker

    click CLI "https://github.com/ankurgajurel/nepse-cli/blob/main/nepse.py"
    click API "https://github.com/ankurgajurel/nepse-cli/blob/main/api/nepse_api.py"
    click Shared "https://github.com/ankurgajurel/nepse-cli/blob/main/api/all_data.py"
    click Req "https://github.com/ankurgajurel/nepse-cli/blob/main/req.py"
    click ReqFile "https://github.com/ankurgajurel/nepse-cli/blob/main/requirements.txt"
    click APIReq "https://github.com/ankurgajurel/nepse-cli/blob/main/api/requirements.txt"
    click Test "https://github.com/ankurgajurel/nepse-cli/blob/main/test_all_data.py"
    click Docker "https://github.com/ankurgajurel/nepse-cli/tree/main/Dockerfile"

    classDef user fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef cli fill:#ADD8E6,stroke:#00008B,stroke-width:1px;
    classDef api fill:#90EE90,stroke:#006400,stroke-width:1px;
    classDef shared fill:#FFB6C1,stroke:#8B0000,stroke-width:1px;
    classDef dep fill:#E0FFFF,stroke:#4682B4,stroke-width:1px;
    classDef test fill:#FFFACD,stroke:#BDB76B,stroke-width:1px;
    classDef docker fill:#D3D3D3,stroke:#696969,stroke-width:1px,stroke-dasharray: 5 5;
```
