# base/web architecture

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

- Interactive diagram: https://gitdiagram.com/base/web
- Repository: https://github.com/base/web

## Overview

##### Project type and purpose
- This is a monorepo full-stack web application (“Base Web”) built with Next.js (React), serving both static/SSR content and API routes.
- It presents the Base Ethereum L2 ecosystem website and supports on-chain interactions (name registration, NFTs, proofs) via Next.js API handlers.
- It includes two apps (`apps/web`, `apps/bridge`) and a shared component library (`libs/base-ui`).

##### File structure
- Root: Yarn workspaces manage multiple packages (apps, libs, tools).
- apps/web: Next.js front-end + API routes + SSR pages + e2e & unit tests + CI config + Dockerfile + public assets.
- apps/bridge: presumably a separate micro-app (lighter).
- libs/base-ui: shared UI components used by apps.
- utils & scripts: deployment, CI, Docker, build pipelines.
- Config: tsconfig, eslint, prettier at root and per-workspace.

##### README
- Confirms it’s the Base.org website: Next.js, Yarn workspaces, run via `yarn workspace @app/web dev`.
- No separate backend service—Next.js API routes handle server logic.
- On-chain interactions use ethers/ABI definitions and JSON-RPC calls to Ethereum L2.

a. Main components
1. Client (Browser/Mobile): React pages & static assets
2. Next.js Server: SSR renderer + API routes
3. Datastores:
- Key-Value store (KV) for caching/proofs
- PostgreSQL for persistent records (registrations, metadata)
4. Ethereum L2 network: RPC endpoints (Optimism) for on-chain reads/writes
5. External services:
- Cloudinary/Pinata (media upload)
- Analytics (Datadog, Bugsnag)
- CDN (serving `/public` assets)
6. Monorepo tooling: Yarn Workspaces, CI (Buildkite, GitHub Actions), Docker

b. Relationships and interactions
- Browser → Next.js:
- HTTP GET for pages (SSR/static)
- HTTP POST to `/api/*` routes
- Next.js API routes → Datastores: read/write via imported KV and Postgres clients
- Next.js API routes → Ethereum RPC: calls via ethers.js/ABI layer to L2 nodes
- Next.js → External media: generate Cloudinary URLs, Pinata uploads via helper utils
- CI pipelines → GitHub Actions/Buildkite trigger builds & Docker image publication

c. Architectural patterns/design principles
- Monorepo & Workspaces: isolate apps and shared libs with strict boundaries
- Serverless-style API: Next.js API routes run in edge/node handlers
- SSR + Static Generation: Next.js pages choose SSG or SSR for SEO/performance
- Shared design system: `libs/base-ui` for reusable UI components
- Layered separation: UI components ↔ data hooks ↔ API handlers ↔ blockchain & DB

d. Key technologies
- Next.js (React, SSR, API routes)
- Node.js, TypeScript
- Ethers.js + ABI JSON for blockchain calls
- PostgreSQL & KV store (likely Redis/Cloudflare KV) via custom datastores utils
- Cloudinary, Pinata for media
- Yarn 3 Workspaces, Docker, GitHub Actions, Buildkite

