# cortez/routinesai architecture

> Architecture diagram of the GitHub repository cortez/routinesai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cortez/routinesai
- Repository: https://github.com/cortez/routinesai

## Overview

##### Main Components

a. Client-Side Layer:
- Pages (show the main index page)
- Styles (indicate Tailwind CSS integration)

b. API Layer:
- Edge Function container (/api/generate endpoint)
- OpenAIStream utility

c. External Services:
- Vercel Edge Runtime

##### Component Relationships

- User Interface → API Routes (HTTP requests)
- API Routes → OpenAI API (External API calls)
- OpenAI API → Edge Function (Response streaming)
- Edge Function → User Interface (Streamed results)

##### Specific Implementation Details

- TypeScript implementation (indicated by .tsx files)
- Server-side components
- Client-side components
- Streaming functionality

**[User Interface Layer]**
- ↓
**[Next.js API Routes Layer]**
- ↓
**[Edge Functions Layer]**
- ↓
**[External Services Layer]**

##### Additional Elements

- Technology badges: Next.js, TypeScript, OpenAI, Vercel
- Environment boundaries (Browser/Edge/External)

##### Key Architectural Aspects to Emphasize

- Edge Function deployment
- Streaming response handling
- API route implementation
- Component hierarchy
- External service integration

##### Technical Details to Note

- Separation between client and server code
- Where TypeScript types are implemented
- Streaming utility implementation
- Entry points for API calls

Remember to:
- Keep components grouped logically
- Clear data flow directions
- Where Edge Functions are utilized
- Streaming nature of the application
- Security boundaries and API integration points

This architecture should emphasize the modern web application aspects: Edge Functions, streaming responses, and AI integration, while maintaining clarity about the application's primary purpose of generating workout plans.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Frontend Layer"
        UI[User Interface]
        HC[Header]:::component
        CC[Choices]:::component
        IC[Input]:::component
        LC["Loading Dots"]:::component
        MP["Main Page"]:::page
        AC["App Config"]:::page
        DC["Document Config"]:::page
        GS["Global Styles"]:::styles
        LS["Loading Styles"]:::styles
        TC["Tailwind Config"]:::styles
    end

    subgraph "API Layer"
        EF["Edge Function"]:::api
        OS["OpenAI Stream Utility"]:::util
    end

    subgraph "External Services"
        OAI["OpenAI GPT-3.5-turbo-instruct"]:::external
        VER["Vercel Edge Runtime"]:::external
    end

    UI --> HC
    UI --> CC
    UI --> IC
    UI --> LC
    UI --> MP
    MP --> EF
    EF --> OS
    OS --> OAI
    OAI -.-> OS
    OS -.-> EF
    EF -.-> UI
    EF --> VER

    classDef component fill:#a8d5ff,stroke:#333
    classDef page fill:#95ccff,stroke:#333
    classDef styles fill:#ffcce6,stroke:#333
    classDef api fill:#98FB98,stroke:#333
    classDef util fill:#DDA0DD,stroke:#333
    classDef external fill:#FFD700,stroke:#333

    click HC "https://github.com/cortez/routinesai/blob/main/components/Header.tsx"
    click CC "https://github.com/cortez/routinesai/blob/main/components/Choices.tsx"
    click IC "https://github.com/cortez/routinesai/blob/main/components/Input.tsx"
    click LC "https://github.com/cortez/routinesai/blob/main/components/LoadingDots.tsx"
    click MP "https://github.com/cortez/routinesai/blob/main/pages/index.tsx"
    click AC "https://github.com/cortez/routinesai/blob/main/pages/_app.tsx"
    click DC "https://github.com/cortez/routinesai/blob/main/pages/_document.tsx"
    click EF "https://github.com/cortez/routinesai/blob/main/pages/api/generate.ts"
    click OS "https://github.com/cortez/routinesai/blob/main/utils/OpenAIStream.ts"
    click GS "https://github.com/cortez/routinesai/blob/main/styles/globals.css"
    click LS "https://github.com/cortez/routinesai/blob/main/styles/loading-dots.module.css"
    click TC "https://github.com/cortez/routinesai/blob/main/tailwind.config.js"
```
