# takayukitooyama/runaly-front architecture

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

- Interactive diagram: https://gitdiagram.com/takayukitooyama/runaly-front
- Repository: https://github.com/takayukitooyama/runaly-front

## Overview

##### Main components
- Frontend (Next.js App): The core “app” folder under src/app holds the page-based routing. There are several routes such as (home), analyze, sign-in, and sign-up. Each route contains dedicated components – for instance, the home route includes calibration, cropping, and video upload components; the analyze route has canvas and player components.
- UI Components Library: Under src/ui, components like Button, Chart, Input, Menu, and layout elements are implemented to ensure a consistent design across the application.
- State Management: The src/lib/store directory suggests the use of custom hooks (for calibration, keypoints, video handling, etc.) to manage application-level state, a key architectural aspect.
- Database Layer: The prisma directory with the schema.prisma file indicates the project uses Prisma as an ORM to interface with the database.
- Configuration & Middleware: Next.js configuration (next.config.js), middleware.ts for server-side logic, and other configuration files (tailwind.config.cjs, tsconfig.json) are essential to describe the operational environment.

##### Relationships and interactions
- The Next.js file-based routing (via the “app” directory) directs how different URL endpoints or page components are served.
- Each page component (for example, home and analyze) is composed of smaller UI components (found under src/ui) and specialized canvas components (found in subdirectories like _canvas) that handle specific functionalities such as image annotation or drawing.
- Custom hooks and state management logic (in src/lib/store) are used by these components to share data (e.g., calibration settings or video data) and respond to user interactions.
- The Prisma schema represents the database layer, which interacts with the backend API endpoints (or server functions possibly within middleware.ts) for persistent data operations.
- Styling and performance features integrate via Tailwind CSS (using tailwind.config.cjs) and Next.js’s built‑in optimization (like next/font for Google Fonts).

##### Architectural patterns and design principles
- Component-Based UI: Each UI element is designed as an independent, reusable React component.
- File-based Routing: The Next.js app structure automatically maps directories and files to routes.
- Separation of Concerns: The division between pages (views), UI components, state management hooks, and database operations reflects good separation.
- Hook-Driven State Management: Custom hooks manage side effects and shared state across components.
- ORM for Data Persistence: Prisma encapsulates database interactions to maintain a clear separation between the business logic and the persistence layer.

##### Detailing
- Every element (especially the canvas-related components and custom hooks) is represented so that the intricate functionalities (e.g., annotation in the analyze and home routes) do not get overlooked.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Next.js Full-Stack Application"
        %% Frontend Section
        subgraph "Frontend (Next.js App)"
            direction TB
            NextApp["Next.js Frontend"]:::frontend

            subgraph "Home Route"
                direction TB
                Home["Home (Route)"]:::frontend
                Calibration["Calibration Component"]:::frontend
                Cropping["Cropping Component"]:::frontend
                VideoUpload["Video Upload Component"]:::frontend
                CanvasHome["Canvas Components (Home)"]:::frontend
            end

            subgraph "Analyze Route"
                direction TB
                Analyze["Analyze (Route)"]:::frontend
                CanvasAnalyze["Canvas Components (Analyze)"]:::frontend
                PlayerAnalyze["Player Components (Analyze)"]:::frontend
                PoseAnalyze["Pose Component (Analyze)"]:::frontend
            end

            subgraph "Auth Routes"
                direction TB
                SignIn["Sign-In Route"]:::frontend
                SignUp["Sign-Up Route"]:::frontend
            end
        end

        %% UI Components Section
        subgraph "UI Components Library"
            direction TB
            UI["UI Components (Button, Chart, Input, Menu, Layout)"]:::ui
        end

        %% State Management Section
        subgraph "State Management (Custom Hooks/Store)"
            direction TB
            Store["State Management (Custom Hooks/Store)"]:::state
        end

        %% Backend Section
        subgraph "Backend"
            direction TB
            PrismaDB["Prisma Database Layer"]:::backend
            Config["Configuration & Middleware"]:::backend
        end
    end

    %% Relationships for Frontend Routing
    NextApp -->|"routes"| Home
    NextApp -->|"routes"| Analyze
    NextApp -->|"routes"| SignIn
    NextApp -->|"routes"| SignUp

    %% Home Route Compositions
    Home -->|"composes"| Calibration
    Home -->|"composes"| Cropping
    Home -->|"composes"| VideoUpload
    Home -->|"composes"| CanvasHome

    %% Analyze Route Compositions
    Analyze -->|"composes"| CanvasAnalyze
    Analyze -->|"composes"| PlayerAnalyze
    Analyze -->|"composes"| PoseAnalyze

    %% UI Usage
    Home -->|"uses"| UI
    CanvasHome -->|"uses"| UI
    CanvasAnalyze -->|"uses"| UI
    PlayerAnalyze -->|"uses"| UI
    PoseAnalyze -->|"uses"| UI

    %% Shared State
    Home -->|"sharesState"| Store
    CanvasHome -->|"sharesState"| Store
    Analyze -->|"sharesState"| Store
    SignIn -->|"sharesState"| Store
    SignUp -->|"sharesState"| Store

    %% Backend Interactions
    Config -->|"handles"| NextApp
    Config -->|"handles"| PrismaDB
    PrismaDB -->|"dataOps"| NextApp

    %% UI and State Management Interaction
    UI -->|"interacts"| Store

    %% Click Events
    click NextApp "https://github.com/takayukitooyama/runaly-front/tree/main/src/app"
    click Home "https://github.com/takayukitooyama/runaly-front/tree/main/src/app/(home)"
    click Calibration "https://github.com/takayukitooyama/runaly-front/blob/main/src/app/(home)/Calibration.tsx"
    click Cropping "https://github.com/takayukitooyama/runaly-front/blob/main/src/app/(home)/HumanCropper.tsx"
    click VideoUpload "https://github.com/takayukitooyama/runaly-front/blob/main/src/app/(home)/VideoFileUploader.tsx"
    click CanvasHome "https://github.com/takayukitooyama/runaly-front/tree/main/src/app/(home)/_canvas"
    click CanvasAnalyze "https://github.com/takayukitooyama/runaly-front/tree/main/src/app/analyze/_canvas"
    click PlayerAnalyze "https://github.com/takayukitooyama/runaly-front/tree/main/src/app/analyze/_player"
    click SignIn "https://github.com/takayukitooyama/runaly-front/blob/main/src/app/sign-in/[[...sign-in]]/page.tsx"
    click SignUp "https://github.com/takayukitooyama/runaly-front/blob/main/src/app/sign-up/[[...sign-up]]/page.tsx"
    click UI "https://github.com/takayukitooyama/runaly-front/tree/main/src/ui"
    click Store "https://github.com/takayukitooyama/runaly-front/tree/main/src/lib/store"
    click PrismaDB "https://github.com/takayukitooyama/runaly-front/blob/main/prisma/schema.prisma"
    click Config "https://github.com/takayukitooyama/runaly-front/blob/main/src/middleware.ts"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#1565C0,stroke-width:2px;
    classDef ui fill:#FFF9C4,stroke:#F9A825,stroke-width:2px;
    classDef state fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef backend fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
```
