# crowell-tailord/no-two-paths architecture

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

- Interactive diagram: https://gitdiagram.com/crowell-tailord/no-two-paths
- Repository: https://github.com/crowell-tailord/no-two-paths

## Overview

##### Project Overview
- This project is an open-ended, Choose Your Own Adventure story game that uses Next.js as the frontend framework and integrates AI elements (ChatGPT via OpenAI and Midjourney through The Next Leg) for generating story content and scene images. The game is built to present a unique story experience through dynamic choices and AI-generated content.

##### Key Components
a. Frontend
- Next.js application: All user-facing pages and React components reside within the "app" directory.
- Components: Elements such as FancyLoader, NFTdeets, Popup, Story, and StoryImage are located in app/components.
- Layout: The application layout is managed by components under app/layout (Header.jsx, Footer.jsx, etc.) and styling in app/globals.css.

b. Backend / API Endpoints
- API Routes: Located under app/api, this folder contains separate endpoints:
- app/api/ai/route.js – Handles interactions with ChatGPT for generating story text or choices.
- app/api/image/route.js – Handles calls to Midjourney (via The Next Leg) for scene image generation.
- These endpoints represent the core AI functionality and dynamic content creation process.

c. Data and Functional Logic
- Data: The app/data folder holds JSON story files (huntOneStory.json, rebel211.json) that are used as static starting points for story generation.
- Business Logic: The file app/func/transformations.js and utilities in app/util (such as Config.js and fonts.js) encapsulate logic used throughout the application including transformations, configuration, and possibly additional processing of story data.

d. Public Assets & Configuration
- Public assets folder: Contains images, audio files (e.g., notif.m4a), and other static resources used by the frontend.
- Configuration Files: Next.js configuration (next.config.js), Tailwind CSS configuration (tailwind.config.js, postcss.config.js) and other project configuration files (jsconfig.json, package.json, etc.), which indicate build and deployment settings.

##### Relationships and Interactions
- The browser (client) communicates with the Next.js server rendering the views.
- User actions on pages trigger calls to API endpoints via client-side fetch or other routing mechanisms:
- The AI endpoint is responsible for generating dynamic text and story choices.
- The Image endpoint interfaces with external AI art services to produce scene images.
- The frontend layout and components fetch and integrate data from static JSON files (located in app/data) and dynamic API responses.
- Utility modules (app/util, app/func) support both frontend formatting and backend processing.

##### Architectural Patterns and Techniques
- Next.js Server-Side Rendering and API Routing: The project leverages Next.js pages and API routes for user interaction and backend logic.
- Separation of Concerns: Frontend (UI components and layouts), API endpoints (serving AI interactions), and business logic (functions and transformations) are neatly organized in separate directories.
- Integration with External Services: Direct interactions with ChatGPT and Midjourney are abstracted behind dedicated API endpoints.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    User["User Browser"]:::external

    %% Frontend Layer
    subgraph "Next.js Frontend"
        direction TB
        FE1["Pages & Layout"]:::frontend
        FE2["UI Components"]:::frontend
    end

    %% Frontend - Pages & Layout Details
    subgraph "Pages & Layout"
        direction TB
        Page["Page"]:::frontend
        Layout["Layout"]:::frontend
        Header["Header"]:::frontend
        Footer["Footer"]:::frontend
    end

    %% Frontend - UI Components Details
    subgraph "UI Components"
        direction TB
        FancyLoader["FancyLoader"]:::frontend
        NFTdeets["NFTdeets"]:::frontend
        Popup["Popup"]:::frontend
        Story["Story"]:::frontend
        StoryImage["StoryImage"]:::frontend
    end

    %% API Endpoints Layer
    subgraph "API Endpoints"
        direction TB
        AIEndpoint["AI Endpoint"]:::backend
        ImageEndpoint["Image Endpoint"]:::backend
    end

    %% Data Storage
    subgraph "Static Story Data"
        direction TB
        HuntOne["huntOneStory.json"]:::data
        Rebel211["rebel211.json"]:::data
    end

    %% Business Logic & Utilities
    subgraph "Business Logic & Utilities"
        direction TB
        Transform["Transformations"]:::util
        ConfigUtil["Config"]:::util
        FontsUtil["Fonts"]:::util
    end

    %% Public Assets & Static Resources
    PublicAssets["Public Assets"]:::config

    %% Project Configuration Files
    ConfigFiles["Configuration Files"]:::config

    %% External Services
    subgraph "External AI Services"
        direction TB
        ChatGPT["ChatGPT (OpenAI)"]:::external
        Midjourney["Midjourney (The Next Leg)"]:::external
    end

    %% Connections
    User -->|"triggers"| FE1
    User -->|"triggers"| FE2

    %% Connecting frontend layout nodes to Pages & Layout group
    FE1 --> Page
    FE1 --> Layout
    FE1 --> Header
    FE1 --> Footer

    %% Connecting frontend components nodes to UI Components group
    FE2 --> FancyLoader
    FE2 --> NFTdeets
    FE2 --> Popup
    FE2 --> Story
    FE2 --> StoryImage

    %% Frontend calls API endpoints on user actions
    FE1 -->|"fetches data"| AIEndpoint
    FE1 -->|"fetches images"| ImageEndpoint
    FE2 -->|"renders story from"| HuntOne
    FE2 -->|"renders story from"| Rebel211

    %% API endpoints interactions with external services
    AIEndpoint -->|"calls"| ChatGPT
    ImageEndpoint -->|"calls"| Midjourney

    %% Frontend leverages Business Logic & Utilities
    FE1 -- "uses" --> Transform
    FE1 -- "uses" --> ConfigUtil
    FE1 -- "uses" --> FontsUtil
    FE2 -- "formats data using" --> Transform

    %% Project configuration and public assets
    FE1 --- PublicAssets
    FE1 --- ConfigFiles

    %% Click Events for Frontend (Pages & Layout)
    click Page "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/page.js"
    click Layout "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/layout.js"
    click Header "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/layout/Header.jsx"
    click Footer "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/layout/Footer.jsx"
    click FE1 "https://github.com/crowell-tailord/no-two-paths/tree/origin/app"
    
    %% Click Events for UI Components
    click FancyLoader "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/components/FancyLoader.jsx"
    click NFTdeets "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/components/NFTdeets.jsx"
    click Popup "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/components/Popup.jsx"
    click Story "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/components/Story.jsx"
    click StoryImage "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/components/StoryImage.jsx"
    click FE2 "https://github.com/crowell-tailord/no-two-paths/tree/origin/app/components"

    %% Click Events for API Endpoints
    click AIEndpoint "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/api/ai/route.js"
    click ImageEndpoint "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/api/image/route.js"

    %% Click Events for Static Story Data
    click HuntOne "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/data/huntOneStory.json"
    click Rebel211 "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/data/rebel211.json"
    click PublicAssets "https://github.com/crowell-tailord/no-two-paths/tree/origin/public"

    %% Click Events for Business Logic & Utilities
    click Transform "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/func/transformations.js"
    click ConfigUtil "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/util/Config.js"
    click FontsUtil "https://github.com/crowell-tailord/no-two-paths/blob/origin/app/util/fonts.js"

    %% Click Events for Configuration Files
    click ConfigFiles "https://github.com/crowell-tailord/no-two-paths/blob/origin/next.config.js"

    %% Class Definitions
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef data fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef util fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef config fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
