# basic-bgnr/nepseunofficialapi architecture

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

- Interactive diagram: https://gitdiagram.com/basic-bgnr/nepseunofficialapi
- Repository: https://github.com/basic-bgnr/nepseunofficialapi

## Overview

##### Main Components
- Library Core: Represent the main package (the “nepse” directory) which contains modules such as NepseLib.py, DummyIDUtils.py, Errors.py, and TokenUtils.py. This is where all the core functionality (API calls, data processing, authentication key deciphering) is implemented.
- CLI Tool: Add a component labeled “nepse-cli” — show that this is a wrapper around the library’s core features, exposing commands to download floor sheets or start a local server.
- Example Server: Include a node for the “example/NepseServer.py” which shows how the library can be integrated into a web server (e.g., a Flask application running on localhost:8000).

##### Relationships and Interactions
- That data (like API endpoints and header configurations) feeds from the “data” component into the library core modules to support the API calls.

##### Architectural Patterns and Design Principles
- Modularity: Emphasize that the package is modular with separate files handling distinct responsibilities (authentication, error reporting, and token management) which is key for maintainability.
- Synchronous/Asynchronous Separation: Clearly show the dual nature of the API access. This separation is fundamental to the design, ensuring users can choose between blocking and non-blocking API calls.
- Externalized Configurations: Call out that the design uses JSON configuration files (from the data folder) which improves flexibility and ease of updates without changing code.
- CLI Layer: Highlight that the CLI tool acts as an adapter over the core library functionality to provide user-friendly interaction from the command line.

##### Technologies and Frameworks
- Python 3.11 (as required by the project)
- HTTP clients (likely httpx instead of requests, per the README’s mention of speed improvements and HTTP2 usage)
- Flask (for the example server in the example folder)
- WebAssembly (css.wasm may be involved in authentication or some specialized processing)
- GitHub Actions: You might optionally note the CI/CD workflows from the .github folder which indicate automated testing and deployment processes.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Interfaces
    subgraph "Client Interfaces"
        CLI("CLI Tool (nepse-cli)"):::client
        FLASK("Example Flask Server"):::client
    end

    %% Library Core and API Types
    subgraph "Library Core"
        CORE("Nepse Core Module"):::core
        SYNC("Synchronous API (Nepse)"):::core
        ASYNC("Asynchronous API (AsyncNepse)"):::core
    end

    %% Data & Configuration
    subgraph "Data & Config"
        CONFIG("Data & Config (JSON Files)"):::data
    end

    %% External Service
    EXTERNAL("Nepalstock API (External)"):::external

    %% Relationships
    CLI -->|"CLICommands"| CORE
    FLASK -->|"APICalls"| CORE

    CORE -->|"uses"| SYNC
    CORE -->|"uses"| ASYNC

    CONFIG -->|"ProvidesConfig"| CORE

    CORE -->|"HTTPSHTTP2"| EXTERNAL
    EXTERNAL -->|"JSONResponse"| CORE

    %% Click Events
    click CORE "https://github.com/basic-bgnr/nepseunofficialapi/tree/master/nepse/"
    click CONFIG "https://github.com/basic-bgnr/nepseunofficialapi/tree/master/nepse/data/"
    click SYNC "https://github.com/basic-bgnr/nepseunofficialapi/blob/master/nepse/NepseLib.py"
    click ASYNC "https://github.com/basic-bgnr/nepseunofficialapi/blob/master/nepse/NepseLib.py"
    click CLI "https://github.com/basic-bgnr/nepseunofficialapi/blob/master/nepse/__main__.py"
    click FLASK "https://github.com/basic-bgnr/nepseunofficialapi/blob/master/example/NepseServer.py"

    %% Styles
    classDef client fill:#B3E5FC,stroke:#0277BD,stroke-width:2px;
    classDef core fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef data fill:#FFECB3,stroke:#F57F17,stroke-width:2px;
    classDef external fill:#F8BBD0,stroke:#C2185B,stroke-width:2px;
```
