# jason9294/nyust-sso-client architecture

> Architecture diagram of the GitHub repository jason9294/nyust-sso-client, 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/jason9294/nyust-sso-client
- Repository: https://github.com/jason9294/nyust-sso-client

## Overview

##### Main Components
- NYUST SSO Client: This is the core component (located in nyust_sso/client.py) that exposes methods like fetch_captcha(), login(), and fetch_my_courses(). It encapsulates the overall API used by client applications.
- HTTP/Network Layer: Found in nyust_sso/http.py, this handles all the networking interactions with the NYUST SSO system (e.g., establishing connections, sending HTTP requests).
- Error Handling: The nyust_sso/errors.py module centrally manages errors, which is important for depicting resilience and exception pathways.
- Domain/Class Entities: The “tronclass” sub-package (under nyust_sso/tronclass) is responsible for modeling domain-specific entities (like course, activity, and base entities). These classes represent the data retrieved after logging in.
- Utility Functions: Both nyust_sso/utils.py and nyust_sso/tronclass/utils.py encapsulate shared functionality that supports the main operations.
- Example Scripts: Located in the “example” directory, these show how to integrate with third-party libraries (like ddddocr for captcha recognition) and how to use the client.

##### Component Relationships and Data Flow
- The user (or an external application) calls the NYUSTSSOClient interface.
- The client first interacts with the HTTP module to fetch the captcha image (fetch_captcha()).
- An external OCR module (e.g., ddddocr) is then used to interpret the captcha image. (This dependency should be noted as an optional integration point.)
- Once the user provides credentials (username, password) along with the captcha text (with appropriate formatting, such as converting to lower-case), the client sends the login request via the HTTP layer.
- Upon successful login, the client fetches course data (e.g., fetch_my_courses()). The data returned might be mapped into domain entities defined in the tronclass package.
- Errors and exceptional cases are managed via the error-handling module.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Source
    A["User/External Application"]:::external

    %% Core Components
    B["NYUST SSO Client (API)"]:::api
    C["HTTP/Network Module"]:::network
    D["Error Handling Module"]:::error
    E["Utils (Core)"]:::util
    F["Utils (Tronclass)"]:::util

    %% Domain Models
    G["Domain Models (tronclass)"]:::domain
    H["Domain Entities"]:::domain

    %% External Dependencies
    I["External OCR (ddddocr)"]:::external
    J["NYUST SSO Server"]:::external

    %% Example Integrations
    K["Example Integration Scripts"]:::example
    K1["complete_all_coursewares.py"]:::example
    K2["login_and_fetch_course_info.py"]:::example

    %% Data Flow Connections (vertical layout)
    A -->|"calls"| B
    B -->|"fetchCaptcha/login"| C
    C -->|"response"| B
    C -->|"errors"| D
    B -->|"uses"| E
    B -->|"uses"| F
    C -->|"communicates"| J
    C -->|"parses data"| G
    G -->|"models"| H
    B -->|"integrates with"| I

    %% Example Integration Flow
    A -->|"demo usage"| K
    K -->|"example script"| K1
    K -->|"example script"| K2

    %% Click Events
    click B "https://github.com/jason9294/nyust-sso-client/blob/main/nyust_sso/client.py"
    click C "https://github.com/jason9294/nyust-sso-client/blob/main/nyust_sso/http.py"
    click D "https://github.com/jason9294/nyust-sso-client/blob/main/nyust_sso/errors.py"
    click G "https://github.com/jason9294/nyust-sso-client/tree/main/nyust_sso/tronclass"
    click H "https://github.com/jason9294/nyust-sso-client/tree/main/nyust_sso/tronclass/entity"
    click E "https://github.com/jason9294/nyust-sso-client/blob/main/nyust_sso/utils.py"
    click F "https://github.com/jason9294/nyust-sso-client/blob/main/nyust_sso/tronclass/utils.py"
    click K "https://github.com/jason9294/nyust-sso-client/tree/main/example"
    click K1 "https://github.com/jason9294/nyust-sso-client/blob/main/example/complete_all_coursewares.py"
    click K2 "https://github.com/jason9294/nyust-sso-client/blob/main/example/login_and_fetch_course_info.py"

    %% Styles
    classDef api fill:#bbf,stroke:#333,stroke-width:2px;
    classDef network fill:#ccf,stroke:#333,stroke-width:2px;
    classDef error fill:#f88,stroke:#333,stroke-width:2px;
    classDef util fill:#afa,stroke:#333,stroke-width:2px;
    classDef domain fill:#fed,stroke:#333,stroke-width:2px;
    classDef external fill:#ddd,stroke:#333,stroke-width:2px;
    classDef example fill:#ffd,stroke:#333,stroke-width:2px;
```
