# cnrad/lanyard-profile-readme architecture

> Architecture diagram of the GitHub repository cnrad/lanyard-profile-readme, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cnrad/lanyard-profile-readme
- Repository: https://github.com/cnrad/lanyard-profile-readme

## Overview

##### Main components
- Frontend: This includes the primary Next.js pages (src/app/page.tsx and src/app/layout.tsx) and React-based UI components (e.g., src/components/popover.tsx and the card rendering utilities in src/utils/renderCard.tsx).
- Backend/API: The API endpoints under src/app/api (notably, the dynamic API route at src/app/api/[...id]/route.ts) are responsible for processing incoming requests (with various query parameters) and delivering the customizable badge.
- Utility & Library Functions: The project has several utility modules spread across src/lib and src/utils (e.g., handling Discord data types, helper functions, Redis operations in redis.ts, converting data formats, etc.). These provide the necessary logic, data processing, and transformation to construct the badge.

##### Relationships and interactions
- That the API endpoint processes the incoming URL with query parameters (theme, bg, borderRadius, etc.) and then invokes the rendering logic.
- That utility libraries are used during the processing to convert responses, handle type-checking, interact with possible caching mechanisms (e.g., Redis in src/utils/redis.ts), and generate the final visual card.
- How external requests (to Lanyard/Discord) might augment the data required when rendering the badge.

##### Architectural patterns and design principles
- Modular Design: Based on the file tree structure, emphasize that components, utilities, and configuration files (Next.js, ESLint, Tailwind, etc.) are isolated modules. This makes the project extensible.

##### Relevant technologies and frameworks
- Next.js: As the core framework for rendering the application and handling serverless API routes.
- Tailwind CSS: For styling and visual customization of the badge.
- Typescript: Noted by TypeScript configuration files (tsconfig.json) and type definition files (next-env.d.ts).
- External APIs: Lanyard and Discord API interactions.
- Additional developer tools: ESLint, Prettier for code quality, and GitHub Actions for automation (see .github/workflows).

##### Instructing the principal software engineer
- Interaction point with external services (Lanyard/Discord) where presence data is fetched and possibly cached.
- Link the UI rendering components (React components in src/app and src/components) that are responsible for assembling the badge.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["User / GitHub Profile"]:::client

    %% Frontend UI Layer
    subgraph "Frontend UI Layer"
        Layout["Next.js Layout (page.tsx)"]:::frontend
        Page["Next.js Page (layout.tsx)"]:::frontend
        Popover["Popover Component (popover.tsx)"]:::frontend
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        API["API Endpoint (route.ts)"]:::api
    end

    %% Utility & Libraries
    subgraph "Utility & Libraries"
        Parameters["Parameter Processing (parameters.ts)"]:::util
        Helpers["Helper Functions (helpers.ts)"]:::util
        Utils["General Utilities (utils.ts)"]:::util
        LanyardTypes["Discord Data Types (LanyardTypes.ts)"]:::util
        Actions["Action Handlers (actions.ts)"]:::util
        Redis["Redis Operations (redis.ts)"]:::util
        Snowflake["Snowflake Conversions (snowflake.ts)"]:::util
        ToBase64["Base64 Conversions (toBase64.ts)"]:::util
        RenderCard["Card Rendering Utility (renderCard.tsx)"]:::util
    end

    %% External Service
    subgraph "External Service"
        Discord["Lanyard/Discord API"]:::external
    end

    %% Data Flow
    Client -->|"badge-request"| API

    %% UI Rendering Flow
    Layout -->|"renders"| Page
    Page -->|"includes"| Popover

    %% API processing chain
    API -->|"processes"| Parameters
    Parameters -->|"validates"| Helpers
    API -->|"caches"| Redis
    Helpers -->|"utilizes"| Utils
    Helpers -->|"uses"| LanyardTypes
    Helpers -->|"triggers"| Actions
    Utils -->|"renders badge"| RenderCard
    RenderCard -->|"converts"#1| Snowflake
    RenderCard -->|"encodes"#2| ToBase64

    %% External API Integration
    API -->|"fetches presence"| Discord
    Discord -->|"returns data"| Helpers

    %% Badge Assembly Response
    RenderCard -->|"badge image"| API
    API -->|"sends response"| Client

    %% UI Layer uses Card Rendering Utility
    Page -->|"assembles badge"| RenderCard

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:2px;
    classDef frontend fill:#ccf,stroke:#333,stroke-width:2px;
    classDef api fill:#cfc,stroke:#333,stroke-width:2px;
    classDef util fill:#ffc,stroke:#333,stroke-width:2px;
    classDef external fill:#fee,stroke:#333,stroke-width:2px;

    %% Click Events for Component Mapping
    click Page "https://github.com/cnrad/lanyard-profile-readme/blob/main/src/app/page.tsx"
    click Layout "https://github.com/cnrad/lanyard-profile-readme/blob/main/src/app/layout.tsx"
    click Popover "https://github.com/cnrad/lanyard-profile-readme/blob/main/src/components/popover.tsx"
    click RenderCard "https://github.com/cnrad/lanyard-profile-readme/blob/main/src/utils/renderCard.tsx"
    click API "https://github.com/cnrad/lanyard-profile-readme/blob/main/src/app/api/[...id]/route.ts"
    click Utils "https://github.com/cnrad/lanyard-profile-readme/blob/main/src/lib/utils.ts"
    click LanyardTypes "https://github.com/cnrad/lanyard-profile-readme/blob/main/src/utils/LanyardTypes.ts"
    click Helpers "https://github.com/cnrad/lanyard-profile-readme/blob/main/src/utils/helpers.ts"
    click Actions "https://github.com/cnrad/lanyard-profile-readme/blob/main/src/utils/actions.ts"
    click Parameters "https://github.com/cnrad/lanyard-profile-readme/blob/main/src/utils/parameters.ts"
    click Redis "https://github.com/cnrad/lanyard-profile-readme/blob/main/src/utils/redis.ts"
    click Snowflake "https://github.com/cnrad/lanyard-profile-readme/blob/main/src/utils/snowflake.ts"
    click ToBase64 "https://github.com/cnrad/lanyard-profile-readme/blob/main/src/utils/toBase64.ts"
```
