# lovell/sharp architecture

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

- Interactive diagram: https://gitdiagram.com/lovell/sharp
- Repository: https://github.com/lovell/sharp

## Overview

sharp is a Node-API image-processing library: callers create a Sharp instance from an image source, configure transformations and output format, then obtain a file, buffer, or stream. The JavaScript API is split across input, resize, compositing, operation, colour, channel, output, and utility modules; native C++ provides image loading and the processing pipeline. The README documents the user workflow and capabilities. Some JavaScript-to-native dispatch details and native helper calls are not visible in the excerpts, so those links are marked unverified.

Main entry points: [`lib/index.mjs`](https://github.com/lovell/sharp/blob/main/lib/index.mjs) (Sharp API), [`src/sharp.cc`](https://github.com/lovell/sharp/blob/main/src/sharp.cc) (Native Binding), [`src/pipeline.cc`](https://github.com/lovell/sharp/blob/main/src/pipeline.cc) (Image Pipeline), [`lib/input.mjs`](https://github.com/lovell/sharp/blob/main/lib/input.mjs) (Input & Metadata)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["JavaScript API"]
  node_entry["Sharp API<br/>[index.mjs]"]
  node_constructor["Instance Setup<br/>[constructor.mjs]"]
  node_input["Input &amp; Metadata<br/>[input.mjs]"]
  node_resize["Resize<br/>[resize.mjs]"]
  node_composite["Compositing<br/>[composite.mjs]"]
  node_operations["Image Operations<br/>[operation.mjs]"]
  node_colour["Colour Controls<br/>[colour.mjs]"]
  node_channels["Channel Controls<br/>[channel.mjs]"]
  node_output["Output &amp; Metadata<br/>[output.mjs]"]
  node_utility["Utilities &amp; Stats<br/>[utility.mjs]"]
end

subgraph group_native["Native Engine"]
  node_binding["Native Binding<br/>[sharp.cc]"]
  node_pipeline["Image Pipeline<br/>[pipeline.cc]"]
  node_nativeops["Native Operations<br/>[operations.cc]"]
  node_common["Image I/O Helpers<br/>[common.cc]"]
end

subgraph group_support["Runtime Support"]
  node_validation["Input Validation<br/>[is.mjs]"]
  node_vips["libvips Runtime<br/>[libvips.mjs]"]
end

node_caller(("Application"))
node_result["Image Result"]

node_caller -->|"creates image"| node_entry
node_entry -->|"installs API"| node_constructor
node_entry -->|"installs input"| node_input
node_entry -->|"installs resize"| node_resize
node_entry -->|"installs compositing"| node_composite
node_entry -->|"installs operations"| node_operations
node_entry -->|"installs colour"| node_colour
node_entry -->|"installs channels"| node_channels
node_entry -->|"installs output"| node_output
node_entry -->|"installs utilities"| node_utility
node_input -->|"validates with"| node_validation
node_resize -->|"validates with"| node_validation
node_operations -->|"validates with"| node_validation
node_input -.->|"dispatches input"| node_binding
node_resize -.->|"dispatches resize"| node_binding
node_composite -.->|"dispatches layers"| node_binding
node_operations -.->|"dispatches options"| node_binding
node_binding -.->|"routes calls"| node_pipeline
node_pipeline -->|"opens inputs"| node_common
node_pipeline -.->|"uses operations"| node_nativeops
node_pipeline -.->|"returns output"| node_output
node_output -->|"produces image"| node_result
node_utility -.->|"requests statistics"| node_binding
node_binding -.->|"loads runtime"| node_vips

click node_entry "https://github.com/lovell/sharp/blob/main/lib/index.mjs"
click node_constructor "https://github.com/lovell/sharp/blob/main/lib/constructor.mjs"
click node_input "https://github.com/lovell/sharp/blob/main/lib/input.mjs"
click node_resize "https://github.com/lovell/sharp/blob/main/lib/resize.mjs"
click node_composite "https://github.com/lovell/sharp/blob/main/lib/composite.mjs"
click node_operations "https://github.com/lovell/sharp/blob/main/lib/operation.mjs"
click node_colour "https://github.com/lovell/sharp/blob/main/lib/colour.mjs"
click node_channels "https://github.com/lovell/sharp/blob/main/lib/channel.mjs"
click node_output "https://github.com/lovell/sharp/blob/main/lib/output.mjs"
click node_utility "https://github.com/lovell/sharp/blob/main/lib/utility.mjs"
click node_validation "https://github.com/lovell/sharp/blob/main/lib/is.mjs"
click node_binding "https://github.com/lovell/sharp/blob/main/src/sharp.cc"
click node_pipeline "https://github.com/lovell/sharp/blob/main/src/pipeline.cc"
click node_nativeops "https://github.com/lovell/sharp/blob/main/src/operations.cc"
click node_common "https://github.com/lovell/sharp/blob/main/src/common.cc"
click node_vips "https://github.com/lovell/sharp/blob/main/lib/libvips.mjs"

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_entry,node_constructor,node_input,node_resize,node_composite,node_operations,node_colour,node_channels,node_output,node_utility toneBlue
class node_binding,node_pipeline,node_nativeops,node_common toneAmber
class node_validation,node_vips toneMint
class node_caller,node_result toneIndigo
```

## Components

### JavaScript API

- [Sharp API](https://github.com/lovell/sharp/blob/main/lib/index.mjs): `lib/index.mjs`
- [Instance Setup](https://github.com/lovell/sharp/blob/main/lib/constructor.mjs): `lib/constructor.mjs`
- [Input & Metadata](https://github.com/lovell/sharp/blob/main/lib/input.mjs): `lib/input.mjs`
- [Resize](https://github.com/lovell/sharp/blob/main/lib/resize.mjs): `lib/resize.mjs`
- [Compositing](https://github.com/lovell/sharp/blob/main/lib/composite.mjs): `lib/composite.mjs`
- [Image Operations](https://github.com/lovell/sharp/blob/main/lib/operation.mjs): `lib/operation.mjs`
- [Colour Controls](https://github.com/lovell/sharp/blob/main/lib/colour.mjs): `lib/colour.mjs`
- [Channel Controls](https://github.com/lovell/sharp/blob/main/lib/channel.mjs): `lib/channel.mjs`
- [Output & Metadata](https://github.com/lovell/sharp/blob/main/lib/output.mjs): `lib/output.mjs`
- [Utilities & Stats](https://github.com/lovell/sharp/blob/main/lib/utility.mjs): `lib/utility.mjs`

### Native Engine

- [Native Binding](https://github.com/lovell/sharp/blob/main/src/sharp.cc): `src/sharp.cc`
- [Image Pipeline](https://github.com/lovell/sharp/blob/main/src/pipeline.cc): `src/pipeline.cc`
- [Native Operations](https://github.com/lovell/sharp/blob/main/src/operations.cc): `src/operations.cc`
- [Image I/O Helpers](https://github.com/lovell/sharp/blob/main/src/common.cc): `src/common.cc`

### Runtime Support

- [Input Validation](https://github.com/lovell/sharp/blob/main/lib/is.mjs): `lib/is.mjs`
- [libvips Runtime](https://github.com/lovell/sharp/blob/main/lib/libvips.mjs): `lib/libvips.mjs`

### Other components

- **Application**
- **Image Result**

## Connections

- Application → Sharp API: creates image (evidence: `README.md`)
- Sharp API → Instance Setup: installs API (evidence: `lib/index.mjs`)
- Sharp API → Input & Metadata: installs input (evidence: `lib/index.mjs`)
- Sharp API → Resize: installs resize (evidence: `lib/index.mjs`)
- Sharp API → Compositing: installs compositing (evidence: `lib/index.mjs`)
- Sharp API → Image Operations: installs operations (evidence: `lib/index.mjs`)
- Sharp API → Colour Controls: installs colour (evidence: `lib/index.mjs`)
- Sharp API → Channel Controls: installs channels (evidence: `lib/index.mjs`)
- Sharp API → Output & Metadata: installs output (evidence: `lib/index.mjs`)
- Sharp API → Utilities & Stats: installs utilities (evidence: `lib/index.mjs`)
- Input & Metadata → Input Validation: validates with (evidence: `lib/input.mjs`)
- Resize → Input Validation: validates with (evidence: `lib/resize.mjs`)
- Image Operations → Input Validation: validates with (evidence: `lib/operation.mjs`)
- Input & Metadata → Native Binding: dispatches input
- Resize → Native Binding: dispatches resize
- Compositing → Native Binding: dispatches layers
- Image Operations → Native Binding: dispatches options
- Native Binding → Image Pipeline: routes calls
- Image Pipeline → Image I/O Helpers: opens inputs (evidence: `src/pipeline.cc`)
- Image Pipeline → Native Operations: uses operations
- Image Pipeline → Output & Metadata: returns output
- Output & Metadata → Image Result: produces image (evidence: `README.md`)
- Utilities & Stats → Native Binding: requests statistics
- Native Binding → libvips Runtime: loads runtime
