# liliuwei/thinkphp-social architecture

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

- Interactive diagram: https://gitdiagram.com/liliuwei/thinkphp-social
- Repository: https://github.com/liliuwei/thinkphp-social

## Overview

##### Project type and purpose
- This is an open-source ThinkPHP extension (“thinkphp-social”) that provides a unified social-login abstraction for ThinkPHP 5.1/6.0.
- It exports two main services:
- Oauth client manager (`src/Oauth.php`) to handle authorization requests, token exchange, and openid/unionid retrieval.
- User info fetcher (`src/GetInfo.php`) to retrieve a normalized user profile.
- It supports a configurable set of social-network SDK adapters under `src/sdk/` (e.g. QQ, Weixin, Github, Google, etc.).

##### File structure
- Top level: `composer.json`, `README.md`, license, `.gitignore`.
- `src/config/config.php`: default package config stub; populated by publishing `social.php` config.
- Key classes in `src/`
- `Oauth.php` – factory + strategy selection + common methods
- `GetInfo.php` – factory + strategy for user-info retrieval
- `src/sdk/`: one class per provider implementing the same interface(s).
- No database or frontend assets; this is purely a backend library.

##### README for additional insights
- Shows how to register routes in ThinkPHP, call `Oauth::getInstance($type)->getRequestCodeURL()`, then handle callback, fetch access token, fetch user info, and retrieve openid/unionid.
- Emphasizes a plug-and-play set of providers, configured via a single config file.

