# heyibad/ai-content-generator architecture

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

- Interactive diagram: https://gitdiagram.com/heyibad/ai-content-generator
- Repository: https://github.com/heyibad/ai-content-generator

## Overview

##### Main Components

A. Frontend Layer:
- Client-side Components (src/app/_components, src/components/ui)
- Dashboard Interface (src/app/dashboard)
- Authentication Pages (src/app/(auth))
- Context Providers (src/app/(context))

B. Backend Layer:
- API Routes (src/app/api)
- Authentication System
- Middleware (src/middleware.ts)

C. External Services:
- Google Generative AI
- Neon Database (Postgres)
- Cloudinary
- LemonSqueezy
- Resend Email Service
- OAuth Providers (Google, GitHub)

**┌─ Client Layer ─────────────────────┐**
- Next.js Frontend                 │
- Shadcn UI Components            │
- Context Providers               │
- Dashboard & Tools               │
- ┬───────────────────┘
- ↓
**┌─ Application Layer ─────────────────┐**
- Next.js API Routes               │
- NextAuth.js                      │
- Middleware                       │
- Business Logic                   │
- ┬───────────────────┘
- ↓
**┌─ Data & Services Layer ────────────┐**
- Neon Database                    │
- Google AI                        │
- Cloudinary                       │
- LemonSqueezy                     │
- Resend                          │
- ┘

##### Specific Component Relationships to Highlight

A. Authentication Flow:
- Flow from auth pages through NextAuth.js to OAuth providers
- Email verification system
- To user management in the database

B. Content Generation Flow:
- User input from dashboard
- API route processing
- Google AI integration
- Response handling and storage

C. Subscription System:
- LemonSqueezy integration
- Webhook handling
- Usage tracking
- Database updates

##### Important Details

A. Data Flow Indicators:
- User authentication requests
- Content generation requests
- File upload processes
- Email notifications
- Payment processing

B. Security Layers:
- API route protection
- Session management
- Middleware verification

##### Technical Implementation Details

- Relationship between Drizzle ORM and Neon Database
- Where TypeScript types are shared
- Context provider boundaries
- Where middleware intersects with requests

Remember to:
- Use clear, consistent symbols
- Version numbers for major services
- Scalability points
- Error handling paths
- Rate limits and quotas
- Caching layers if present

This will provide a comprehensive view of the system while maintaining clarity and usefulness for development and deployment purposes.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Dashboard["Dashboard Interface"]:::frontend
        AuthPages["Authentication Pages"]:::frontend
        UIComponents["UI Components"]:::frontend
        ContextProviders["Context Providers"]:::frontend
        Tools["Tools Interface"]:::frontend
        
        Dashboard --> Tools
        AuthPages --> Dashboard
    end

    subgraph Application
        APIRoutes["API Routes"]:::backend
        AuthSystem["Authentication System"]:::backend
        Middleware["Middleware"]:::backend
        BusinessLogic["Business Logic"]:::backend
        
        APIRoutes --> BusinessLogic
        AuthSystem --> APIRoutes
        Middleware --> APIRoutes
    end

    subgraph External
        DB[(Neon Database)]:::database
        GoogleAI["Google AI"]:::external
        Cloudinary["Cloudinary"]:::external
        LemonSqueezy["LemonSqueezy"]:::external
        Resend["Resend Email"]:::external
        OAuth["OAuth Providers"]:::external
    end

    %% Client to Application
    Dashboard --> APIRoutes
    AuthPages --> AuthSystem
    Tools --> BusinessLogic

    %% Application to External
    BusinessLogic --> GoogleAI
    BusinessLogic --> DB
    AuthSystem --> OAuth
    BusinessLogic --> Cloudinary
    BusinessLogic --> LemonSqueezy
    BusinessLogic --> Resend

    %% Click Events
    click Dashboard "https://github.com/heyibad/ai-content-generator/tree/main/src/app/dashboard"
    click AuthPages "https://github.com/heyibad/ai-content-generator/tree/main/src/app/(auth)"
    click UIComponents "https://github.com/heyibad/ai-content-generator/tree/main/src/components/ui"
    click ContextProviders "https://github.com/heyibad/ai-content-generator/tree/main/src/app/(context)"
    click Tools "https://github.com/heyibad/ai-content-generator/tree/main/src/app/dashboard/tool"
    click AuthSystem "https://github.com/heyibad/ai-content-generator/tree/main/src/app/api/auth"
    click Middleware "https://github.com/heyibad/ai-content-generator/blob/main/src/middleware.ts"
    click BusinessLogic "https://github.com/heyibad/ai-content-generator/blob/main/src/helpers/Ai.ts"

    %% Styling
    classDef frontend fill:#3b82f6,color:#fff
    classDef backend fill:#22c55e,color:#fff
    classDef database fill:#6b7280,color:#fff
    classDef external fill:#a855f7,color:#fff
    
    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Service"]:::backend
        Database["Database"]:::database
        External["External Service"]:::external
    end
```
