# david-patrick-chuks/ai-content-creator architecture

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

- Interactive diagram: https://gitdiagram.com/david-patrick-chuks/ai-content-creator
- Repository: https://github.com/david-patrick-chuks/ai-content-creator

## Overview

##### Main Components

A. Frontend Layer:
- Client-Side Components
- Authentication Routes (/sign-in, /sign-up)
- Dashboard Interface
- Content Management
- Billing System
- Settings
- History Tracking

B. Application Layer:
- Next.js Server Components
- Authentication Middleware
- API Routes
- Context Providers (TotalUsageContext, UpdateCreditUsageContext)

C. Database Layer:
- Database (indicated by drizzle.config.js and schema.tsx)
- Data Models

D. External Services:
- Authentication Service (implied by auth directory structure)
- AI Service (implied by AiModal.tsx)

**┌─────────────────────────────────────────────────────────┐**
- Client Layer                         │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────┐    │
- Public    │  │    Auth     │  │  Dashboard   │    │
- Pages    │  │    Pages    │  │    Pages     │    │
- ┘  └─────────────┘  └─────────────┘    │
- ┤
- Next.js Server Layer                     │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────┐    │
- API      │  │  Server     │  │  Context    │    │
- Routes    │  │ Components  │  │ Providers   │    │
- ┘  └─────────────┘  └─────────────┘    │
- ┤
- Service Layer                            │
- ┌─────────────┐  ┌─────────────┐                     │
- Auth     │  │     AI      │                     │
- Service    │  │   Service   │                     │
- ┘  └─────────────┘                     │
- ┤
- Data Layer                               │
- ┌─────────────────────────────────┐                   │
- Database              │                   │
- (Drizzle ORM)             │                   │
- ┘                   │
- ┘

##### Key Relationships to Highlight

- Authentication flow between client, server, and auth service
- Dashboard components interaction with AI service
- Data flow between server components and database
- Context providers' relationship with components
- Middleware interactions for protected routes

##### Technical Stack Indicators

- Next.js 13+ (App Router)
- TypeScript
- Tailwind CSS
- Drizzle ORM
- Authentication System
- AI Integration

Remember to:
- Keep the main flows clear and visible
- Notes for important architectural decisions
- Scalability points
- Error handling paths
- Security boundaries

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        direction TB
        PublicPages["Public Pages"]
        AuthPages["Authentication Pages"]:::auth
        DashboardPages["Dashboard Pages"]:::dashboard
        click AuthPages "https://github.com/David-patrick-chuks/ai-content-creator/tree/main/app/(auth)"
        click DashboardPages "https://github.com/David-patrick-chuks/ai-content-creator/tree/main/app/dashboard"
    end

    subgraph Server["Next.js Server Layer"]
        direction TB
        API["API Routes"]
        ServerComp["Server Components"]
        Context["Context Providers"]:::context
        click Context "https://github.com/David-patrick-chuks/ai-content-creator/tree/main/app/(context)"
    end

    subgraph Services["Service Layer"]
        direction TB
        AuthService["Authentication Service"]
        AiService["AI Service"]:::ai
        click AiService "https://github.com/David-patrick-chuks/ai-content-creator/blob/main/utils/AiModal.tsx"
    end

    subgraph Data["Data Layer"]
        direction TB
        DB[(Database)]:::db
        Schema["Schema"]:::db
        click DB "https://github.com/David-patrick-chuks/ai-content-creator/blob/main/drizzle.config.js"
        click Schema "https://github.com/David-patrick-chuks/ai-content-creator/blob/main/utils/schema.tsx"
    end

    subgraph Dashboard["Dashboard Components"]
        direction TB
        DashLayout["Dashboard Layout"]:::dashboard
        Header["Header"]:::dashboard
        Navigation["Side Navigation"]:::dashboard
        UsageTrack["Usage Tracking"]:::dashboard
        Templates["Template System"]:::dashboard
        click DashLayout "https://github.com/David-patrick-chuks/ai-content-creator/blob/main/app/dashboard/layout.tsx"
        click Header "https://github.com/David-patrick-chuks/ai-content-creator/blob/main/app/dashboard/_components/Header.tsx"
        click Navigation "https://github.com/David-patrick-chuks/ai-content-creator/blob/main/app/dashboard/_components/SideNav.tsx"
        click UsageTrack "https://github.com/David-patrick-chuks/ai-content-creator/blob/main/app/dashboard/_components/UsageTrack.tsx"
        click Templates "https://github.com/David-patrick-chuks/ai-content-creator/blob/main/app/(data)/Template.tsx"
    end

    subgraph Auth["Auth Components"]
        direction TB
        SignIn["Sign In"]:::auth
        SignUp["Sign Up"]:::auth
        click SignIn "https://github.com/David-patrick-chuks/ai-content-creator/blob/main/app/(auth)/sign-in/[[...sign-in]]/page.tsx"
        click SignUp "https://github.com/David-patrick-chuks/ai-content-creator/blob/main/app/(auth)/sign-up/[[...sign-up]]/page.tsx"
    end

    subgraph Features["Feature Pages"]
        direction TB
        Content["Content Management"]:::feature
        Billing["Billing System"]:::feature
        Settings["Settings"]:::feature
        History["History"]:::feature
        click Content "https://github.com/David-patrick-chuks/ai-content-creator/tree/main/app/dashboard/content"
        click Billing "https://github.com/David-patrick-chuks/ai-content-creator/blob/main/app/dashboard/billing/page.tsx"
        click Settings "https://github.com/David-patrick-chuks/ai-content-creator/blob/main/app/dashboard/settings/page.tsx"
        click History "https://github.com/David-patrick-chuks/ai-content-creator/blob/main/app/dashboard/history/page.tsx"
    end

    %% Relationships
    PublicPages --> API
    AuthPages --> AuthService
    DashboardPages --> ServerComp
    API --> DB
    ServerComp --> DB
    AuthService --> DB
    Context --> ServerComp
    Context --> DashboardPages
    AiService --> API
    Dashboard --> Features
    Auth --> AuthService
    Features --> API

    %% Styles
    classDef auth fill:#f9f,stroke:#333
    classDef dashboard fill:#9cf,stroke:#333
    classDef feature fill:#fcf,stroke:#333
    classDef context fill:#cfc,stroke:#333
    classDef ai fill:#ff9,stroke:#333
    classDef db fill:#c9f,stroke:#333

    %% Legend
    subgraph Legend
        direction TB
        L1["Authentication"]:::auth
        L2["Dashboard"]:::dashboard
        L3["Features"]:::feature
        L4["Context"]:::context
        L5["AI Service"]:::ai
        L6["Database"]:::db
    end
```