##### Detail without overthinking
- Them to show dataflow: config → manager → adapter → API → adapter → data back → controller.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Users and Application
    User["User"]:::external
    ThinkApp["ThinkPHP App\nController"]:::thinkphp

    %% Social-Login Extension
    subgraph "Social-Login Extension"
        ConfigModule["Config Module"]:::lib
        OauthManager["Oauth Manager\n(factory + strategy)"]:::lib
        GetInfoService["GetInfo Service\n(profile fetcher)"]:::lib

        subgraph "SDK Adapters" 
            SDKDir["Adapters Directory"]:::sdk
            Baidu["Baidu Adapter"]:::sdk
            Dingtalk["Dingtalk Adapter"]:::sdk
            Douyin["Douyin Adapter"]:::sdk
            Facebook["Facebook Adapter"]:::sdk
            Gitee["Gitee Adapter"]:::sdk
            Github["Github Adapter"]:::sdk
            Google["Google Adapter"]:::sdk
            Oschina["Oschina Adapter"]:::sdk
            QQ["QQ Adapter"]:::sdk
            Sina["Sina Adapter"]:::sdk
            Taobao["Taobao Adapter"]:::sdk
            Weixin["Weixin Adapter"]:::sdk
            Xiaomi["Xiaomi Adapter"]:::sdk
        end
    end

    %% External Social APIs
    subgraph "External Social APIs"
        ExtBaidu["Baidu API"]:::external
        ExtDingtalk["Dingtalk API"]:::external
        ExtDouyin["Douyin API"]:::external
        ExtFacebook["Facebook API"]:::external
        ExtGitee["Gitee API"]:::external
        ExtGithub["Github API"]:::external
        ExtGoogle["Google API"]:::external
        ExtOschina["Oschina API"]:::external
        ExtQQ["QQ API"]:::external
        ExtSina["Sina API"]:::external
        ExtTaobao["Taobao API"]:::external
        ExtWeixin["Weixin API"]:::external
        ExtXiaomi["Xiaomi API"]:::external
    end

    %% Flows
    User -->|"click Login"| ThinkApp
    ThinkApp -->|"calls"| OauthManager
    OauthManager -->|"loads"| ConfigModule
    OauthManager -->|"selects adapter"| SDKDir
    SDKDir --> Baidu
    SDKDir --> Dingtalk
    SDKDir --> Douyin
    SDKDir --> Facebook
    SDKDir --> Gitee
    SDKDir --> Github
    SDKDir --> Google
    SDKDir --> Oschina
    SDKDir --> QQ
    SDKDir --> Sina
    SDKDir --> Taobao
    SDKDir --> Weixin
    SDKDir --> Xiaomi

    OauthManager -->|"auth request"| Baidu
    OauthManager -->|"auth request"| Dingtalk
    OauthManager -->|"auth request"| Douyin
    OauthManager -->|"auth request"| Facebook
    OauthManager -->|"auth request"| Gitee
    OauthManager -->|"auth request"| Github
    OauthManager -->|"auth request"| Google
    OauthManager -->|"auth request"| Oschina
    OauthManager -->|"auth request"| QQ
    OauthManager -->|"auth request"| Sina
    OauthManager -->|"auth request"| Taobao
    OauthManager -->|"auth request"| Weixin
    OauthManager -->|"auth request"| Xiaomi

    Baidu -->|redirect| ExtBaidu
    Dingtalk -->|redirect| ExtDingtalk
    Douyin -->|redirect| ExtDouyin
    Facebook -->|redirect| ExtFacebook
    Gitee -->|redirect| ExtGitee
    Github -->|redirect| ExtGithub
    Google -->|redirect| ExtGoogle
    Oschina -->|redirect| ExtOschina
    QQ -->|redirect| ExtQQ
    Sina -->|redirect| ExtSina
    Taobao -->|redirect| ExtTaobao
    Weixin -->|redirect| ExtWeixin
    Xiaomi -->|redirect| ExtXiaomi

    ExtBaidu -->|callback| OauthManager
    ExtDingtalk -->|callback| OauthManager
    ExtDouyin -->|callback| OauthManager
    ExtFacebook -->|callback| OauthManager
    ExtGitee -->|callback| OauthManager
    ExtGithub -->|callback| OauthManager
    ExtGoogle -->|callback| OauthManager
    ExtOschina -->|callback| OauthManager
    ExtQQ -->|callback| OauthManager
    ExtSina -->|callback| OauthManager
    ExtTaobao -->|callback| OauthManager
    ExtWeixin -->|callback| OauthManager
    ExtXiaomi -->|callback| OauthManager

    ThinkApp -->|"requests user info"| GetInfoService
    GetInfoService -->|"uses adapter"| SDKDir
    GetInfoService -->|"fetch profile"| Baidu
    GetInfoService -->|"fetch profile"| Dingtalk
    GetInfoService -->|"fetch profile"| Douyin
    GetInfoService -->|"fetch profile"| Facebook
    GetInfoService -->|"fetch profile"| Gitee
    GetInfoService -->|"fetch profile"| Github
    GetInfoService -->|"fetch profile"| Google
    GetInfoService -->|"fetch profile"| Oschina
    GetInfoService -->|"fetch profile"| QQ
    GetInfoService -->|"fetch profile"| Sina
    GetInfoService -->|"fetch profile"| Taobao
    GetInfoService -->|"fetch profile"| Weixin
    GetInfoService -->|"fetch profile"| Xiaomi

    %% Click Events
    click ConfigModule "https://github.com/liliuwei/thinkphp-social/blob/master/src/config/config.php"
    click OauthManager "https://github.com/liliuwei/thinkphp-social/blob/master/src/Oauth.php"
    click GetInfoService "https://github.com/liliuwei/thinkphp-social/blob/master/src/GetInfo.php"
    click SDKDir "https://github.com/liliuwei/thinkphp-social/tree/master/src/sdk/"
    click Baidu "https://github.com/liliuwei/thinkphp-social/blob/master/src/sdk/Baidu.php"
    click Dingtalk "https://github.com/liliuwei/thinkphp-social/blob/master/src/sdk/Dingtalk.php"
    click Douyin "https://github.com/liliuwei/thinkphp-social/blob/master/src/sdk/Douyin.php"
    click Facebook "https://github.com/liliuwei/thinkphp-social/blob/master/src/sdk/Facebook.php"
    click Gitee "https://github.com/liliuwei/thinkphp-social/blob/master/src/sdk/Gitee.php"
    click Github "https://github.com/liliuwei/thinkphp-social/blob/master/src/sdk/Github.php"
    click Google "https://github.com/liliuwei/thinkphp-social/blob/master/src/sdk/Google.php"
    click Oschina "https://github.com/liliuwei/thinkphp-social/blob/master/src/sdk/Oschina.php"
    click QQ "https://github.com/liliuwei/thinkphp-social/blob/master/src/sdk/Qq.php"
    click Sina "https://github.com/liliuwei/thinkphp-social/blob/master/src/sdk/Sina.php"
    click Taobao "https://github.com/liliuwei/thinkphp-social/blob/master/src/sdk/Taobao.php"
    click Weixin "https://github.com/liliuwei/thinkphp-social/blob/master/src/sdk/Weixin.php"
    click Xiaomi "https://github.com/liliuwei/thinkphp-social/blob/master/src/sdk/Xiaomi.php"

    %% Styles
    classDef thinkphp fill:#E8F0FE,stroke:#1A73E8,color:#1A73E8;
    classDef lib fill:#E6F4EA,stroke:#34A853,color:#34A853;
    classDef sdk fill:#FFF4E5,stroke:#FBBC04,color:#FBBC04;
    classDef external fill:#FCE8E6,stroke:#EA4335,color:#EA4335;
```
