# riley-brown/turbo-repo-express-next-example architecture

> Architecture diagram of the GitHub repository riley-brown/turbo-repo-express-next-example, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/riley-brown/turbo-repo-express-next-example
- Repository: https://github.com/riley-brown/turbo-repo-express-next-example

## Overview

##### Project type and purpose
- This is a full-stack monorepo built with Turborepo and pnpm workspaces.
- It contains a Next.js front-end (“apps/front-end”), an Express back-end (“apps/server”), and several locally shared TypeScript packages under “packages/*”.
- Its main goal is to demonstrate how to bundle and transpile shared packages at build time—using Next.js’s transpilePackages for the front-end and tsup with noExternal for the server.

##### File structure
- Top-level orchestrator files:
- turbo.json / pnpm-workspace.yaml: defines the workspace and build pipelines
- package.json, pnpm-lock.yaml: root dependency management
- apps/:
- front-end: Next.js app (pages/, public/, next.config.js with transpilePackages)
- server: Express app (index.ts, tsup.config.ts for bundling)
- packages/: shared libs:
- eslint: custom ESLint rules
- logger: logging utility
- utils: general utilities
- tsconfig: base and node TypeScript configs
- Tooling configs: .eslintrc.js, tsconfig.json, .vscode/, etc.

##### README for additional insights
- The front-end uses Next.js 13’s built-in transpilePackages to include local packages
- The server uses tsup with noExternal to bundle @example/* packages into dist/
- Turborepo runs install, dev, build, start across all apps and packages in parallel or in pipelines

a. Main components (nodes):
- Monorepo root (Turborepo orchestrator + pnpm workspace)
- Front-end app (Next.js)
- Back-end app (Express)
- Shared packages (logger, utils, eslint, tsconfig)
- Build tools (Next.js build, tsup, pnpm)
- External dependencies (npm registry modules, client browsers)
b. Relationships & interactions (edges):
- Front-end ↔ Shared packages: imports at build time via transpilePackages
- Server ↔ Shared packages: bundles via tsup noExternal
- Client browser → Front-end: HTTP(S) requests for UI pages and API calls
- Front-end → Server API: fetch /api endpoints
- Turborepo → apps & packages: orchestrates dev, build, start scripts
- pnpm → all workspace nodes: resolves dependencies
c. Architectural patterns & principles:
- Monorepo for code sharing and unified versioning
- Build-time code-sharing vs. individual package builds
- BFF pattern: Next.js front-end acting as a frontend that also proxies or calls the Express API
- Bundle-everything approach: zero separate publish/build steps for shared packages
d. Key technologies:
- Next.js 13, React, TypeScript
- Express.js, tsup
- Turborepo, pnpm workspaces
- ESLint (custom rules), shared tsconfig

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Tooling / Orchestration
    subgraph "Tooling / Orchestration"
        Turborepo["Monorepo Orchestrator (Turborepo)"]:::orchestrator
        PNPM["pnpm Workspace Config"]:::orchestrator
        RootPkg["package.json"]:::orchestrator
        RootLock["pnpm-lock.yaml"]:::orchestrator
    end

    %% Applications
    subgraph "apps"
        subgraph "Front-end (Next.js)"
            NextApp["Next.js App"]:::frontend
            NextConf["next.config.js"]:::config
            FEtsconfig["tsconfig.json"]:::config
            Pages["pages/"]:::files
        end
        subgraph "Back-end (Express)"
            ExpressApp["Express Server"]:::backend
            Entry["index.ts"]:::files
            TsupConf["tsup.config.ts"]:::config
            BEtsconfig["tsconfig.json"]:::config
        end
    end

    %% Shared Libraries
    subgraph "packages (shared libs)"
        Logger["@example/logger"]:::library
        LogIndex["index.ts"]:::files
        Utils["@example/utils"]:::library
        UtilsIndex["index.ts"]:::files
        UtilsAdd["anotherUtil.ts"]:::files
        ESLintPkg["@example/eslint"]:::library
        ESLintIndex["index.js"]:::files
        ESLintConf[".eslintrc.js"]:::config
        TSConfigPkg["@example/tsconfig"]:::library
        TSCBase["tsconfig.base.json"]:::config
        TSCNode["tsconfig.node.json"]:::config
    end

    %% Root Configuration
    subgraph "Configuration Files"
        RootTS["tsconfig.json"]:::config
        RootESLint[".eslintrc.js"]:::config
        TurboJson["turbo.json"]:::config
        PnpmYaml["pnpm-workspace.yaml"]:::config
    end

    %% External Entities
    Browser["Client Browser"]:::external
    NpmRegistry["npm Registry"]:::external

    %% Orchestration Flows
    Turborepo -->|orchestrates dev/build/start| NextApp
    Turborepo -->|orchestrates dev/build/start| ExpressApp
    Turborepo -->|orchestrates dev/build/start| Logger
    Turborepo -->|orchestrates dev/build/start| Utils
    Turborepo -->|orchestrates dev/build/start| ESLintPkg
    Turborepo -->|orchestrates dev/build/start| TSConfigPkg

    PNPM -->|resolves dependencies| NextApp
    PNPM -->|resolves dependencies| ExpressApp
    PNPM -->|resolves dependencies| Logger
    PNPM -->|resolves dependencies| Utils
    PNPM -->|resolves dependencies| ESLintPkg
    PNPM -->|resolves dependencies| TSConfigPkg

    NpmRegistry -->|provides modules| NextApp
    NpmRegistry -->|provides modules| ExpressApp
    NpmRegistry -->|provides modules| Logger
    NpmRegistry -->|provides modules| Utils
    NpmRegistry -->|provides modules| ESLintPkg
    NpmRegistry -->|provides modules| TSConfigPkg

    %% Build-time Dependencies
    NextApp -->|transpilePackages| Logger
    NextApp -->|transpilePackages| Utils
    NextApp -->|transpilePackages| ESLintPkg
    NextApp -->|transpilePackages| TSConfigPkg

    ExpressApp -->|tsup noExternal| Logger
    ExpressApp -->|tsup noExternal| Utils
    ExpressApp -->|tsup noExternal| ESLintPkg
    ExpressApp -->|tsup noExternal| TSConfigPkg

    %% Runtime Interactions
    Browser -->|HTTP requests| NextApp
    NextApp -->|fetch /api| ExpressApp
    Browser -->|direct API calls| ExpressApp

    %% Click Events
    click TurboJson "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/turbo.json"
    click PnpmYaml "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/pnpm-workspace.yaml"
    click RootPkg "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/package.json"
    click RootLock "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/pnpm-lock.yaml"
    click NextApp "https://github.com/riley-brown/turbo-repo-express-next-example/tree/master/apps/front-end"
    click NextConf "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/apps/front-end/next.config.js"
    click FEtsconfig "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/apps/front-end/tsconfig.json"
    click Pages "https://github.com/riley-brown/turbo-repo-express-next-example/tree/master/apps/front-end/pages/"
    click ExpressApp "https://github.com/riley-brown/turbo-repo-express-next-example/tree/master/apps/server"
    click Entry "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/apps/server/index.ts"
    click TsupConf "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/apps/server/tsup.config.ts"
    click BEtsconfig "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/apps/server/tsconfig.json"
    click Logger "https://github.com/riley-brown/turbo-repo-express-next-example/tree/master/packages/logger"
    click LogIndex "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/packages/logger/index.ts"
    click Utils "https://github.com/riley-brown/turbo-repo-express-next-example/tree/master/packages/utils"
    click UtilsIndex "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/packages/utils/index.ts"
    click UtilsAdd "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/packages/utils/anotherUtil.ts"
    click ESLintPkg "https://github.com/riley-brown/turbo-repo-express-next-example/tree/master/packages/eslint"
    click ESLintIndex "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/packages/eslint/index.js"
    click ESLintConf "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/packages/eslint/.eslintrc.js"
    click TSConfigPkg "https://github.com/riley-brown/turbo-repo-express-next-example/tree/master/packages/tsconfig"
    click TSCBase "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/packages/tsconfig/tsconfig.base.json"
    click TSCNode "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/packages/tsconfig/tsconfig.node.json"
    click RootTS "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/tsconfig.json"
    click RootESLint "https://github.com/riley-brown/turbo-repo-express-next-example/blob/master/.eslintrc.js"

    %% Styles
    classDef orchestrator fill:#FFDD44,stroke:#333,stroke-width:1px
    classDef frontend fill:#88CCFF,stroke:#333,stroke-width:1px
    classDef backend fill:#FF8888,stroke:#333,stroke-width:1px
    classDef library fill:#CCFF88,stroke:#333,stroke-width:1px
    classDef config fill:#EEEEEE,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef files fill:#FFFFFF,stroke:#333,stroke-width:1px
    classDef external fill:#CCCCCC,stroke:#333,stroke-width:1px,stroke-dasharray: 2 2
```
