# alebupal/tvspy architecture

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

- Interactive diagram: https://gitdiagram.com/alebupal/tvspy
- Repository: https://github.com/alebupal/tvspy

## Overview

- Frontend Client: Represented by the React application (tvspy-frontend). This component includes the UI elements such as pages (Home, Channel, Registry, Settings, User), components (headers, sidebars, tables), layouts, and theming (via Tailwind CSS, custom CSS, etc.).
- Backend Server: Represented by the Node.js server (tvspy-backend) which handles HTTP routes (configuration, registries, statistics, etc.), WebSocket connections for logging active sessions, and integration with external services.
- Database: Represent the embedded SQLite database that stores data (located under tvspy-backend/src/database). Although it looks file-based, think of this component as the datastore supporting business logic.
- External Services: Include TVHeadend (the streaming server that is being monitored) and Telegram (for sending notifications of state changes like recording activities).
- Infrastructure & Deployment: Illustrate Docker components (Dockerfile, docker-compose.yml) and the Nginx reverse-proxy (nginx.conf) that likely helps in routing requests between frontend, backend, and possibly for load balancing or securing endpoints.

##### Relationships and Interactions
- Between the Backend and Database, indicate data persistence – reading the configuration and writing logs or user activities.
- A separate connection from the Backend towards External Services (TVHeadend for retrieving live monitoring data and Telegram for sending notifications) should be clearly drawn.
- Optionally, if Nginx is used as a reverse proxy, show it sitting in front of the backend (and perhaps even routing static assets for the frontend).
- Docker container encapsulation for both frontend and backend, illustrating that each runs inside its own container or as part of a multi-container setup orchestrated via docker-compose.

##### Architectural Patterns
- The separation between frontend and backend is a central element. This is typically modeled using an API layer that abstracts communication, possibly RESTful or WebSocket-based, which should be highlighted.
- The backend exhibits a modular structure as it splits the routing (configRoutes, registriesRoutes, statisticsRoutes, etc.) and database interactions, indicating adherence to a separation of concerns / layered architecture.
- The use of Docker and Nginx underlines an emphasis on containerized deployments, meaning that environment configuration, orchestration, and potential scalability are considered in the design.

##### Relevant Technologies and Tools
- Languages and frameworks (Node.js for backend, React + TypeScript for frontend).
- Mention additional libraries such as WebSocket support, Tailwind CSS for styling, and Docker for containerization.
- Use of postman collections (TVSPY.postman_collection.json) to support testing of APIs, which can also be represented as a testing component if useful.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Infrastructure & Deployment
    subgraph "Infrastructure & Deployment"
        Docker["Docker (Dockerfile & docker-compose.yml)"]:::infra
        Nginx["Nginx Reverse Proxy"]:::infra
        Postman["Postman Collection"]:::infra
    end

    %% Application Layer
    subgraph "Application Layer"
        FFE["TVSPY Frontend (React + TS)"]:::frontend
        BE["TVSPY Backend (Node.js)"]:::backend
        Docker --> FFE
        Docker --> BE
        Nginx --> BE
        Postman --> BE
    end

    %% Backend Services
    subgraph "Backend Services"
        %% API Routes Subgroup
        subgraph "API Routes"
            CR["configRoutes.js"]:::api
            CTH["configTvheadend.js"]:::api
            RR["registriesRoutes.js"]:::api
            SR["statisticsRoutes.js"]:::api
            SU["subcriptions.js"]:::api
            THR["tvheadendRoutes.js"]:::api
        end
        DB1["SQLite Database"]:::database
        XTV["TVHeadend Server"]:::external
        XTG["Telegram Notification Service"]:::external
    end

    %% Connections between layers
    FFE -->|"APIcalls"| BE
    BE -->|"calls"| CR
    BE -->|"calls"| CTH
    BE -->|"calls"| RR
    BE -->|"calls"| SR
    BE -->|"calls"| SU
    BE -->|"calls"| THR
    BE -->|"CRUD"| DB1
    BE --o|"WS/HTTP"| XTV
    BE --o|"Notifications"| XTG

    %% Styles
    classDef frontend fill:#FFEEAD,stroke:#333,stroke-width:2px;
    classDef backend fill:#B3E5FC,stroke:#333,stroke-width:2px;
    classDef api fill:#FFCDD2,stroke:#333,stroke-width:2px;
    classDef database fill:#C8E6C9,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
    classDef external fill:#D1C4E9,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
    classDef infra fill:#E1BEE7,stroke:#333,stroke-width:2px;

    %% Click Events
    click FFE "https://github.com/alebupal/tvspy/tree/main/tvspy-frontend/"
    click BE "https://github.com/alebupal/tvspy/tree/main/tvspy-backend/"
    click DB1 "https://github.com/alebupal/tvspy/tree/main/tvspy-backend/src/database/"
    click CR "https://github.com/alebupal/tvspy/blob/main/tvspy-backend/src/routes/configRoutes.js"
    click CTH "https://github.com/alebupal/tvspy/blob/main/tvspy-backend/src/routes/configTvheadend.js"
    click RR "https://github.com/alebupal/tvspy/blob/main/tvspy-backend/src/routes/registriesRoutes.js"
    click SR "https://github.com/alebupal/tvspy/blob/main/tvspy-backend/src/routes/statisticsRoutes.js"
    click SU "https://github.com/alebupal/tvspy/blob/main/tvspy-backend/src/routes/subcriptions.js"
    click THR "https://github.com/alebupal/tvspy/blob/main/tvspy-backend/src/routes/tvheadendRoutes.js"
    click Postman "https://github.com/alebupal/tvspy/blob/main/tvspy-backend/TVSPY.postman_collection.json"
    click Nginx "https://github.com/alebupal/tvspy/blob/main/nginx.conf"
    click Docker "https://github.com/alebupal/tvspy/tree/main/Dockerfile"
```
