# akshaynstack/reactai architecture

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

- Interactive diagram: https://gitdiagram.com/akshaynstack/reactai
- Repository: https://github.com/akshaynstack/reactai

## Overview

##### Main Components

A. Frontend Layer:
- Next.js Application (App Router)
- Main UI Components (/components)
- Authentication Pages (sign-in, sign-up)
- Component Sharing Feature (/share)
- Sandpack Code Viewer Integration

B. Backend Layer:
- API Routes (/app/api)
- Claude AI Integration
- Authentication System
- Database Layer (Prisma + PostgreSQL)

**┌─ Client Browser ─────────────────────┐**

- ┌─ Next.js Frontend ──────────────┐ │
- Main App Interface            │ │
- Component Preview (Sandpack)  │ │
- Authentication UI             │ │
- ┘ │
- ┘

**┌─ API Layer ──────────────────────────┐**
- ┌─ Next.js API Routes ─────────────┐ │
- /api/generateCode             │ │
- /api/generateNextjsCode       │ │
- /api/og (OpenGraph)           │ │
- ┘ │

- ┌─ External Services ─────────────┐ │
- Claude AI Integration         │ │
- ┘ │
- ┘

**┌─ Data Persistence ──────────────────┐**
- ┌─ Prisma ORM ──────────────────┐  │

- ┬───────────────────┘  │

- ┌───────────▼───────────────────┐  │
- PostgreSQL Database      │  │
- ┘  │
- ┘

##### Additional Elements

Specific project elements:
- Shadcn UI Components integration
- Authentication middleware
- File structure organization
- Shared utilities and hooks

##### Technical Details to Note

Annotations for:
- Next.js App Router architecture
- Prisma schema and migrations
- API route implementations
- Authentication flow with [...sign-in] catch-all routes
- Component sharing functionality

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        Browser["Web Browser"]
        NextFrontend["Next.js Frontend"]:::frontend
        click NextFrontend "https://github.com/akshaynstack/reactai/blob/main/app/(main)/layout.tsx"
        
        subgraph UIComponents["UI Components"]
            MainUI["Main Components"]:::frontend
            click MainUI "https://github.com/akshaynstack/reactai/tree/main/components"
            CodeViewer["Sandpack Code Viewer"]:::frontend
            click CodeViewer "https://github.com/akshaynstack/reactai/blob/main/components/code-viewer.tsx"
            AuthUI["Authentication UI"]:::frontend
            click AuthUI "https://github.com/akshaynstack/reactai/blob/main/app/sign-in/[[...sign-in]]/page.tsx"
            ShadcnUI["Shadcn UI Components"]:::frontend
            click ShadcnUI "https://github.com/akshaynstack/reactai/tree/main/components/ui"
            CoreUI["Core UI Framework"]:::frontend
            click CoreUI "https://github.com/akshaynstack/reactai/blob/main/components/Header.tsx"
        end
    end

    subgraph APILayer["API & Services Layer"]
        direction TB
        APIRoutes["Next.js API Routes"]:::api
        click APIRoutes "https://github.com/akshaynstack/reactai/tree/main/app/api"
        
        subgraph Routes["Route Handlers"]
            GenCode["Generate Code API"]:::api
            click GenCode "https://github.com/akshaynstack/reactai/blob/main/app/api/generateCode/route.ts"
            GenNextCode["Generate Next.js Code API"]:::api
            click GenNextCode "https://github.com/akshaynstack/reactai/blob/main/app/api/generateNextjsCode/route.ts"
            OGRoute["OpenGraph API"]:::api
            click OGRoute "https://github.com/akshaynstack/reactai/blob/main/app/api/og/route.tsx"
        end
        
        ClaudeAI["Claude AI Service"]:::external
        AuthMiddleware["Auth Middleware"]:::service
        click AuthMiddleware "https://github.com/akshaynstack/reactai/blob/main/middleware.ts"
    end

    subgraph DataLayer["Data Persistence Layer"]
        PrismaORM["Prisma ORM"]:::database
        click PrismaORM "https://github.com/akshaynstack/reactai/blob/main/prisma/schema.prisma"
        PostgreSQL["PostgreSQL Database"]:::database
    end

    subgraph Utilities["Shared Utilities"]
        Utils["Utility Functions"]:::util
        click Utils "https://github.com/akshaynstack/reactai/blob/main/lib/utils.ts"
        Hooks["Custom Hooks"]:::util
        click Hooks "https://github.com/akshaynstack/reactai/blob/main/hooks/use-scroll-to.ts"
        Domain["Domain Utils"]:::util
        click Domain "https://github.com/akshaynstack/reactai/blob/main/utils/domain.ts"
    end

    %% Connections
    Browser --> NextFrontend
    NextFrontend --> UIComponents
    NextFrontend --> APIRoutes
    APIRoutes --> Routes
    GenCode & GenNextCode --> ClaudeAI
    APIRoutes --> AuthMiddleware
    AuthMiddleware --> PrismaORM
    PrismaORM --> PostgreSQL
    UIComponents --> Utils
    UIComponents --> Hooks

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#e74c3c,stroke:#c0392b,color:white
    classDef database fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#e67e22,stroke:#d35400,color:white
    classDef util fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        API["API Component"]:::api
        Service["Service Component"]:::service
        Database["Database Component"]:::database
        External["External Service"]:::external
        Utility["Utility Component"]:::util
    end
```
