# cansin/next-with-workbox architecture

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

- Interactive diagram: https://gitdiagram.com/cansin/next-with-workbox
- Repository: https://github.com/cansin/next-with-workbox

## Overview

next-with-workbox is a small Next.js configuration plugin that adds Workbox service-worker generation to the client webpack build. The workflow is: an application configures the wrapper, the wrapper preserves and invokes any existing webpack hook, then skips server and disabled development builds; enabled builds prepare output cleanup and precache options before selecting GenerateSW or InjectManifest. The README also documents application-side service-worker registration, which is external to this package. Relationships are based on the sampled index.js and README; no additional runtime modules are present in the tree.

Main entry points: [`index.js`](https://github.com/cansin/next-with-workbox/blob/master/index.js) (Webpack hook)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_config["Next.js Integration"]
  node_wrapper["Config wrapper<br/>[index.js]"]
  node_webpack_hook["Webpack hook<br/>[index.js]"]
  node_build_gates["Build gates<br/>[index.js]"]
end

subgraph group_build["Worker Build"]
  node_cleanup["Output cleanup<br/>[index.js]"]
  node_precache["Precache options<br/>[index.js]"]
  node_generate_sw["GenerateSW mode<br/>[index.js]"]
  node_inject_manifest["InjectManifest mode<br/>[index.js]"]
end

node_app(("Next.js application"))
node_workbox["Workbox webpack plugin"]
node_worker_source["Custom worker source"]
node_public_assets["Public assets"]
node_service_worker["Generated service worker"]
node_registration["Browser registration"]

node_app -->|"configures"| node_wrapper
node_wrapper -->|"returns hook"| node_webpack_hook
node_webpack_hook -->|"checks build"| node_build_gates
node_webpack_hook -->|"adds cleanup"| node_cleanup
node_webpack_hook -->|"assembles options"| node_precache
node_precache -->|"scans assets"| node_public_assets
node_webpack_hook -->|"selects default"| node_generate_sw
node_webpack_hook -->|"selects with source"| node_inject_manifest
node_generate_sw -->|"configures plugin"| node_workbox
node_inject_manifest -->|"configures plugin"| node_workbox
node_inject_manifest -->|"reads source"| node_worker_source
node_workbox -->|"generates output"| node_service_worker
node_registration -->|"registers"| node_service_worker
node_app -->|"implements example"| node_registration

click node_wrapper "https://github.com/cansin/next-with-workbox/blob/master/index.js"
click node_webpack_hook "https://github.com/cansin/next-with-workbox/blob/master/index.js"
click node_build_gates "https://github.com/cansin/next-with-workbox/blob/master/index.js"
click node_cleanup "https://github.com/cansin/next-with-workbox/blob/master/index.js"
click node_precache "https://github.com/cansin/next-with-workbox/blob/master/index.js"
click node_generate_sw "https://github.com/cansin/next-with-workbox/blob/master/index.js"
click node_inject_manifest "https://github.com/cansin/next-with-workbox/blob/master/index.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_wrapper,node_webpack_hook,node_build_gates,node_registration toneBlue
class node_cleanup,node_precache,node_generate_sw,node_inject_manifest toneAmber
class node_app,node_workbox,node_public_assets toneIndigo
class node_worker_source,node_service_worker toneRose
```

## Components

### Next.js Integration

- [Config wrapper](https://github.com/cansin/next-with-workbox/blob/master/index.js): `index.js`
- [Webpack hook](https://github.com/cansin/next-with-workbox/blob/master/index.js): `index.js`
- [Build gates](https://github.com/cansin/next-with-workbox/blob/master/index.js): `index.js`

### Worker Build

- [Output cleanup](https://github.com/cansin/next-with-workbox/blob/master/index.js): `index.js`
- [Precache options](https://github.com/cansin/next-with-workbox/blob/master/index.js): `index.js`
- [GenerateSW mode](https://github.com/cansin/next-with-workbox/blob/master/index.js): `index.js`
- [InjectManifest mode](https://github.com/cansin/next-with-workbox/blob/master/index.js): `index.js`

### Other components

- **Next.js application**
- **Workbox webpack plugin**
- **Custom worker source**
- **Public assets**
- **Generated service worker**
- **Browser registration**

## Connections

- Next.js application → Config wrapper: configures (evidence: `README.md`)
- Config wrapper → Webpack hook: returns hook (evidence: `index.js`)
- Webpack hook → Build gates: checks build (evidence: `index.js`)
- Webpack hook → Output cleanup: adds cleanup (evidence: `index.js`)
- Webpack hook → Precache options: assembles options (evidence: `index.js`)
- Precache options → Public assets: scans assets (evidence: `index.js`)
- Webpack hook → GenerateSW mode: selects default (evidence: `index.js`)
- Webpack hook → InjectManifest mode: selects with source (evidence: `index.js`)
- GenerateSW mode → Workbox webpack plugin: configures plugin (evidence: `index.js`)
- InjectManifest mode → Workbox webpack plugin: configures plugin (evidence: `index.js`)
- InjectManifest mode → Custom worker source: reads source (evidence: `index.js`)
- Workbox webpack plugin → Generated service worker: generates output (evidence: `README.md`)
- Browser registration → Generated service worker: registers (evidence: `README.md`)
- Next.js application → Browser registration: implements example (evidence: `README.md`)
