# mitthu786/ts-jiotv architecture

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

- Interactive diagram: https://gitdiagram.com/mitthu786/ts-jiotv
- Repository: https://github.com/mitthu786/ts-jiotv

## Overview

##### Project Type and Purpose
- This is a monolithic PHP‑based streaming web application (LAMP stack) providing live and 7‑day catchup TV for JioTV channels.
- It contains both presentation (HTML/CSS/JS) and application logic (PHP scripts for login, API proxying, playlist generation, streaming).

##### File‑Structure Analysis
- Top‑Level
– index.php and .htaccess: entry point and routing rules
– app/: contains all application logic, assets, sub‑modules
- app/assets/: static files (CSS, JavaScript, placeholder data)
- app/login/: OTP login, session management
- app/catchup/: catchup TV logic, API calls, proxy support
- play.php, playlist.php, stream.php: streaming entry points
- app/functions.php and app/catchup/cpfunctions.php: shared helper functions (proxy flag, JioTV API wrappers)

##### Key Components
a. Client Layer
– Web browsers (desktop, mobile, Android TV)
– JS player (JWPlayer), search UI
b. Web Server
– Apache (with .htaccess rules)
– PHP 7.4+ runtime
c. Application Layer (PHP Modules)
– Authentication Module (app/login)
– Catchup Module (app/catchup)
– Playlist/Streaming Controllers (play.php, playlist.php, stream.php)
– Shared Services (functions.php, cpfunctions.php)
d. External Dependencies
– JioTV public/private streaming APIs
– Optional proxy endpoint (configured via $PROXY)
e. Static Assets
– CSS, JS delivered from app/assets
f. Clients for Third‑Party Services
– OTP provider (SMS gateway)
– Channel metadata (search, filters)

##### Relationships and Data Flow
- User → Browser → HTTP GET/POST → Apache
- Apache routes requests via .htaccess to index.php or specific controllers
- Controllers invoke shared functions to:
– Validate session/OTP
– Proxy streaming / catchup API calls to JioTV endpoints (via cpapi, cpstream)
– Generate M3U playlist or HLS stream URLs
- Server → Response
– HTML pages (injected with JS player)
– JSON/AJAX for search, filters
– M3U8 or TS segments for player
- Browser/JWPlayer → Playback requests (chunked delivery)

