# cloudflare/next-on-pages architecture

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

- Interactive diagram: https://gitdiagram.com/cloudflare/next-on-pages
- Repository: https://github.com/cloudflare/next-on-pages

## Overview

##### Main Components

a. Core Components:
- CLI Tool Interface
- Build System
- Development Server
- ESLint Plugin
- Next.js Integration Layer
- Cloudflare Pages Integration Layer

b. Supporting Components:
- Cache Management System
- Router Handler
- Worker File Generator
- Request Context Manager
- Static Assets Handler

**┌─ Developer Interface Layer ─────────────────┐**
- CLI Tool                                 │
- ESLint Plugin                           │
- ┬───────────────────────┘
- ↓
**┌─ Build Processing Layer ───────────────────┐**
- Build Application System                 │
- Vercel Output Processing                 │
- Worker File Generation                   │
- ┬───────────────────────┘
- ↓
**┌─ Runtime Layer ────────────────────────────┐**
- Request Handler                          │
- Cache Management                         │
- Route Matcher                            │
- ┬───────────────────────┘
- ↓
**┌─ Platform Integration Layer ───────────────┐**
- Cloudflare Pages Integration            │
- Edge Runtime Adapters                   │
- ┘

##### Key Relationships to Highlight

- Bidirectional flow between CLI and Build System
- Data flow from Build System to Worker Generator
- Cache interaction patterns
- Routing system's connections
- Integration points with Cloudflare Pages

##### Implementation Details

- File processing flow
- Build artifact generation
- Cache management strategy
- Request handling pipeline
- Static asset processing

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef developer fill:#3498db,color:white
    classDef build fill:#2ecc71,color:white
    classDef runtime fill:#e67e22,color:white
    classDef platform fill:#9b59b6,color:white
    classDef support fill:#95a5a6,color:white

    %% Developer Interface Layer
    subgraph DevLayer["Developer Interface Layer"]
        CLI["CLI Tool Interface"]
        ESLint["ESLint Plugin"]
        DevServer["Development Server"]
    end
    
    %% Build Processing Layer
    subgraph BuildLayer["Build Processing Layer"]
        BuildSystem["Build Application System"]
        WorkerGen["Worker File Generator"]
        VercelProc["Vercel Output Processing"]
    end
    
    %% Runtime Layer
    subgraph RuntimeLayer["Runtime Layer"]
        ReqHandler["Request Handler"]
        CacheSystem["Cache Management System"]
        RouterHandler["Router Handler"]
        ReqContext["Request Context Manager"]
        StaticAssets["Static Assets Handler"]
    end
    
    %% Platform Integration Layer
    subgraph PlatformLayer["Platform Integration Layer"]
        CloudflarePages["Cloudflare Pages Integration"]
        EdgeRuntime["Edge Runtime Adapters"]
    end
    
    %% Relationships
    CLI --> BuildSystem
    BuildSystem --> WorkerGen
    BuildSystem --> VercelProc
    WorkerGen --> CloudflarePages
    VercelProc --> EdgeRuntime
    
    ReqHandler --> RouterHandler
    ReqHandler --> CacheSystem
    ReqHandler --> ReqContext
    RouterHandler --> StaticAssets
    
    EdgeRuntime --> ReqHandler
    
    DevServer --> BuildSystem
    ESLint --> BuildSystem
    
    %% Click Events
    click CLI "https://github.com/cloudflare/next-on-pages/blob/main/packages/next-on-pages/src/cli.ts"
    click BuildSystem "https://github.com/cloudflare/next-on-pages/tree/main/packages/next-on-pages/src/buildApplication/"
    click DevServer "https://github.com/cloudflare/next-on-pages/tree/main/internal-packages/next-dev/"
    click ESLint "https://github.com/cloudflare/next-on-pages/tree/main/packages/eslint-plugin-next-on-pages/"
    click CacheSystem "https://github.com/cloudflare/next-on-pages/tree/main/packages/next-on-pages/templates/cache/"
    click RouterHandler "https://github.com/cloudflare/next-on-pages/blob/main/packages/next-on-pages/templates/_worker.js/routes-matcher.ts"
    click WorkerGen "https://github.com/cloudflare/next-on-pages/blob/main/packages/next-on-pages/src/buildApplication/buildWorkerFile.ts"
    click ReqContext "https://github.com/cloudflare/next-on-pages/blob/main/packages/next-on-pages/src/api/getRequestContext.ts"
    click StaticAssets "https://github.com/cloudflare/next-on-pages/blob/main/packages/next-on-pages/templates/_worker.js/utils/images.ts"
    
    %% Styling Classes
    class CLI,ESLint,DevServer developer
    class BuildSystem,WorkerGen,VercelProc build
    class ReqHandler,CacheSystem,RouterHandler,ReqContext,StaticAssets runtime
    class CloudflarePages,EdgeRuntime platform
    
    %% Legend
    subgraph Legend
        Dev["Developer Components"]:::developer
        Build["Build Components"]:::build
        Run["Runtime Components"]:::runtime
        Plat["Platform Components"]:::platform
    end
```
