# biliticket/transition-ticket architecture

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

- Interactive diagram: https://gitdiagram.com/biliticket/transition-ticket
- Repository: https://github.com/biliticket/transition-ticket

## Overview

##### Project type and purpose
- This is a Python-based command-line ticket-sniping tool (“Transition Ticket”) designed to automate the process of grabbing “back-in-stock” tickets from Bilibili.
- It exposes a CLI interface (cli.py) that orchestrates a finite-state machine (FSM) workflow, handles login, task scheduling, captcha solving (Geetest), ticket querying, and user notification (audio/console).

##### File structure
- Top-level entrypoint:
- cli.py – the main CLI launcher and FSM driver
- cli.spec – PyInstaller packaging script
- “geetest” directory: static web assets (HTML/CSS/JS) used to render and solve Geetest captchas in a headless browser (Edge).
- interface/CLI: argument parsing and subcommands (user, setting, product).
- util/*: core business modules, each encapsulating a domain concern:
- Config – load/save user settings
- Login – Bilibili session management
- Captcha – integrate WebView + geetest assets
- Request – HTTP client wrappers
- Task – scheduling retry loops, polling
- Data, Info, Notice – data models, console output and sound alerts
- Bilibili – wrapper around Bilibili endpoints
- assets/alarm.wav: final notification audio
- Requirements and packaging: pyproject.toml, requirements.txt, flake.nix, pre-commit, CI workflows.

##### README for additional insights
- Describes an FSM-driven flow (assets/fsm.png) from “login → captcha → ticket query → notify.”
- Notes external dependencies: PortAudio (for playback), Edge browser (for captcha), Python 3.10–3.13.
- Packaging steps with PyInstaller reflect deployment concerns.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        CLI["CLI (cli.py)"]:::presentation
        Subcmd["CLI Subcommands"]:::presentation
        FSM["FSM Orchestrator"]:::presentation
    end

    %% Core Domain Layer
    subgraph "Core Domain Layer"
        Login["Login Module"]:::core
        Captcha["Captcha Module"]:::core
        Request["HTTP Client Wrapper"]:::core
        Task["Task Scheduler"]:::core
        Config["Config Management"]:::core
        Data["Data Models"]:::core
        Info["Console Output & Sound Alert"]:::core
        Bili["Bilibili API Wrapper"]:::core
    end

    %% External Services
    subgraph "External Services"
        BiliAPI["Bilibili HTTP API"]:::external
        Geetest["Geetest Captcha Service"]:::external
    end

    %% Local Resources
    subgraph "Local Resources"
        GeetestAssets["Geetest Assets (HTML/CSS/JS)"]:::resource
        Audio["Alarm Audio"]:::resource
        ConfigFiles["Config & Cache Files"]:::resource
    end

    %% Packaging / Build
    subgraph "Packaging & Deployment"
        Spec["PyInstaller Script"]:::packaging
        Dependencies["Dependencies & Build Config"]:::packaging
        Executable["Packaged Executable"]:::packaging
    end

    %% Relationships
    Subcmd -->|"invokes"| CLI
    CLI -->|"drives"| FSM

    FSM -->|"calls"| Login
    FSM -->|"calls"| Captcha
    FSM -->|"calls"| Task

    Login -->|"uses"| Request
    Captcha -->|"uses"| Request
    Task -->|"uses"| Request
    Task -->|"queries"| Bili
    Task -->|"stores/fetches"| Data
    Task -->|"reads/writes"| Config
    Data -->|"persistent storage"| ConfigFiles
    Info -->|"reads data"| Data

    Captcha -->|"loads assets"| GeetestAssets
    Captcha -->|"requests token from"| Geetest
    Bili -->|"calls"| BiliAPI

    Info -->|"plays audio"| Audio

    CLI -->|"packaged by"| Spec
    Dependencies -->|"configured in"| Spec
    Spec -->|"produces"| Executable
    Dependencies -->|"required for"| Executable

    %% Click Events
    click CLI "https://github.com/biliticket/transition-ticket/blob/dev/cli.py"
    click Spec "https://github.com/biliticket/transition-ticket/blob/dev/cli.spec"
    click Subcmd "https://github.com/biliticket/transition-ticket/tree/dev/interface/CLI/"
    click GeetestAssets "https://github.com/biliticket/transition-ticket/tree/dev/geetest/"
    click Audio "https://github.com/biliticket/transition-ticket/blob/dev/assets/alarm.wav"
    click Bili "https://github.com/biliticket/transition-ticket/tree/dev/util/Bilibili/"
    click Captcha "https://github.com/biliticket/transition-ticket/tree/dev/util/Captcha/"
    click Config "https://github.com/biliticket/transition-ticket/tree/dev/util/Config/"
    click Data "https://github.com/biliticket/transition-ticket/tree/dev/util/Data/"
    click Info "https://github.com/biliticket/transition-ticket/tree/dev/util/Info/"
    click Login "https://github.com/biliticket/transition-ticket/tree/dev/util/Login/"
    click Request "https://github.com/biliticket/transition-ticket/tree/dev/util/Request/"
    click Task "https://github.com/biliticket/transition-ticket/tree/dev/util/Task/"
    click Dependencies "https://github.com/biliticket/transition-ticket/blob/dev/pyproject.toml"

    %% Styles
    classDef presentation fill:#AED6F1,stroke:#3498DB
    classDef core fill:#ABEBC6,stroke:#27AE60
    classDef external fill:#FAD7A0,stroke:#D68910
    classDef resource fill:#D5D8DC,stroke:#566573
    classDef packaging fill:#E8DAEF,stroke:#8E44AD
```
