# chervaliery/tv_show_fetcher architecture

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

- Interactive diagram: https://gitdiagram.com/chervaliery/tv_show_fetcher
- Repository: https://github.com/chervaliery/tv_show_fetcher

## Overview

##### Project type and purpose
- This is a Django-based full-stack application named “tv_show_fetcher.”
- Purpose: automates fetching and downloading TV show data/episodes using Selenium and OCR (Tesseract), then provides a web “backoffice” interface to manage shows and episodes stored in MySQL.

##### File structure
- Top level:
- manage.py – Django CLI entry point
- tv_show_fetcher/ – Django project folder containing settings, URLs, WSGI
- backoffice/ – Django app for admin/views/commands
- tv_show_fetcher/settings.py – DB, middleware, installed apps
- tv_show_fetcher/urls.py – root URL dispatcher
- backoffice/management/commands/*.py – custom Django commands (downloadepisode, fetchshow, getshow)
- backoffice/models.py – ORM definitions for Show/Episode
- backoffice/views.py & admin.py – HTTP views and admin customizations
- backoffice/utils.py – helper functions (e.g., image→text via pytesseract)
- Configuration files: .gitignore, LICENSE, README.md

##### README for additional insights
- Dependencies: Python-pip, MySQL, python-mysqldb, xvfb, tesseract-ocr
- Python packages: django, selenium, pytesseract, Image, pyvirtualdisplay
- Implies headless browser automation + OCR pipeline for data extraction

a. Main components
1. Web Client (browser)
2. Django Web Server
- backoffice app (models, views, admin)
- custom management commands (CLI)
3. MySQL Database
4. External Headless Browser Service
- Selenium + Xvfb
5. OCR Engine
- Tesseract via pytesseract
6. File Store (temporary screenshots/images)
b. Relationships & data flow
- Web client ↔ Django views (HTTP/HTTPS)
- Django ORM ↔ MySQL (CRUD on Show/Episode models)
- Management commands triggered (cron or manual) → launch Selenium in Xvfb → fetch page → save screenshot → invoke pytesseract → parse text → create/update DB records
- backoffice views read from DB and render templates
c. Architectural patterns/design principles
- MVC (Django’s MTV) for web layer
- Command pattern for data‐fetch tasks
- Layered architecture: Presentation → Business (views/utils/commands) → Data (models/DB)
- Separation of concerns: OCR & browser automation isolated in utils & commands
d. Key technologies
- Django (web framework, ORM, command infrastructure)
- MySQL (relational store)
- Selenium + Xvfb (headless browser automation)
- Tesseract OCR (text extraction)
- Python imaging libraries (PIL/Image)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["Web Client (Browser)"]:::frontend
        Views["Backoffice Views"]:::frontend
    end

    Browser -->|"HTTP/HTTPS"| Views
    Views -->|"renders via Django" | Browser

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        CLI["Django CLI Entry Point"]:::backend
        Settings["Django Settings"]:::backend
        URLs["Root URL Dispatcher"]:::backend
        WSGI["WSGI Application"]:::backend
        subgraph "Backoffice App"
            direction TB
            AppConfig["App Configuration"]:::backend
            Models["ORM Models (Show & Episode)"]:::backend
            Admin["Admin Customizations"]:::backend
            Utils["Utility Functions (OCR, Image Processing)"]:::backend
            ViewsCmd["HTTP Views (Backoffice UI)"]:::backend
            Tests["Backoffice App Tests"]:::backend
            subgraph "Management Commands"
                direction TB
                FetchShow["fetchshow"]:::backend
                GetShow["getshow"]:::backend
                DownloadEpisode["downloadepisode"]:::backend
            end
        end
    end

    Views -->|"uses URL dispatcher"| URLs
    URLs --> Settings
    Settings --> WSGI
    CLI --> Settings
    CLI --> URLs
    CLI --> WSGI
    Views --> Models
    Admin --> Models
    ViewsCmd --> Models
    Utils --> Models
    Models --> Tests

    %% External Services
    subgraph "External Services"
        direction TB
        Selenium["Selenium + Xvfb"]:::external
        OCR["Tesseract OCR"]:::external
    end

    FetchShow -->|"launch"| Selenium
    GetShow -->|"launch"| Selenium
    DownloadEpisode -->|"launch"| Selenium
    Selenium -->|"screenshot"| FileStore
    FileStore -->|"image file"| OCR
    OCR --> Utils

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MySQL["MySQL Database"]:::storage
        FileStore["File Store (Temp Images)"]:::storage
    end

    Models -->|"CRUD"| MySQL
    Utils -->|"inserts/updates"| MySQL
    Tests --> MySQL

    %% Click Events
    click CLI "https://github.com/chervaliery/tv_show_fetcher/blob/master/manage.py"
    click Settings "https://github.com/chervaliery/tv_show_fetcher/blob/master/tv_show_fetcher/settings.py"
    click URLs "https://github.com/chervaliery/tv_show_fetcher/blob/master/tv_show_fetcher/urls.py"
    click WSGI "https://github.com/chervaliery/tv_show_fetcher/blob/master/tv_show_fetcher/wsgi.py"
    click AppConfig "https://github.com/chervaliery/tv_show_fetcher/blob/master/backoffice/apps.py"
    click Models "https://github.com/chervaliery/tv_show_fetcher/blob/master/backoffice/models.py"
    click ViewsCmd "https://github.com/chervaliery/tv_show_fetcher/blob/master/backoffice/views.py"
    click Admin "https://github.com/chervaliery/tv_show_fetcher/blob/master/backoffice/admin.py"
    click Utils "https://github.com/chervaliery/tv_show_fetcher/blob/master/backoffice/utils.py"
    click FetchShow "https://github.com/chervaliery/tv_show_fetcher/blob/master/backoffice/management/commands/fetchshow.py"
    click GetShow "https://github.com/chervaliery/tv_show_fetcher/blob/master/backoffice/management/commands/getshow.py"
    click DownloadEpisode "https://github.com/chervaliery/tv_show_fetcher/blob/master/backoffice/management/commands/downloadepisode.py"
    click Tests "https://github.com/chervaliery/tv_show_fetcher/blob/master/backoffice/tests.py"
    click README "https://github.com/chervaliery/tv_show_fetcher/blob/master/README.md"
    click GITIGNORE "https://github.com/chervaliery/tv_show_fetcher/blob/master/.gitignore"
    click LICENSE "https://github.com/chervaliery/tv_show_fetcher/tree/master/LICENSE"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#006064
    classDef backend fill:#E8F5E9,stroke:#1B5E20,color:#1B5E20
    classDef external fill:#FFF3E0,stroke:#E65100,color:#E65100
    classDef storage fill:#ECEFF1,stroke:#37474F,color:#37474F
```
