# straymeteor3337/wechatrealfriends architecture

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

- Interactive diagram: https://gitdiagram.com/straymeteor3337/wechatrealfriends
- Repository: https://github.com/straymeteor3337/wechatrealfriends

## Overview

##### Project type and purpose
- This is a desktop/CLI tool with an embedded web-UI, written in Rust for the backend engine and using a small Node/JS-based front end for user interaction.
- Purpose: connect to the WeChat iPad protocol, detect one-way friend relationships, tag and export results for cleanup.

##### File structure
- Top level:
- Cargo.toml, src/main.rs → Rust backend (binary).
- web/ → front-end assets and code.
- web/ contains:
- package.json → Node tooling for bundling the front-end.
- index.html, main.html + JS/CSS assets → two entry points (login vs. main UI).
- WechatAPI.js → JavaScript wrapper for backend API calls.
- layui/ → UI component library.
- No separate database directories—data is held in memory or local files by the Rust service.
- No microservices; it’s a single Rust server that also serves static files and API.

##### README for technical stack and architecture notes
- Backend: Rust, using compiled iPad-protocol binary.
- Frontend: plain JS/CSS/HTML with layui.
- Communication: HTTP (or WebSocket) APIs between front-end and backend.
- External dependency: official WeChat iPad protocol server endpoints.

##### Main components and interactions (
a. Frontend (Browser)
- index.html/main.html, index.js/main.js, CSS, layui components.
- WechatAPI.js defines AJAX/WebSocket calls.
b. Backend (Rust Service)
- src/main.rs: HTTP server (serves static files + REST/WebSocket endpoints).
- Business logic: login via iPad protocol, friend list retrieval, one-way detection.
c. Protocol Library
- Pre‐compiled iPad protocol binary (imported by the Rust service).
d. External WeChat Servers
- Official endpoints for QR code login, data fetch.
e. Local Data Store (optional)
- In‐memory or local file (temporary session, tags).

##### Relationships and data flows
- User Browser ←→ Rust Service
- Step 1: load login page (/static files).
- Step 2: request QR code, scan with phone.
- Step 3: poll backend for login status via Protocol Library → WeChat servers.
- Step 4: fetch friend list → detect one-way friends.
- Step 5: return results to Browser for tagging and display.
- Rust Service ←→ WeChat Servers via Protocol Library
- Login handshake, data fetch, status updates.

##### Architectural patterns and principles
- Client‐Server: single backend serving static assets + API.
- Separation of concerns:
- UI layer (web folder) isolated from business logic (src/main.rs).
- Protocol implementation hidden in compiled binary, behind a library facade.
- Monolith: all functionality in a single deployable binary + static asset bundle.

##### Technologies and frameworks
- Backend: Rust (Cargo), HTTP framework (e.g., Actix or Rocket), FFI for protocol library.
- Frontend: Node/npm for package management, plain JS + layui CSS/JS.
- External: WeChat iPad protocol endpoints, Swagger UI for protocol exploration.

- Major flows (Login flow, Friend list fetch, Tagging flow).
- Technologies next to each component (Rust, JS, layui).
- Keep it simple: separate UI vs. backend vs. external services, then add details around protocol calls and data flow.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Browser UI)"
        classDef frontend fill:#D0E8FF,stroke:#000;
        Browser(("User Browser")):::frontend
        IndexHTML["index.html"]:::frontend
        MainHTML["main.html"]:::frontend
        IndexJS["index.js"]:::frontend
        MainJS["main.js"]:::frontend
        IndexCSS["index.css"]:::frontend
        MainCSS["main.css"]:::frontend
        APIWrapper["WechatAPI.js"]:::frontend
        UIlib["layui/"]:::frontend
        NpmConfig["package.json"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Rust Service)"
        classDef backend fill:#DFF2D8,stroke:#000;
        StaticFileSrv["Rust HTTP Server\n(serves static files)"]:::backend
        APILayer["Rust API Layer\n(REST/WebSocket)"]:::backend
        ProtoLib["iPad Protocol Library\n(FFI binary)"]:::backend
        DataStore["Local Data Store\n(in-memory/files)"]:::backend
    end

    %% External Systems
    subgraph "External Systems"
        classDef external fill:#F0F0F0,stroke:#000;
        WechatServers["WeChat iPad Protocol Servers"]:::external
    end

    %% Documentation
    subgraph "Documentation"
        classDef docs fill:#FFF3D8,stroke:#000;
        README["README.md"]:::docs
        Cargo["Cargo.toml"]:::docs
    end

    %% Relationships
    Browser -->|"request static assets"| StaticFileSrv
    StaticFileSrv -->|"deliver index.html/main.html"| Browser
    Browser -->|"AJAX/WebSocket calls"| APILayer
    APIWrapper -.-> Browser
    Browser --> APIWrapper
    APILayer -->|"invoke protocol"| ProtoLib
    ProtoLib -->|"login & fetch data"| WechatServers
    WechatServers -->|"responses"| ProtoLib
    ProtoLib -->|"data results"| APILayer
    APILayer -->|"store session/tags"| DataStore
    APILayer -->|"send results"| Browser

    %% Click Events
    click IndexHTML "https://github.com/straymeteor3337/wechatrealfriends/blob/main/web/index.html"
    click MainHTML "https://github.com/straymeteor3337/wechatrealfriends/blob/main/web/main.html"
    click IndexJS "https://github.com/straymeteor3337/wechatrealfriends/blob/main/web/index.js"
    click MainJS "https://github.com/straymeteor3337/wechatrealfriends/blob/main/web/main.js"
    click IndexCSS "https://github.com/straymeteor3337/wechatrealfriends/blob/main/web/index.css"
    click MainCSS "https://github.com/straymeteor3337/wechatrealfriends/blob/main/web/main.css"
    click APIWrapper "https://github.com/straymeteor3337/wechatrealfriends/blob/main/web/WechatAPI.js"
    click UIlib "https://github.com/straymeteor3337/wechatrealfriends/tree/main/web/layui/"
    click NpmConfig "https://github.com/straymeteor3337/wechatrealfriends/blob/main/web/package.json"
    click APILayer "https://github.com/straymeteor3337/wechatrealfriends/blob/main/src/main.rs"
    click Cargo "https://github.com/straymeteor3337/wechatrealfriends/blob/main/Cargo.toml"
    click README "https://github.com/straymeteor3337/wechatrealfriends/blob/main/README.md"
```
