# nergy101/retro-ranker architecture

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

- Interactive diagram: https://gitdiagram.com/nergy101/retro-ranker
- Repository: https://github.com/nergy101/retro-ranker

## Overview

##### Project Type and Purpose
- That Retro Ranker is a full-stack application. Its main purpose is to provide a user-friendly interface for comparing retro handheld gaming devices using data-driven specifications, performance metrics, and side-by-side comparisons.
- That it is built using the Fresh framework, which leverages server-side rendering combined with interactive “islands” for client-side behaviors.

##### Main Components
a. Frontend:
- Components: Containing reusable UI elements (e.g., Device Cards, SEO, shared utilities).
- Islands: Interactive client-side components like LayoutSelector, TagTypeahead, TimelineContent, and various auth and chart-related islands that provide reactive, stateful behaviors.
- Routes: The pages and API endpoints under the routes directory (including both the public pages and authentication endpoints).
b. Backend/API:
- API endpoints are structured under routes/api. They handle user authentication (sign-in, sign-out, sign-up) and device-related operations such as fetching device data and comparisons.
- The server entry point (main.ts) bootstraps the application and routing.
c. Data and Models:
- Data source and device parser/patcher scripts handle the fetching, parsing, and updating of the retro handhelds' data.
d. Services:
- Integrations with external systems like Pocketbase (for storage/user data) and Umami (for analytics) are found under the services directory.
e. Static Assets and Scripts:
- Static directory contains assets such as images, stylesheets (e.g., PicoCSS), and additional media files.
- Scripts provide utility functions for tasks like generating device entries, scraping images, or generating sitemaps.
f. DevOps and Deployment:
- The .devcontainer, Dockerfile, and GitHub workflows (in .github) indicate containerization and CI/CD practices for development and deployment.
- Deno tasks (e.g., start, build, check, preview) indicate standardized commands for different stages in the development and deployment lifecycle.

##### Relationships and Interactions
- User requests enter through the main entry point (main.ts) and are routed based on the URL:
- Regular dynamic pages are rendered via routes (_layout, _app) while interactive components use the islands pattern.
- API endpoints under routes/api are invoked for actions like authentication and device queries.
- The frontend communicates with backend services when dynamic data is required. This interaction is usually a REST-like call, as suggested by the sign-in, sign-up, and device fetch operations.
- Data flows from the Data folder through business logic in services and parsers to the UI components which then display device comparisons and performance metrics.
- External services (Pocketbase, Umami analytics) are integrated through dedicated service modules, indicating clear separation of concerns for data persistence and analytics.

## Diagram (Mermaid)

```mermaid
flowchart TD
    user["User"]:::external

    subgraph "Frontend"
        direction TB
        compUI["Components (UI Elements)"]:::frontend
        islands["Interactive Islands"]:::frontend
        routes["Routes (Pages & API Endpoints)"]:::frontend
    end

    subgraph "Backend/Services"
        direction TB
        server["Server Entry Point (main.ts)"]:::backend
        dataLayer["Data Models & Parsing (Data)"]:::backend
        integrations["External Services (Pocketbase & Umami)"]:::external
        utility["Utility Scripts"]:::utility
        staticAssets["Static Assets"]:::backend
    end

    subgraph "DevOps & Deployment"
        direction TB
        devops["DevOps Configurations"]:::devops
    end

    user -->|"interacts"| compUI
    user -->|"interacts"| islands
    user -->|"navigates"| routes

    routes -->|"API_call"| server
    server -->|"fetch_update"| dataLayer
    server -->|"integrates_with"| integrations
    server -->|"utilizes"| utility
    server -->|"serves"| staticAssets
    devops -->|"deploys"| server

    click compUI "https://github.com/nergy101/retro-ranker/blob/main/components/DeviceLinks.tsx"
    click compUI "https://github.com/nergy101/retro-ranker/blob/main/components/SEO.tsx"
    
    click islands "https://github.com/nergy101/retro-ranker/blob/main/islands/LayoutSelector.tsx"
    click islands "https://github.com/nergy101/retro-ranker/blob/main/islands/TagTypeahead.tsx"
    click islands "https://github.com/nergy101/retro-ranker/blob/main/islands/TimelineContent.tsx"
    
    click routes "https://github.com/nergy101/retro-ranker/blob/main/routes/_app.tsx"
    click routes "https://github.com/nergy101/retro-ranker/blob/main/routes/_layout.tsx"
    click routes "https://github.com/nergy101/retro-ranker/tree/main/routes/api/auth"
    click routes "https://github.com/nergy101/retro-ranker/tree/main/routes/api/devices"
    
    click server "https://github.com/nergy101/retro-ranker/blob/main/main.ts"
    
    click dataLayer "https://github.com/nergy101/retro-ranker/blob/main/data/device.model.ts"
    click dataLayer "https://github.com/nergy101/retro-ranker/tree/main/data/source/device-parser"
    click dataLayer "https://github.com/nergy101/retro-ranker/tree/main/data/source/device-patcher"
    
    click integrations "https://github.com/nergy101/retro-ranker/blob/main/services/pocketbase/pocketbase.service.ts"
    click integrations "https://github.com/nergy101/retro-ranker/blob/main/services/umami/umami.service.ts"
    click integrations "https://github.com/nergy101/retro-ranker/tree/main/services/devices"
    
    click utility "https://github.com/nergy101/retro-ranker/blob/main/scripts/generate-devices.ts"
    click utility "https://github.com/nergy101/retro-ranker/blob/main/scripts/scrape-images.ts"
    
    click staticAssets "https://github.com/nergy101/retro-ranker/tree/main/static/devices"
    click staticAssets "https://github.com/nergy101/retro-ranker/tree/main/static/images"
    click staticAssets "https://github.com/nergy101/retro-ranker/tree/main/static/retro-ranker-color"
    click staticAssets "https://github.com/nergy101/retro-ranker/blob/main/static/styles.css"
    
    click devops "https://github.com/nergy101/retro-ranker/blob/main/.devcontainer"
    click devops "https://github.com/nergy101/retro-ranker/tree/main/Dockerfile"
    click devops "https://github.com/nergy101/retro-ranker/blob/main/.github"
    click devops "https://github.com/nergy101/retro-ranker/blob/main/.github/workflows/deploy.yml"

    classDef frontend fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef backend fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef external fill:#f94144,stroke:#333,stroke-width:2px;
    classDef devops fill:#577590,stroke:#333,stroke-width:2px;
    classDef utility fill:#90a8d0,stroke:#333,stroke-width:2px;
```
