# wikiar/newapi architecture

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

- Interactive diagram: https://gitdiagram.com/wikiar/newapi
- Repository: https://github.com/wikiar/newapi

## Overview

##### Main Components
- API Client/Wrapper Interface: This is the high-level module (exposed by the “newapi” calls shown in the README) that provides the public methods, e.g., Login, MainPage, CatDepth, and NEW_API.
- Login Module: Represented by components such as “super_login.py” and the sub-packages under “super/login_bots”. This part is responsible for authentication, managing cookies, sessions, and using the MediaWiki client (mwclient).
- Page Operations Module: Including components such as “page.py”, “wiki_page.py”, “mdwiki_page.py”, “ncc_page.py”, and sub-components in “super/page_bots”. This module handles page existence checks, text retrieval, editing, template processing, and various page queries.
- Bot Functionality Modules: These include “botEdit.py”, “db_bot.py”, “pymysql_bot.py”, the “botapi_bots” under “super”, and the “login_bots” and “page_bots” folders. They encapsulate automation routines and error-handling for specific automated tasks.
- Utility and Helper Functions: Modules like “except_err.py”, “pformat.py”, “printe.py”, “txtlib.py”, and “wd_sparql.py” that support logging, error handling, text formatting, or interfacing with databases.
- Automated Documentation & Continuous Integration: As indicated by the “.github” folder and workflows (e.g., “snorkell-auto-documentation.yml”), include a note about how deployment/CI aspects are handled, even if they are not core to the API’s functionality.

##### Establish Relationships and Data Flow
- The API Client acts as the gateway, with methods that internally route calls to either the login or page operations modules.
- The Login Module communicates with both Wikimedia’s API and some internal session/token management utilities.
- The Page Operations Module also may query additional services (or use common utilities) to process and handle page data, and might depend on bot modules when automating edits or retrieval.
- Utility components are shared between these major sections, ensuring that common logic (like error handling and formatting) is centralized.

##### Architectural Patterns & Design Principles
- Modular Design: The project is cleanly split into modules that correspond to specific functionality (login, page edits, bots, etc.). This separation of concerns should be evident.
- Layered Structure: Indicate a high-level presentation/API layer, a business logic layer (handling login and page operations), and utility/support layers.
- Error Handling & Abstraction: Several modules (e.g., “except_err.py”, “ar_err.py” in sub-folders) indicate robust error handling, which is a key design principle in this project.

##### Additional Advice for the Principal Software Engineer
- Annotations or legends that explain key relationships, such as “calls”, “depends on”, or “provides data to”.
- A separate section/note for CI/CD workflows (depicting the .github workflows) that, although not core to runtime architecture, are integral for project sustainability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    APIClient["API Client/Wrapper Interface"]:::api
    subgraph "Business Logic Layer"
        LoginModule["Login Module"]:::login
        PageOps["Page Operations Module"]:::page
        BotModules["Bot Functionality Module"]:::bot
    end
    Utilities["Utilities/Helpers"]:::util
    External["Wikimedia API"]:::external
    CICD["CI/CD Workflows"]:::cicd

    %% Data Flow Connections
    APIClient -->|"calls"| LoginModule
    APIClient -->|"calls"| PageOps
    LoginModule -->|"authenticates"| External
    PageOps -->|"queries"| External
    LoginModule -->|"triggers"| BotModules
    PageOps -->|"initiates"| BotModules
    Utilities -->|"supports"| LoginModule
    Utilities -->|"supports"| PageOps
    Utilities -->|"supports"| BotModules
    CICD -.-|"deploys"| APIClient

    %% Click Events for API Client/Wrapper Interface
    click APIClient "https://github.com/wikiar/newapi/blob/main/README.md"
    click APIClient "https://github.com/wikiar/newapi/blob/main/ __init__.py"

    %% Click Events for Login Module
    click LoginModule "https://github.com/wikiar/newapi/blob/main/super/super_login.py"
    click LoginModule "https://github.com/wikiar/newapi/tree/main/super/login_bots/"

    %% Click Events for Page Operations Module
    click PageOps "https://github.com/wikiar/newapi/blob/main/page.py"
    click PageOps "https://github.com/wikiar/newapi/blob/main/wiki_page.py"
    click PageOps "https://github.com/wikiar/newapi/blob/main/mdwiki_page.py"
    click PageOps "https://github.com/wikiar/newapi/blob/main/ncc_page.py"
    click PageOps "https://github.com/wikiar/newapi/tree/main/super/page_bots/"

    %% Click Events for Bot Functionality Modules
    click BotModules "https://github.com/wikiar/newapi/blob/main/botEdit.py"
    click BotModules "https://github.com/wikiar/newapi/blob/main/db_bot.py"
    click BotModules "https://github.com/wikiar/newapi/blob/main/pymysql_bot.py"
    click BotModules "https://github.com/wikiar/newapi/tree/main/super/botapi_bots/"
    click BotModules "https://github.com/wikiar/newapi/tree/main/super/bots/"

    %% Click Events for Utility and Helper Functions
    click Utilities "https://github.com/wikiar/newapi/blob/main/except_err.py"
    click Utilities "https://github.com/wikiar/newapi/blob/main/pformat.py"
    click Utilities "https://github.com/wikiar/newapi/blob/main/printe.py"
    click Utilities "https://github.com/wikiar/newapi/blob/main/txtlib.py"
    click Utilities "https://github.com/wikiar/newapi/blob/main/wd_sparql.py"

    %% Click Event for CI/CD Workflows
    click CICD "https://github.com/wikiar/newapi/tree/main/.github/"

    %% Styles
    classDef api fill:#a2d2ff,stroke:#000,stroke-width:1px;
    classDef login fill:#ffadad,stroke:#000,stroke-width:1px;
    classDef page fill:#ffd6a5,stroke:#000,stroke-width:1px;
    classDef bot fill:#fdffb6,stroke:#000,stroke-width:1px;
    classDef util fill:#caffbf,stroke:#000,stroke-width:1px;
    classDef cicd fill:#9bf6ff,stroke:#000,stroke-width:1px;
    classDef external fill:#ffccff,stroke:#000,stroke-width:1px;
```
