# glg-public/glg-simple-movie-app architecture

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

- Interactive diagram: https://gitdiagram.com/glg-public/glg-simple-movie-app
- Repository: https://github.com/glg-public/glg-simple-movie-app

## Overview

##### Project type and purpose
- This is a full-stack web application built with React (Vite) on the front end and Node.js/TypeScript on the back end.
- It fetches movie and TV data from The Movie Database (TMDb) API (or from local JSON mocks when offline).
- It’s designed to run in Docker for a consistent development environment.

##### File structure
- Top level: Docker and environment config files (`Dockerfile.dev`, `docker-compose.yml`, `.env` templates, `bin/prepare-docker.sh`).
- `src/`: the client-side React application (components, views, hooks, contexts, MSW mocks, styles).
- `server/`: the back-end API (controllers, router, service layer for TMDb, server-side mocks).
- `public/` and `index.html`: static assets and the single HTML host page for the SPA.
- `package.json`, `vite.config.ts`, `tsconfig*.json`: build and toolchain configuration.

##### README for additional insights
- Confirms React + Node + TypeScript tech stack.
- Mentions optional MSW mocks via `VITE_MOCK_RESULTS=true`.
- Describes database tables (MEDIA, USER, relations) conceptually—even though the current server uses JSON mocks rather than a real database.

##### Main components
a. Front-end Application Container
- React SPA served by Vite (or Docker-mounted static files in production).
- Client-side MSW (Mock Service Worker) that can intercept API calls when enabled.
b. Back-end API Container
- Node.js + Express (or similar) server in `server/index.ts`.
- Controllers/routers under `server/controllers`, service layer in `server/services` (MovieDB.ts).
- Server-side mocks (`server/mocks/data/...`) used when external API is unreachable.
c. External Services
- The Movie Database (TMDb) REST API.
- (Optional) Docker daemon or local file system mounts for code and env injection.
d. (Conceptual) Database

##### Relationships and data flows
- User → Browser → React SPA
- React SPA → (MSW? →) API server
- API server → MovieDB service → TMDb API (or server-side JSON mocks)
- API server → (in future) database
- Docker Compose orchestrates two containers (front-end and back-end), injecting `/etc/dev.env`.

