# khanhthanhdev/nex-crawl architecture

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

- Interactive diagram: https://gitdiagram.com/khanhthanhdev/nex-crawl
- Repository: https://github.com/khanhthanhdev/nex-crawl

## Overview

##### Main Components

a. Frontend Layer:
- Client-side Components (app/ directory structure)
- Authentication Views (/app/(auth))
- Dashboard Views (/app/(dashboard))
- Workflow Editor (/app/workflow)
- UI Components Library (/components/ui)

b. Backend Layer:
- API Routes (/app/api)
- Action Handlers (/actions)
- Workflow Execution Engine (/lib/workflow)
- Database Layer (Prisma)

c. Core Features:
- Authentication System
- Workflow Management
- Billing/Credits System
- Analytics
- Credential Management

**┌─ Client Layer ─────────────────────────┐**
- Next.js Pages & Components          │
- React Components                    │
- UI Framework                        │
- ┬────────────────────┘
- ↓
**┌─ Server Layer ──────────────────────────┐**
- Next.js API Routes                   │
- Server Actions                       │
- Workflow Executor                    │
- ┬────────────────────┘
- ↓
**┌─ Database Layer ────────────────────────┐**
- Prisma ORM                           │
- SQLite Database                      │
- ┘

##### Key Relationships to Highlight

a. Workflow System:
- Flow from task definition to execution
- Various executor types (browser automation, AI extraction, etc.)

b. Authentication Flow:
- Auth routes integration
- Protected routes and middleware checks

c. Data Flow:
- How actions connect UI to database operations
- Analytics data collection and presentation path

##### Component Relationships

- Data flow direction
- Dependencies between components
- API calls and responses
- Database queries and mutations

##### Technical Stack Labels

- Next.js 13+ (App Router)
- React
- Prisma ORM
- SQLite
- TypeScript
- Tailwind CSS

##### Additional Elements

- Version information
- External service integrations
- Scaling points

Remember to include:
- Error handling flows
- Security boundaries
- Data persistence paths
- Task execution pipeline
- Credit/billing system integration

This will provide a complete picture of the system while keeping it understandable and maintainable.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        Auth["Authentication Views"]
        Dashboard["Dashboard Views"]
        WorkflowEditor["Workflow Editor"]
        UILib["UI Components Library"]
        Analytics["Analytics UI"]
        Billing["Billing UI"]
        Credentials["Credentials UI"]
    end

    subgraph Server["Server Layer"]
        API["API Routes"]
        Actions["Action Handlers"]
        WorkflowEngine["Workflow Execution Engine"]
        TaskExecutors["Task Executors"]
        direction TB
    end

    subgraph Data["Database Layer"]
        Prisma["Prisma ORM"]
        DB[(SQLite Database)]
        direction TB
    end

    %% Component Relationships
    Auth --> API
    Dashboard --> API
    WorkflowEditor --> API
    API --> Actions
    Actions --> WorkflowEngine
    WorkflowEngine --> TaskExecutors
    Actions --> Prisma
    Prisma --> DB

    %% Click Events
    click Auth "https://github.com/khanhthanhdev/nex-crawl/tree/main//app/(auth)"
    click Dashboard "https://github.com/khanhthanhdev/nex-crawl/tree/main//app/(dashboard)"
    click WorkflowEditor "https://github.com/khanhthanhdev/nex-crawl/tree/main//app/workflow"
    click UILib "https://github.com/khanhthanhdev/nex-crawl/tree/main//components/ui"
    click Analytics "https://github.com/khanhthanhdev/nex-crawl/blob/main//app/(dashboard)/(home)/_components/ExecutionStatusChart.tsx"
    click Billing "https://github.com/khanhthanhdev/nex-crawl/tree/main//app/(dashboard)/billing"
    click Credentials "https://github.com/khanhthanhdev/nex-crawl/tree/main//app/(dashboard)/credentials"
    click API "https://github.com/khanhthanhdev/nex-crawl/tree/main//app/api/workflows"
    click Actions "https://github.com/khanhthanhdev/nex-crawl/tree/main//actions"
    click WorkflowEngine "https://github.com/khanhthanhdev/nex-crawl/blob/main//lib/workflow/executeWorkflow.ts"
    click TaskExecutors "https://github.com/khanhthanhdev/nex-crawl/tree/main//lib/workflow/executor"
    click Prisma "https://github.com/khanhthanhdev/nex-crawl/blob/main//prisma/schema.prisma"

    %% Styling
    classDef frontend fill:#3b82f6,color:#fff
    classDef server fill:#22c55e,color:#fff
    classDef database fill:#eab308,color:#fff
    classDef executor fill:#8b5cf6,color:#fff

    class Auth,Dashboard,WorkflowEditor,UILib,Analytics,Billing,Credentials frontend
    class API,Actions,WorkflowEngine server
    class TaskExecutors executor
    class Prisma,DB database

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        ServerComp["Server Component"]:::server
        ExecutorComp["Executor Component"]:::executor
        DBComp["Database Component"]:::database
    end
```
