# opennextjs/opennextjs-aws architecture

> Architecture diagram of the GitHub repository opennextjs/opennextjs-aws, 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/opennextjs/opennextjs-aws
- Repository: https://github.com/opennextjs/opennextjs-aws

## Overview

##### Main Components Identification

The system should be divided into these primary components:
- Build System
- Runtime Adapters
- Core Services
- Platform Integrations

##### Connection Types

- Double lines: Data flow paths

##### Specific Implementation Details

Specialized components for:
- ISR (Incremental Static Regeneration) handling
- SSR (Server-Side Rendering) processing
- API Routes management
- Middleware processing
- Image optimization pipeline

##### Key Elements to Highlight

a) Build Process Flow:
**Next.js App → Build System → Output Packages**
- ↓
- Configuration → Adapters → Platform-Specific Bundles

b) Request Processing Flow:
**Client Request → Edge/Lambda → Router → Handler → Response**
- ↓
- Cache Layer

##### Deployment View

A separate section showing:
- AWS Lambda functions
- Edge functions
- Static assets distribution
- Cache layers
- Database interactions

##### Performance Optimization Points

Highlight:
- Warmer function locations
- Cache strategies
- Edge computing points
- Static/Dynamic split

##### Integration Points

Connections with:
- Next.js core
- AWS services
- External APIs
- Authentication systems

This system design should effectively communicate how OpenNext transforms a Next.js application into a cloud-native deployment while maintaining all Next.js 14 features and optimizing for serverless environments.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        NA[Next.js Application]
    end

    subgraph BuildSystem["Build System"]
        BP["Build Process"]:::build
        AB["Asset Bundler"]:::build
        CC["Configuration Compiler"]:::build
        SB["Server Bundle Creator"]:::build
        IOB["Image Optimization Bundle"]:::build
        
        BP --> AB
        BP --> CC
        BP --> SB
        BP --> IOB
    end

    subgraph AdapterLayer["Adapter Layer"]
        SA["Server Adapter"]:::adapter
        EA["Edge Adapter"]:::adapter
        IOA["Image Optimization Adapter"]:::adapter
        CA["Cache Adapter"]:::adapter
        MA["Middleware Adapter"]:::adapter
    end

    subgraph RuntimeLayer["Runtime Layer"]
        RH["Request Handler"]:::runtime
        RS["Routing System"]:::runtime
        CS["Cache System"]:::runtime
        MH["Main Handler"]:::runtime
    end

    subgraph PlatformLayer["Platform Integration Layer"]
        ALI["AWS Lambda Integration"]:::platform
        CFI["CloudFront Integration"]:::platform
        DI["DynamoDB Integration"]:::platform
        NS["Node.js Server Support"]:::platform
    end

    subgraph CoreComponents["Core Components"]
        HH["HTTP Handling"]:::core
        CF["Configuration"]:::core
        LS["Logging System"]:::core
    end

    NA --> BP
    BuildSystem --> AdapterLayer
    AdapterLayer --> RuntimeLayer
    RuntimeLayer --> PlatformLayer
    CoreComponents --> RuntimeLayer

    %% Component Mappings
    click BP "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/build.ts"
    click AB "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/build/createAssets.ts"
    click CC "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/build/compileConfig.ts"
    click SB "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/build/createServerBundle.ts"
    click IOB "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/build/createImageOptimizationBundle.ts"
    click SA "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/adapters/server-adapter.ts"
    click EA "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/adapters/edge-adapter.ts"
    click IOA "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/adapters/image-optimization-adapter.ts"
    click CA "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/adapters/cache.ts"
    click MA "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/adapters/middleware.ts"
    click RH "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/core/requestHandler.ts"
    click RS "https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/core/routing"
    click CS "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/core/routing/cacheInterceptor.ts"
    click MH "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/core/createMainHandler.ts"
    click ALI "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/overrides/wrappers/aws-lambda.ts"
    click CFI "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/overrides/converters/aws-cloudfront.ts"
    click DI "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/adapters/dynamo-provider.ts"
    click NS "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/overrides/wrappers/node.ts"
    click HH "https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/http"
    click CF "https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/adapters/config"
    click LS "https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/adapters/logger.ts"

    classDef build fill:#2374e1,color:white
    classDef adapter fill:#ff7f0e,color:white
    classDef runtime fill:#2ca02c,color:white
    classDef platform fill:#9467bd,color:white
    classDef core fill:#8c564b,color:white

    %% Legend
    subgraph Legend
        L1["Build Components"]:::build
        L2["Adapters"]:::adapter
        L3["Runtime Components"]:::runtime
        L4["Platform Integration"]:::platform
        L5["Core Components"]:::core
    end
```
