# amannn/next-intl architecture

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

## Overview

##### Main Components Overview

a) Core Library Components:
- Message Processing System
- Formatting Engine
- Routing System
- Provider System

b) Integration Layers:
- Next.js App Router Integration
- Next.js Pages Router Integration
- React Integration Layer

##### Detailed Component Breakdown

A. Message Processing System
**┌─────────────────────────┐**
- Message Processing    │
- ┤
- ICU Message Parser    │
- Translation Resolver  │
- Namespace Handler     │
- ┘

B. Provider Architecture
**┌─────────────────────────┐**
- Provider System      │
- ┤
- IntlProvider         │
- ClientProvider       │
- ServerProvider       │
- ┘

C. Formatting Engine
**┌─────────────────────────┐**
- Formatting Engine     │
- ┤
- Date/Time Formatter   │
- Number Formatter      │
- Relative Time Handler │
- ┘

##### Integration Points

Clear integration points with:
- Next.js App Router
- React Components
- Message Storage
- Middleware Layer

##### Key Features Implementation

Specialized features:
**┌─────────────────────────┐**
- Feature Modules       │
- ┤
- i18n Routing         │
- Type Safety System   │
- Message Compilation  │
- Hooks System         │
- ┘

##### Environment Support

Different execution contexts:
**┌─────────────────────────┐**
- Environment Handlers   │
- ┤
- Server Components    │
- Client Components    │
- Static Generation    │
- ┘

##### Performance Optimization Paths

Indicators for:
- Static optimization opportunities
- Caching layers
- Bundle splitting points

##### Testing Boundaries

Testing boundaries with:
- Unit test zones
- Integration test areas
- E2E test coverage

Remember to include:
- Version compatibility indicators
- Configuration flow
- Plugin architecture
- Message loading pipeline
- Locale detection and handling

This system design should help developers understand both the high-level architecture and the detailed implementation of the next-intl library while maintaining clarity about how different parts interact with each other.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core ["Core Library Components"]
        MP["Message Processing System"]
        FE["Formatting Engine"]
        RS["Routing System"]
        PS["Provider System"]
    end

    subgraph MessageProcessing ["Message Processing"]
        Parser["ICU Message Parser"]
        Resolver["Translation Resolver"]
        NSHandler["Namespace Handler"]
    end

    subgraph Providers ["Provider Architecture"]
        IntlProv["IntlProvider"]
        ClientProv["ClientProvider"]
        ServerProv["ServerProvider"]
    end

    subgraph Formatting ["Formatting Engine"]
        DateTime["Date/Time Formatter"]
        Number["Number Formatter"]
        RelTime["Relative Time Handler"]
    end

    subgraph Integration ["Integration Layers"]
        AppRouter["Next.js App Router"]
        PagesRouter["Next.js Pages Router"]
        ReactLayer["React Integration"]
    end

    subgraph Environment ["Environment Handlers"]
        ServerComp["Server Components"]
        ClientComp["Client Components"]
        StaticGen["Static Generation"]
    end

    subgraph Features ["Feature Modules"]
        i18nRouting["i18n Routing"]
        TypeSafety["Type Safety System"]
        MsgCompile["Message Compilation"]
        Hooks["Hooks System"]
    end

    MP --> MessageProcessing
    PS --> Providers
    FE --> Formatting
    RS --> i18nRouting

    Parser --> Resolver
    Resolver --> NSHandler

    IntlProv --> ClientProv
    IntlProv --> ServerProv

    DateTime --> RelTime
    Number --> RelTime

    AppRouter --> ServerComp
    PagesRouter --> ClientComp
    ReactLayer --> StaticGen

    classDef core fill:#2374ab
    classDef integration fill:#2a9d8f
    classDef feature fill:#e76f51
    classDef env fill:#8338ec

    class MP,FE,RS,PS core
    class AppRouter,PagesRouter,ReactLayer integration
    class i18nRouting,TypeSafety,MsgCompile,Hooks feature
    class ServerComp,ClientComp,StaticGen env

    %% Click events for component mapping
    click MP "https://github.com/amannn/next-intl/blob/main/packages/use-intl/src/core/createTranslator.tsx"
    click Parser "https://github.com/amannn/next-intl/blob/main/packages/use-intl/src/core/AbstractIntlMessages.tsx"
    click NSHandler "https://github.com/amannn/next-intl/blob/main/packages/use-intl/src/core/resolveNamespace.tsx"
    click ClientProv "https://github.com/amannn/next-intl/blob/main/packages/next-intl/src/shared/NextIntlClientProvider.tsx"
    click ServerProv "https://github.com/amannn/next-intl/blob/main/packages/next-intl/src/react-server/NextIntlClientProviderServer.tsx"
    click IntlProv "https://github.com/amannn/next-intl/blob/main/packages/use-intl/src/react/IntlProvider.tsx"
    click FE "https://github.com/amannn/next-intl/blob/main/packages/use-intl/src/core/createFormatter.tsx"
    click DateTime "https://github.com/amannn/next-intl/blob/main/packages/use-intl/src/core/DateTimeFormatOptions.tsx"
    click Number "https://github.com/amannn/next-intl/blob/main/packages/use-intl/src/core/NumberFormatOptions.tsx"
    click RelTime "https://github.com/amannn/next-intl/blob/main/packages/use-intl/src/core/RelativeTimeFormatOptions.tsx"
    click ReactLayer "https://github.com/amannn/next-intl/tree/main/packages/next-intl/src/navigation/react-client/"
    click AppRouter "https://github.com/amannn/next-intl/tree/main/packages/next-intl/src/navigation/react-server/"
    click RS "https://github.com/amannn/next-intl/blob/main/packages/next-intl/src/middleware/middleware.tsx"
    click i18nRouting "https://github.com/amannn/next-intl/blob/main/packages/next-intl/src/routing/defineRouting.tsx"
    click ServerComp "https://github.com/amannn/next-intl/tree/main/packages/next-intl/src/server/react-server/"
    click ClientComp "https://github.com/amannn/next-intl/tree/main/packages/next-intl/src/server/react-client/"
```