##### Detail recommendations
- API endpoints categories (registry, proofs, auth, health).
- Shared `libs/base-ui` as part of the build pipeline feeding into the frontend bundle.
- CI/CD: code in Git → Yarn build → Docker image → Deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        ClientApp["app (Pages & Components)"]:::frontend
        PublicAssets["public (Static Assets)"]:::frontend
        SharedUI["libs/base-ui (Shared Components)"]:::frontend
        BridgeApp["apps/bridge (Secondary App)"]:::frontend
        ClientApp -->|Served via| CDN
        PublicAssets -->|Served via| CDN
        SharedUI -->|Bundled into| ClientApp
        BridgeApp -->|Standalone Next.js| CDN
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        NextServer["Next.js Server (SSR & Middleware)"]:::backend
        APIRoutes["Next.js API Routes"]:::backend
        OnChain["On-chain Interaction Layer"]:::backend
        ClientApp -->|HTTP GET/POST| NextServer
        NextServer -->|Invokes| APIRoutes
        APIRoutes -->|Uses| OnChain
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        KVStore["KV Store (Caching/Proofs)"]:::data
        PostgresDB["PostgreSQL (Persistent Records)"]:::data
        APIRoutes -->|Read/Write| KVStore
        APIRoutes -->|Read/Write| PostgresDB
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Ethereum["Ethereum L2"]:::external
        Cloudinary["Cloudinary"]:::external
        Pinata["Pinata"]:::external
        Analytics["Analytics & Error Tracking"]:::external
        OnChain -->|RPC Calls| Ethereum
        APIRoutes -->|Generate URLs| Cloudinary
        APIRoutes -->|Upload Media| Pinata
        APIRoutes -->|Emit Metrics & Errors| Analytics
    end

    %% CDN
    CDN["CDN"]:::frontend
    NextServer -->|Serve Static + SSR| CDN

    %% CI/CD & Tooling
    subgraph "CI/CD & Tooling"
        direction TB
        Workspaces["Yarn Workspaces & Monorepo Tooling"]:::tooling
        CI["CI/CD Pipelines"]:::tooling
        Workspaces -->|Manages| ClientApp
        Workspaces -->|Manages| BridgeApp
        Workspaces -->|Manages| SharedUI
        CI -->|Build & Deploy| Docker
    end

    Docker["Docker Images"]:::tooling
    CI -->|Publish| Docker

    %% Click Events
    click ClientApp "https://github.com/base/web/tree/master/apps/web/app"
    click PublicAssets "https://github.com/base/web/tree/master/apps/web/public"
    click SharedUI "https://github.com/base/web/tree/master/libs/base-ui"
    click BridgeApp "https://github.com/base/web/tree/master/apps/bridge"
    click APIRoutes "https://github.com/base/web/tree/master/apps/web/app/api"
    click NextServer "https://github.com/base/web/blob/master/apps/web/middleware.ts"
    click NextServer "https://github.com/base/web/blob/master/apps/web/next.config.js"
    click OnChain "https://github.com/base/web/tree/master/apps/web/src/abis"
    click OnChain "https://github.com/base/web/blob/master/apps/web/src/hooks/useWriteContractWithReceipt.ts"
    click OnChain "https://github.com/base/web/blob/master/apps/web/src/hooks/useWriteContractsWithLogs.ts"
    click OnChain "https://github.com/base/web/blob/master/apps/web/src/utils/paymasterConfig.ts"
    click OnChain "https://github.com/base/web/blob/master/apps/web/src/utils/paymasterSponsor.ts"
    click KVStore "https://github.com/base/web/blob/master/apps/web/src/utils/datastores/kv/index.ts"
    click PostgresDB "https://github.com/base/web/blob/master/apps/web/src/utils/datastores/postgres/index.ts"
    click Cloudinary "https://github.com/base/web/blob/master/apps/web/src/api/cloudinaryUrl/route.ts"
    click Pinata "https://github.com/base/web/blob/master/apps/web/src/utils/pinata.ts"
    click Analytics "https://github.com/base/web/blob/master/apps/web/datadog.ts"
    click Analytics "https://github.com/base/web/blob/master/apps/web/src/utils/logger.ts"
    click Analytics "https://github.com/base/web/blob/master/apps/web/src/utils/metrics.ts"
    click Analytics "https://github.com/base/web/blob/master/apps/web/src/utils/bugsnag.ts"
    click Workspaces "https://github.com/base/web/blob/master/package.json"
    click CI "https://github.com/base/web/blob/master/.buildkite/pipeline.yml"
    click CI "https://github.com/base/web/blob/master/.github/workflows/main.yml"

    %% Styles
    classDef frontend fill:#e0f7fa,stroke:#006064,color:#004d40;
    classDef backend fill:#bbdefb,stroke:#0d47a1,color:#0d47a1;
    classDef data fill:#fff9c4,stroke:#f57f17,color:#b26000;
    classDef external fill:#cfd8dc,stroke:#455a64,color:#263238;
    classDef tooling fill:#d7ccc8,stroke:#4e342e,color:#3e2723;
```