##### Architectural patterns and key principles
- SPA architecture (separation of concerns: views, controllers, stores).
- API-First design (REST endpoints in Node).
- Service layer abstraction for external API (MovieDB service).
- Mock-first development enabled via MSW both client- and server-side.
- Containerization for environment parity.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Docker Compose grouping
    subgraph "Docker Compose" 
        direction TB
        subgraph "Frontend Container" 
            direction TB
            ReactSPA["React SPA"]:::frontend
            ViteServer["Vite Dev Server"]:::frontend
            PublicHTML["Static Host (index.html)"]:::frontend
            subgraph "Client-side MSW" 
                direction TB
                MSWWorker["Mock Service Worker"]:::mock
                MSWBrowser["browser.ts"]:::mock
                MSWHandlers["handlers.ts"]:::mock
            end
            subgraph "Frontend Files"
                direction TB
                IndexTSX["index.tsx"]:::frontend
                PublicIndex["index.html"]:::frontend
                ViteConfig["vite.config.ts"]:::frontend
                PackageJSON["package.json"]:::frontend
            end
            ReactSPA --> ViteServer
            ReactSPA --> PublicHTML
            ReactSPA --> MSWWorker
            ReactSPA --> APIServer
        end

        subgraph "Backend Container"
            direction TB
            APIServer["Node.js API Server"]:::backend
            IndexServer["server/index.ts"]:::backend
            subgraph "Controllers"
                direction TB
                MediaRouter["MediaRouter"]:::backend
                MediaController["MediaController"]:::backend
            end
            MovieService["MovieDB Service"]:::backend
            subgraph "Server-side Mocks"
                direction TB
                MockHandlers["handlers.ts"]:::mock
                NodeMocks["node.ts"]:::mock
                subgraph "Mock Data"
                    direction TB
                    AllJSON["all.json"]:::mock
                    MovieJSON["movie/*.json"]:::mock
                    TVJSON["tv/*.json"]:::mock
                end
            end
            APIServer --> MediaRouter
            MediaRouter --> MediaController
            MediaController --> MovieService
            MovieService --> TMDbAPI
            MovieService --> MockHandlers
            MockHandlers --> AllJSON
            MockHandlers --> MovieJSON
            MockHandlers --> TVJSON
            APIServer --> Database
        end

        subgraph "Dev Env Setup"
            direction TB
            Dockerfile["Dockerfile.dev"]:::external
            ComposeFile["docker-compose.yml"]:::external
            PrepareScript["bin/prepare-docker.sh"]:::external
            EnvFile["etc/dev.env"]:::external
        end
    end

    %% External systems
    TMDbAPI["TMDb REST API"]:::external
    Database["Relational DB (future)"]:::external
    User(("User")):::external

    %% Flows
    User -->|"Uses"| ReactSPA
    ReactSPA -->|"Fetches data"| APIServer
    ReactSPA -->|"Intercepts calls"| MSWWorker
    APIServer -->|"External API calls"| TMDbAPI
    APIServer -->|"Mocks fallback"| MockHandlers
    APIServer -->|"Future persistence"| Database

    %% Click events for Frontend Files
    click IndexTSX "https://github.com/glg-public/glg-simple-movie-app/blob/main/src/index.tsx"
    click PublicIndex "https://github.com/glg-public/glg-simple-movie-app/blob/main/public/index.html"
    click ViteConfig "https://github.com/glg-public/glg-simple-movie-app/blob/main/vite.config.ts"
    click PackageJSON "https://github.com/glg-public/glg-simple-movie-app/blob/main/package.json"

    %% Click events for MSW
    click MSWWorker "https://github.com/glg-public/glg-simple-movie-app/blob/main/public/mockServiceWorker.js"
    click MSWBrowser "https://github.com/glg-public/glg-simple-movie-app/blob/main/src/mocks/browser.ts"
    click MSWHandlers "https://github.com/glg-public/glg-simple-movie-app/blob/main/src/mocks/handlers.ts"

    %% Click events for Backend
    click IndexServer "https://github.com/glg-public/glg-simple-movie-app/blob/main/server/index.ts"
    click MediaRouter "https://github.com/glg-public/glg-simple-movie-app/blob/main/server/controllers/media/MediaRouter.ts"
    click MediaController "https://github.com/glg-public/glg-simple-movie-app/blob/main/server/controllers/media/MediaController.ts"
    click MovieService "https://github.com/glg-public/glg-simple-movie-app/blob/main/server/services/MovieDB.ts"
    click MockHandlers "https://github.com/glg-public/glg-simple-movie-app/blob/main/server/mocks/handlers.ts"
    click NodeMocks "https://github.com/glg-public/glg-simple-movie-app/blob/main/server/mocks/node.ts"
    click AllJSON "https://github.com/glg-public/glg-simple-movie-app/blob/main/server/mocks/data/all.json"
    click MovieJSON "https://github.com/glg-public/glg-simple-movie-app/blob/main/server/mocks/data/movie/*.json"
    click TVJSON "https://github.com/glg-public/glg-simple-movie-app/blob/main/server/mocks/data/tv/*.json"

    %% Click events for Dev Env
    click Dockerfile "https://github.com/glg-public/glg-simple-movie-app/blob/main/Dockerfile.dev"
    click ComposeFile "https://github.com/glg-public/glg-simple-movie-app/blob/main/docker-compose.yml"
    click PrepareScript "https://github.com/glg-public/glg-simple-movie-app/blob/main/bin/prepare-docker.sh"
    click EnvFile "https://github.com/glg-public/glg-simple-movie-app/blob/main/etc/dev.env"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef mock fill:#FFFACD,stroke:#000,stroke-width:1px
```