##### Architectural Patterns and Principles
- Modular organization: separate sub‑directories for each functional area
- Controller‑Helper pattern: small PHP entry scripts call shared helper functions
- No relational database: filesystem or in‑memory session storage
- Proxy abstraction: toggled via configuration ($PROXY)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        Browser("Web Browser (desktop/mobile/Android TV)"):::frontend
        JWPlayer("JWPlayer Player"):::frontend
        SearchUI("Search UI (search.js, button.js)"):::frontend
        Browser -->|"HTTP GET/POST"| Apache
        Browser --> SearchUI
        Browser --> JWPlayer
    end

    subgraph "Web Server"
        Apache("Apache HTTP Server"):::backend
        HT("Routing Rules (.htaccess)"):::backend
        Index("Front Controller (index.php)"):::backend
        Apache --> HT
        HT --> Index
        Index --> PHP
    end

    subgraph "Application Layer"
        subgraph "Authentication Module"
            AuthIndex("Login Entry (/app/login/index.php)"):::backend
            OTPVerify("OTP Verification (/app/login/otpVerify.php)"):::backend
            RefreshLogin("Session Refresh (/app/login/refreshLogin.php)"):::backend
            Logout("Logout (/app/login/logout.php)"):::backend
        end

        subgraph "Catchup Module"
            CatchIndex("Catchup Front Controller (/app/catchup/index.php)"):::backend
            CPAPI("API Proxy (/app/catchup/cpapi.php)"):::backend
            CPAuth("Authenticated Proxy (/app/catchup/cpauth.php)"):::backend
            CPSony("Sony‑Specific Auth (/app/catchup/cpSonyAuth.php)"):::backend
            CPStream("Stream Proxy (/app/catchup/cpstream.php)"):::backend
            CPlay("Playback Handler (/app/catchup/cplay.php)"):::backend
        end

        subgraph "Playback & Playlist Controllers"
            Live("Live Streaming (/app/live.php, /app/s_live.php)"):::backend
            PlayEP("Play Endpoint (/app/play.php)"):::backend
            Playlist("Playlist Generation (/app/playlist.php)"):::backend
            StreamDel("Stream Delivery (/app/stream.php)"):::backend
            Details("Details Endpoint (/app/details.php)"):::backend
            AuthWrap("Authentication Wrapper (/app/auth.php)"):::backend
        end
    end

    subgraph "Shared Services"
        GlobalFunc("Global Helpers (/app/functions.php)"):::backend
        CatchupFunc("Catchup Helpers (/app/catchup/cpfunctions.php)"):::backend
    end

    subgraph "Static Asset Server"
        Assets("Asset Root (/app/assets/index.php)"):::static
        CSS("CSS Stylesheets (/app/assets/css/player.css)"):::static
        SearchJS("search.js (/app/assets/js/search.js)"):::static
        ButtonJS("button.js (/app/assets/js/button.js)"):::static
        JWLib("jwplayer.js (/app/assets/js/jwplayer.js)"):::static
        Assets --> CSS
        Assets --> SearchJS
        Assets --> ButtonJS
        Assets --> JWLib
    end

    subgraph "External Services"
        JioTVAPI("JioTV Streaming APIs"):::external
        OTPService("OTP Provider (SMS Gateway)"):::external
        ChannelMeta("Channel Metadata Service"):::external
    end

    PHP("PHP 7.4+ Runtime"):::backend

    %% Connections
    Index --> AuthIndex
    Index --> CatchIndex
    Index --> Live
    Index --> PlayEP
    Index --> Playlist
    Index --> StreamDel
    Index --> Details
    Index --> AuthWrap

    AuthIndex --> GlobalFunc
    OTPVerify --> GlobalFunc
    RefreshLogin --> GlobalFunc
    Logout --> GlobalFunc
    AuthIndex --> OTPService
    OTPVerify --> OTPService

    CatchIndex --> CPAPI
    CPAPI --> CatchupFunc
    CPAuth --> CatchupFunc
    CPSony --> CatchupFunc
    CPStream --> CatchupFunc
    CPAPI --> JioTVAPI
    CPStream --> JioTVAPI
    CPlay --> JioTVAPI

    Live --> JioTVAPI

    Playlist --> GlobalFunc
    Playlist --> JWPlayer
    PlayEP --> StreamDel
    StreamDel --> JWPlayer

    SearchUI -->|"AJAX/JSON"| Index
    SearchUI --> ChannelMeta
    ChannelMeta --> Index

    Apache --> Assets
    Assets --> Browser

    %% Click Events
    click HT "https://github.com/mitthu786/ts-jiotv/blob/main//.htaccess"
    click Index "https://github.com/mitthu786/ts-jiotv/blob/main//index.php"
    click AuthIndex "https://github.com/mitthu786/ts-jiotv/blob/main//app/login/index.php"
    click OTPVerify "https://github.com/mitthu786/ts-jiotv/blob/main//app/login/otpVerify.php"
    click RefreshLogin "https://github.com/mitthu786/ts-jiotv/blob/main//app/login/refreshLogin.php"
    click Logout "https://github.com/mitthu786/ts-jiotv/blob/main//app/login/logout.php"
    click CatchIndex "https://github.com/mitthu786/ts-jiotv/blob/main//app/catchup/index.php"
    click CPAPI "https://github.com/mitthu786/ts-jiotv/blob/main//app/catchup/cpapi.php"
    click CPAuth "https://github.com/mitthu786/ts-jiotv/blob/main//app/catchup/cpauth.php"
    click CPSony "https://github.com/mitthu786/ts-jiotv/blob/main//app/catchup/cpSonyAuth.php"
    click CPStream "https://github.com/mitthu786/ts-jiotv/blob/main//app/catchup/cpstream.php"
    click CPlay "https://github.com/mitthu786/ts-jiotv/blob/main//app/catchup/cplay.php"
    click GlobalFunc "https://github.com/mitthu786/ts-jiotv/blob/main//app/functions.php"
    click CatchupFunc "https://github.com/mitthu786/ts-jiotv/blob/main//app/catchup/cpfunctions.php"
    click Live "https://github.com/mitthu786/ts-jiotv/blob/main//app/live.php"
    click PlayEP "https://github.com/mitthu786/ts-jiotv/blob/main//app/play.php"
    click Playlist "https://github.com/mitthu786/ts-jiotv/blob/main//app/playlist.php"
    click StreamDel "https://github.com/mitthu786/ts-jiotv/blob/main//app/stream.php"
    click Details "https://github.com/mitthu786/ts-jiotv/blob/main//app/details.php"
    click AuthWrap "https://github.com/mitthu786/ts-jiotv/blob/main//app/auth.php"
    click Assets "https://github.com/mitthu786/ts-jiotv/blob/main//app/assets/index.php"
    click CSS "https://github.com/mitthu786/ts-jiotv/blob/main//app/assets/css/player.css"
    click SearchJS "https://github.com/mitthu786/ts-jiotv/blob/main//app/assets/js/search.js"
    click ButtonJS "https://github.com/mitthu786/ts-jiotv/blob/main//app/assets/js/button.js"
    click JWLib "https://github.com/mitthu786/ts-jiotv/blob/main//app/assets/js/jwplayer.js"

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:1px;
    classDef backend fill:#bbf,stroke:#333,stroke-width:1px;
    classDef static fill:#bfb,stroke:#333,stroke-width:1px;
    classDef external fill:#ffb,stroke:#333,stroke-width:1px;
```
