# sjlu/popular-movies architecture

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

- Interactive diagram: https://gitdiagram.com/sjlu/popular-movies
- Repository: https://github.com/sjlu/popular-movies

## Overview

##### Main Components
- Data Fetching/Integration Layer – Represented by multiple modules in the lib directory such as tmdb.js, imdb.js, metacritic.js, omdb.js, r2.js, and others. These modules communicate with external movie data APIs.
- Caching/Utility Layer – There is an fs_cache.js module that suggests the project makes use of local caching for fetched data to possibly reduce network calls or improve performance.
- Data Aggregation & Evaluation Component – At the heart of the project is the logic that uses data from the different sources and feeds it to a large language model (LLM) for evaluating movie popularity. Even though explicit LLM integration code isn’t separately visible, the README’s description tells us this is a core purpose.
- API/Data Exposure/Output Layer – The project generates JSON files (such as movies.json, movies-imdb-minX.json, etc.) which are hosted on an S3 endpoint (with a noted change of URL). This layer is responsible for outputting processed movie data.
- Deployment & Testing Utilities – With a separate bin directory (containing deploy.js and test scripts) and a test directory (with test/all.js and GitHub workflows for linting and S3 uploading), you have dedicated scripts for deployment, running tests, and CI/CD.
- Configuration & Environment – Files like config.js and the .env instructions in the README indicate that you must include API keys (like TMDB_KEY) and other configuration details such as connections to a locally running instance of Redis for caching or other local storage needs.

##### Relationships and Data Flow
- Data Acquisition: From these sources, the corresponding modules in the lib/ directory fetch the movie data.
- Caching & Utility Processing: Data may be cached using fs_cache.js for better performance or reliability.
- Data Processing: The aggregated data is then evaluated by the popularity engine that uses LLMs (this could be a combination of custom logic in index.js or within lib modules such as anthropic.js, which might relate to LLMs) to determine the “popularity” of new releases.
- Data Output: The processed results are then formatted (using json2csv, for example) and stored or exposed as JSON files that are eventually deployed via S3. The S3 module and deployment script (bin/deploy.js) facilitate pushing these output files to their endpoint.
- Testing & CI/CD: Automated tests (in test/all.js) and GitHub workflows ensure continuous integration and smooth updates.

##### Architectural Patterns & Design Principles
- Modular Design – The storage of different responsibilities in separate modules (e.g., one file per data-source integration) adheres to modular design.
- Separation of Concerns – Fetching data, caching, processing with LLM evaluations, and serving JSON files are clearly separated into different components.
- Automation & CI/CD – The inclusion of GitHub workflows and deployment scripts for sustainable operation.
- Extensibility – The way the system is structured suggests that additional data sources or evaluation logic can be plugged in with minimal changes.

##### Elements
- Clear component labels: Indicate “Data Fetch Modules” (e.g., TMDB, IMDb, etc.), “Caching Module”, “LLM Evaluation Engine”, “JSON Output Generator”, “Deployment Module”, and optionally “Frontend” (if applicable).
- Annotations for technologies: Label Node.js as the runtime, mention Redis for caching, and indicate that AWS S3 is used for deployment of output JSON files. Also annotate the use of npm/node modules as referenced in package.json.

## Diagram (Mermaid)

