# tsukinatsune/pysimple-sharescreen architecture

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

- Interactive diagram: https://gitdiagram.com/tsukinatsune/pysimple-sharescreen
- Repository: https://github.com/tsukinatsune/pysimple-sharescreen

## Overview

##### Project Type and Purpose
- This is a lightweight, single-host screen-sharing tool written in C (`build.c` → `Release.exe`) that captures the desktop, encodes frames as Motion-JPEG, and serves them via HTTP on port 8080.
- A companion HTML client (`Sharescreen.html`) connects to that stream.

##### File Structure
- Top level:
- `build.c` : source code for the capture + HTTP server
- `Release.exe` : compiled binary
- `Sharescreen.html` : client-side viewer
- `file/` : resource directory containing `.trafileN` (likely configuration or resource data)
- No separate frontend/backend folders—both client (HTML) and server (C) coexist in the same repo.
- No external DB or microservices—everything runs on one host.

##### Extract Key Architectural Insights from README
- The server listens on port 8080 and streams MJPEG.
- The user must port-forward that port externally.
- The HTML page fetches the MJPEG stream over HTTP.

##### Relationships & Data Flows
1. Desktop frames → pass to JPEG Encoder
2. Encoder outputs motion-JPEG frames → HTTP Server
3. HTTP Server exposes an MJPEG stream on localhost:8080
4. External user/browser fetches via port-forward → displays in `Sharescreen.html`
5. Resource Loader feeds any static data (e.g., config, overlays) into the server at startup.

##### Architectural Patterns & Design Principles
- Monolithic, single-process model
- Modular internal separation: capture → encode → serve
- HTTP-based streaming (stateless per frame)
- File-based configuration/resources

##### Technologies & Frameworks
- C standard library + platform-specific screen capture APIs
- HTTP protocol (simple socket server)
- MJPEG format
- HTML5 `<img>` tag or `<video>` tag for client

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Actors and external
    Desktop(["Desktop Screen"]):::external

    %% Server Container
    subgraph "ScreenShare Server"
        direction TB
        Binary["Release.exe"]:::server
        build["build.c"]:::server
        ResourceLoader["Resource Loader"]:::server
        Capture["Screen Capture Module"]:::server
        Encoder["JPEG Encoder Module"]:::server
        HTTPServer["HTTP Server Module\n(port 8080)"]:::server
    end

    %% Resources
    Resources[("file/*.trafile*\n(resource files)")]:::resource

    %% Network and Client
    Internet(("Internet / Port-Forward\n(8080)")):::network
    Client["Sharescreen.html Client"]:::client
    README["Project Docs: README.md"]:::docs

    %% Connections
    Desktop -->|"captured frames"| Capture
    build -->|"compiles into"| Binary
    Capture -->|"raw frames"| Encoder
    Encoder -->|"MJPEG frames"| HTTPServer
    HTTPServer -->|"HTTP GET /mjpg/video"| Internet
    Internet -->|"streams MJPEG"| Client

    Resources --> ResourceLoader
    ResourceLoader -->|"loads config at startup"| build

    README --- build

    %% Click Events
    click Binary "https://github.com/tsukinatsune/pysimple-sharescreen/blob/main/Release.exe"
    click build "https://github.com/tsukinatsune/pysimple-sharescreen/blob/main/build.c"
    click Resources "https://github.com/tsukinatsune/pysimple-sharescreen/tree/main/file/"
    click Client "https://github.com/tsukinatsune/pysimple-sharescreen/blob/main/Sharescreen.html"
    click README "https://github.com/tsukinatsune/pysimple-sharescreen/blob/main/README.md"

    %% Styles
    classDef server fill:#add8e6,stroke:#000,stroke-width:1px
    classDef resource fill:#d3d3d3,stroke:#000
    classDef network fill:#b3e5fc,stroke:#000
    classDef client fill:#a5d6a7,stroke:#000
    classDef external fill:#ffffff,stroke:#000,stroke-dasharray: 5 5
    classDef docs fill:#ffcccb,stroke:#000
```
