# firehead90544/senpy architecture

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

- Interactive diagram: https://gitdiagram.com/firehead90544/senpy
- Repository: https://github.com/firehead90544/senpy

## Overview

##### Project Type and Purpose
- SenPY is a specialized Python-based CLI tool focused on downloading anime episodes. It scrapes data from gogoanime, retrieves direct download links, and then uses aria2 as an external download accelerator.
- The README mentions that it “fakes a browser request” and manages login sessions, then uses the aria2 tool to download episodes. Also, the installation instructions show that it supports creating a standalone executable through PyInstaller.

##### File Structure
- Top-Level Files:
- main.py – Likely the entry point that initializes the application.
- requirements.txt – Lists all the Python dependencies needed.
- LICENSE and README.md – Informative non-code files.
- CURRENT_URL.txt – Possibly used to track the current domain/URL for scraping.
- The senpy directory:
- __init__.py – Marks the folder as a package.
- client.py – Likely handles interaction with the anime sources, manages sessions, or coordinates downloads.
- config.py – Handles reading/updating the configuration (both global and local config.json as mentioned in README).
- errors.py – Contains custom exceptions.
- utils.py – Utility functions supporting core functionality.
- .github/workflows – Contains continuous integration build scripts (e.g., for building or fetching current domain data).

##### Main Components
a. User Interface / Entry Point Component:
- main.py acts as the primary CLI interface.
- It interacts with the user for initial configuration and passes commands.
b. Configuration Management:
- The config.py module manages loading and updating of configuration from the global and local config.json files.
- This component ensures the proper setup of the aria2 path, anime download location, and user credentials.
c. Scraper / Session Manager:
- The client.py (possibly with support from utils.py) manages the session that “fakes a browser request” to gogoanime.
- This includes authenticating the user, fetching cookies, and scraping the anime pages to extract download links.
d. Download Manager / External Integration:
- Integration with the external aria2 tool (as noted in the README and environment setup) that manages high-speed downloads.
- The application passes the final download URLs to aria2 through subprocess calls.
e. Logging and Error Handling:
- errors.py and logging modules ensure that errors are caught and logs are generated for debugging.
f. Continuous Integration and Deployment:
- The .github/workflows (build.yml, fetch_current_domain.yml) indicate that automated testing/build deployment steps are used.

##### Relationships and Interactions
- The user starts the application via main.py, which first checks configuration (config.py) to load necessary credentials and aria2 settings.
- main.py or the client module then initiates a session; client.py uses utilities in utils.py to send requests (via requests and possibly BeautifulSoup from bs4) to gogoanime.
- The scraper component retrieves and parses HTML data, then validates download links through HTTP HEAD requests.
- Retrieved links are then passed to the download manager that interacts with aria2 externally (using subprocess) to download the episodes.
- Throughout this process, logging captures system events and errors are managed via the errors module.

##### Architectural Patterns and Design Principles
- Modular Design – By separating configuration, client/scraping, error handling, and utility functions into different modules, the code adheres to separation of concerns.
- External Process Integration – The design cleanly encapsulates external dependency handling (aria2) via subprocess calls.
- CLI Application Principles – Simple flow where user inputs lead to configuration and then controlling the flow of network requests and downloads.

##### Technologies, Frameworks, and Libraries
- Python as the primary language.
- External tools: aria2 for downloads.
- Libraries such as requests, bs4 (for parsing HTML), colorama, InquirerPy, plyer, and logging.
- CI/CD setup using GitHub Workflows.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["User Interface / CLI Handler (main.py)"]:::cli
    B["Configuration Manager (config.py)"]:::internal
    subgraph "Session and Scraper Engine"
        C["client.py (Session & Scraper Engine)"]:::internal
        D["utils.py (Helper Functions)"]:::internal
    end
    E["Download Manager (aria2 integration)"]:::internal
    F["External Service: gogoanime"]:::external
    G["External Service: aria2"]:::external
    I["Error Handling & Logging (errors.py)"]:::internal
    J["CI/CD Pipeline (.github/workflows)"]:::ci

    A -->|"loadsConfig"| B
    B -->|"initiateSession"| C
    C -->|"utilizes"| D
    C -->|"scrapesData"| F
    C -->|"generatesLinks"| E
    E -->|"triggersDownload"| G
    B -->|"reportsErrors"| I
    C -->|"reportsErrors"| I
    E -->|"reportsErrors"| I
    A -->|"feedback"| I
    J -->|"automatedBuild"| A

    click A "https://github.com/firehead90544/senpy/blob/main/main.py"
    click B "https://github.com/firehead90544/senpy/blob/main/senpy/config.py"
    click C "https://github.com/firehead90544/senpy/blob/main/senpy/client.py"
    click D "https://github.com/firehead90544/senpy/blob/main/senpy/utils.py"
    click I "https://github.com/firehead90544/senpy/blob/main/senpy/errors.py"
    click J "https://github.com/firehead90544/senpy/tree/main/.github/workflows"

    classDef cli fill:#ffd700,stroke:#333,stroke-width:2px
    classDef internal fill:#87cefa,stroke:#333,stroke-width:2px
    classDef external fill:#ffa07a,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
    classDef ci fill:#90ee90,stroke:#333,stroke-width:2px
```