```mermaid
graph TD
  %% External Systems
  subgraph "External Systems"
    TMDB_API["TMDB API"]:::external
    IMDb_API["IMDb API"]:::external
    Metacritic_API["Metacritic API"]:::external
    OMDB_API["OMDB API"]:::external
    Rotten_API["RottenTomatoes API"]:::external
  end

  %% Data Fetching Layer
  subgraph "Data Fetching Layer"
    TMDB_Module["tmdb.js"]:::fetch
    IMDb_Module["imdb.js"]:::fetch
    Metacritic_Module["metacritic.js"]:::fetch
    OMDB_Module["omdb.js"]:::fetch
    R2_Module["r2.js"]:::fetch
  end

  %% Caching & Utility Layer
  subgraph "Caching & Utility Layer"
    Cache["fs_cache.js"]:::cache
    CSVUtil["json2csv.js"]:::cache
  end

  %% Aggregation & Evaluation Layer
  subgraph "Aggregation & Evaluation Layer"
    Aggregator["index.js"]:::aggregation
    LLM["anthropic.js"]:::aggregation
  end

  %% API/Data Exposure Layer
  subgraph "API Data Exposure Layer"
    S3_Module["s3.js"]:::api
    JSON_Output["Generated JSON Files"]:::api
  end

  %% Deployment & Testing Utilities
  subgraph "Deployment & Testing"
    Deploy["deploy.js"]:::deploy
    Test_Script["bin/test"]:::deploy
    Test_All["test/all.js"]:::deploy
    CI_Workflows["GitHub Workflows"]:::deploy
  end

  %% Configuration & Environment
  subgraph "Configuration & Environment"
    Config["config.js"]:::config
    Readme["README.md (.env & API Keys)"]:::config
  end

  %% Data Flow Connections
  TMDB_API -->|"fetch"| TMDB_Module
  IMDb_API -->|"fetch"| IMDb_Module
  Metacritic_API -->|"fetch"| Metacritic_Module
  OMDB_API -->|"fetch"| OMDB_Module
  Rotten_API -->|"fetch"| R2_Module

  TMDB_Module -->|"cache"| Cache
  IMDb_Module -->|"cache"| Cache
  Metacritic_Module -->|"cache"| Cache
  OMDB_Module -->|"cache"| Cache
  R2_Module -->|"cache"| Cache

  Cache -->|"aggregate"| Aggregator
  Aggregator -->|"invoke"| LLM
  Aggregator -->|"format"| CSVUtil
  CSVUtil -->|"deploy"| S3_Module
  S3_Module -->|"output"| JSON_Output
  Deploy -->|"trigger"| S3_Module

  %% Configuration Dependencies
  Config ---|"configures"| Aggregator
  Config ---|"configures"| TMDB_Module
  Config ---|"configures"| IMDb_Module
  Config ---|"configures"| Metacritic_Module
  Config ---|"configures"| OMDB_Module
  Config ---|"configures"| R2_Module

  %% Deployment & Testing Influence (dotted connections)
  Test_Script ---|"verifies"| Aggregator
  Test_All ---|"tests"| Aggregator
  CI_Workflows ---|"automates"| Deploy

  %% Click Events
  click TMDB_Module "https://github.com/sjlu/popular-movies/blob/main/lib/tmdb.js"
  click IMDb_Module "https://github.com/sjlu/popular-movies/blob/main/lib/imdb.js"
  click Metacritic_Module "https://github.com/sjlu/popular-movies/blob/main/lib/metacritic.js"
  click OMDB_Module "https://github.com/sjlu/popular-movies/blob/main/lib/omdb.js"
  click R2_Module "https://github.com/sjlu/popular-movies/blob/main/lib/r2.js"
  click Cache "https://github.com/sjlu/popular-movies/blob/main/lib/fs_cache.js"
  click CSVUtil "https://github.com/sjlu/popular-movies/blob/main/lib/json2csv.js"
  click Aggregator "https://github.com/sjlu/popular-movies/blob/main/index.js"
  click LLM "https://github.com/sjlu/popular-movies/blob/main/lib/anthropic.js"
  click S3_Module "https://github.com/sjlu/popular-movies/blob/main/lib/s3.js"
  click Deploy "https://github.com/sjlu/popular-movies/blob/main/bin/deploy.js"
  click Test_Script "https://github.com/sjlu/popular-movies/tree/main/bin/test"
  click Test_All "https://github.com/sjlu/popular-movies/blob/main/test/all.js"
  click CI_Workflows "https://github.com/sjlu/popular-movies/tree/main/.github/workflows"
  click Config "https://github.com/sjlu/popular-movies/blob/main/config.js"
  click Readme "https://github.com/sjlu/popular-movies/blob/main/README.md"

  %% Class Definitions for Colors and Styles
  classDef external fill:#f9c74f,stroke:#000,stroke-width:2px;
  classDef fetch fill:#90be6d,stroke:#000,stroke-width:2px;
  classDef cache fill:#f9844a,stroke:#000,stroke-width:2px;
  classDef aggregation fill:#577590,stroke:#000,stroke-width:2px,color:#fff;
  classDef api fill:#f94144,stroke:#000,stroke-width:2px;
  classDef deploy fill:#277da1,stroke:#000,stroke-width:2px,color:#fff;
  classDef config fill:#6a4c93,stroke:#000,stroke-width:2px,color:#fff;
```
