# carbon-app/carbon architecture

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

## Overview

Carbon is a web app for turning source code into customized, shareable images. The main workflow is to enter or load code, adjust its appearance in the editor, then export or share it; saved snippets and embeds provide additional paths. The graph preserves those documented capabilities, but the excerpts do not show the main editor container or export handlers in detail, so their connections are limited to documented relationships. Authentication-to-API behavior is supported by the excerpts; unsampled feature wiring is left unasserted.

Main entry points: [`components/Carbon.js`](https://github.com/carbon-app/carbon/blob/main/components/Carbon.js) (Image renderer), [`components/Themes/index.js`](https://github.com/carbon-app/carbon/blob/main/components/Themes/index.js) (Theme chooser), [`components/Settings.js`](https://github.com/carbon-app/carbon/blob/main/components/Settings.js) (Image settings), [`pages/embed/index.js`](https://github.com/carbon-app/carbon/blob/main/pages/embed/index.js) (Embed view)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_editor["Code editing"]
  node_editor_page["Editor page<br/>[index.js]"]
  node_editor_shell["Editor container<br/>[EditorContainer.js]"]
  node_editor["Code editor<br/>[Editor.js]"]
  node_carbon["Image renderer<br/>[Carbon.js]"]
  node_selection["Line selection<br/>[SelectionEditor.js]"]
  node_language["Language modes"]
end

subgraph group_appearance["Image customization"]
  node_themes["Theme chooser<br/>[index.js]"]
  node_theme_create["Custom themes<br/>[ThemeCreate.js]"]
  node_global_highlights["Highlight styles"]
  node_settings["Image settings<br/>[Settings.js]"]
  node_presets["Saved presets<br/>[Presets.js]"]
  node_font["Font styles<br/>[Font.js]"]
end

subgraph group_sharing["Sharing and embeds"]
  node_snippet_page["Saved snippets<br/>[snippets.js]"]
  node_snippet_route["Snippet route<br/>[&#91;id&#93;.js]"]
  node_embed_route["Embed view<br/>[index.js]"]
  node_embed_id["ID embed route<br/>[&#91;id&#93;.js]"]
  node_export["Image export<br/>[&#91;id&#93;.js]"]
  node_oembed["oEmbed metadata<br/>[oembed.js]"]
end

subgraph group_identity["Accounts"]
  node_auth_provider["Sign-in UI<br/>[LoginButton.js]"]
  node_auth_context["Auth context<br/>[AuthContext.js]"]
  node_firebase["Firebase auth<br/>[client.js]"]
end

subgraph group_platform["App foundation"]
  node_api_context["API context<br/>[ApiContext.js]"]
  node_api["API client<br/>[api.js]"]
  node_route_state["URL state<br/>[routing.js]"]
  node_local_state[("Browser state<br/>[util.js]")]
  node_site_page["Page layout<br/>[Page.js]"]
  node_themes_config["Theme definitions<br/>[constants.js]"]
end

node_user(("Visitor"))
node_hosted_services(("Hosted services"))

node_user -->|"opens editor"| node_editor_page
node_editor_page -->|"renders"| node_editor_shell
node_editor_shell -->|"renders"| node_editor
node_editor -.->|"renders image"| node_carbon
node_carbon -->|"renders selection"| node_selection
node_carbon -->|"loads modes"| node_language
node_user -->|"customizes image"| node_settings
node_settings -.->|"selects theme"| node_themes
node_themes -->|"opens creator"| node_theme_create
node_themes -->|"renders highlights"| node_global_highlights
node_settings -.->|"uses presets"| node_presets
node_settings -.->|"chooses font"| node_font
node_user -->|"downloads image"| node_export
node_user -->|"saves snippet"| node_snippet_page
node_user -->|"embeds snippet"| node_embed_route
node_embed_id -->|"loads embed view"| node_embed_route
node_embed_route -->|"renders code"| node_carbon
node_embed_route -->|"reads URL state"| node_route_state
node_user -->|"signs in"| node_auth_provider
node_auth_provider -.->|"provides identity"| node_auth_context
node_auth_context -->|"observes auth"| node_firebase
node_auth_context -->|"sets auth header"| node_api
node_api_context -->|"provides client"| node_api
node_api -.->|"makes requests"| node_hosted_services
node_firebase -.->|"authenticates"| node_hosted_services
node_site_page -->|"wraps content"| node_auth_context
node_site_page -.->|"serves pages"| node_user
node_themes -.->|"uses definitions"| node_themes_config
node_route_state -->|"escapes route values"| node_local_state
node_user -->|"opens shared link"| node_snippet_route
node_snippet_route -.->|"renders snippet"| node_carbon
node_user -.->|"requests metadata"| node_oembed

click node_editor_page "https://github.com/carbon-app/carbon/blob/main/pages/index.js"
click node_editor_shell "https://github.com/carbon-app/carbon/blob/main/components/EditorContainer.js"
click node_editor "https://github.com/carbon-app/carbon/blob/main/components/Editor.js"
click node_carbon "https://github.com/carbon-app/carbon/blob/main/components/Carbon.js"
click node_selection "https://github.com/carbon-app/carbon/blob/main/components/SelectionEditor.js"
click node_language "https://github.com/carbon-app/carbon/blob/main/lib/highlight-languages.js"
click node_themes "https://github.com/carbon-app/carbon/blob/main/components/Themes/index.js"
click node_theme_create "https://github.com/carbon-app/carbon/blob/main/components/Themes/ThemeCreate.js"
click node_global_highlights "https://github.com/carbon-app/carbon/blob/main/components/Themes/GlobalHighlights.js"
click node_settings "https://github.com/carbon-app/carbon/blob/main/components/Settings.js"
click node_presets "https://github.com/carbon-app/carbon/blob/main/components/Presets.js"
click node_font "https://github.com/carbon-app/carbon/blob/main/components/style/Font.js"
click node_snippet_page "https://github.com/carbon-app/carbon/blob/main/pages/snippets.js"
click node_snippet_route "https://github.com/carbon-app/carbon/blob/main/pages/%5Bid%5D.js"
click node_embed_route "https://github.com/carbon-app/carbon/blob/main/pages/embed/index.js"
click node_embed_id "https://github.com/carbon-app/carbon/blob/main/pages/embed/%5Bid%5D.js"
click node_export "https://github.com/carbon-app/carbon/blob/main/pages/api/image/%5Bid%5D.js"
click node_oembed "https://github.com/carbon-app/carbon/blob/main/pages/api/oembed.js"
click node_auth_provider "https://github.com/carbon-app/carbon/blob/main/components/LoginButton.js"
click node_auth_context "https://github.com/carbon-app/carbon/blob/main/components/AuthContext.js"
click node_firebase "https://github.com/carbon-app/carbon/blob/main/lib/client.js"
click node_api_context "https://github.com/carbon-app/carbon/blob/main/components/ApiContext.js"
click node_api "https://github.com/carbon-app/carbon/blob/main/lib/api.js"
click node_route_state "https://github.com/carbon-app/carbon/blob/main/lib/routing.js"
click node_local_state "https://github.com/carbon-app/carbon/blob/main/lib/util.js"
click node_site_page "https://github.com/carbon-app/carbon/blob/main/components/Page.js"
click node_themes_config "https://github.com/carbon-app/carbon/blob/main/lib/constants.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_editor_page,node_editor_shell,node_editor,node_carbon,node_selection,node_language toneBlue
class node_themes,node_theme_create,node_global_highlights,node_settings,node_presets,node_font toneAmber
class node_snippet_page,node_snippet_route,node_embed_route,node_embed_id,node_export,node_oembed toneMint
class node_auth_provider,node_auth_context,node_firebase toneRose
class node_api_context,node_api,node_route_state,node_local_state,node_site_page,node_themes_config,node_user,node_hosted_services toneIndigo
```

## Components

### Code editing

- [Editor page](https://github.com/carbon-app/carbon/blob/main/pages/index.js): `pages/index.js`
- [Editor container](https://github.com/carbon-app/carbon/blob/main/components/EditorContainer.js): `components/EditorContainer.js`
- [Code editor](https://github.com/carbon-app/carbon/blob/main/components/Editor.js): `components/Editor.js`
- [Image renderer](https://github.com/carbon-app/carbon/blob/main/components/Carbon.js): `components/Carbon.js`
- [Line selection](https://github.com/carbon-app/carbon/blob/main/components/SelectionEditor.js): `components/SelectionEditor.js`
- [Language modes](https://github.com/carbon-app/carbon/blob/main/lib/highlight-languages.js): `lib/highlight-languages.js`

### Image customization

- [Theme chooser](https://github.com/carbon-app/carbon/blob/main/components/Themes/index.js): `components/Themes/index.js`
- [Custom themes](https://github.com/carbon-app/carbon/blob/main/components/Themes/ThemeCreate.js): `components/Themes/ThemeCreate.js`
- [Highlight styles](https://github.com/carbon-app/carbon/blob/main/components/Themes/GlobalHighlights.js): `components/Themes/GlobalHighlights.js`
- [Image settings](https://github.com/carbon-app/carbon/blob/main/components/Settings.js): `components/Settings.js`
- [Saved presets](https://github.com/carbon-app/carbon/blob/main/components/Presets.js): `components/Presets.js`
- [Font styles](https://github.com/carbon-app/carbon/blob/main/components/style/Font.js): `components/style/Font.js`

### Sharing and embeds

- [Saved snippets](https://github.com/carbon-app/carbon/blob/main/pages/snippets.js): `pages/snippets.js`
- [Snippet route](https://github.com/carbon-app/carbon/blob/main/pages/%5Bid%5D.js): `pages/[id].js`
- [Embed view](https://github.com/carbon-app/carbon/blob/main/pages/embed/index.js): `pages/embed/index.js`
- [ID embed route](https://github.com/carbon-app/carbon/blob/main/pages/embed/%5Bid%5D.js): `pages/embed/[id].js`
- [Image export](https://github.com/carbon-app/carbon/blob/main/pages/api/image/%5Bid%5D.js): `pages/api/image/[id].js`
- [oEmbed metadata](https://github.com/carbon-app/carbon/blob/main/pages/api/oembed.js): `pages/api/oembed.js`

### Accounts

- [Sign-in UI](https://github.com/carbon-app/carbon/blob/main/components/LoginButton.js): `components/LoginButton.js`
- [Auth context](https://github.com/carbon-app/carbon/blob/main/components/AuthContext.js): `components/AuthContext.js`
- [Firebase auth](https://github.com/carbon-app/carbon/blob/main/lib/client.js): `lib/client.js`

### App foundation

- [API context](https://github.com/carbon-app/carbon/blob/main/components/ApiContext.js): `components/ApiContext.js`
- [API client](https://github.com/carbon-app/carbon/blob/main/lib/api.js): `lib/api.js`
- [URL state](https://github.com/carbon-app/carbon/blob/main/lib/routing.js): `lib/routing.js`
- [Browser state](https://github.com/carbon-app/carbon/blob/main/lib/util.js): `lib/util.js`
- [Page layout](https://github.com/carbon-app/carbon/blob/main/components/Page.js): `components/Page.js`
- [Theme definitions](https://github.com/carbon-app/carbon/blob/main/lib/constants.js): `lib/constants.js`

### Other components

- **Visitor**
- **Hosted services**

## Connections

- Visitor → Editor page: opens editor
- Editor page → Editor container: renders (evidence: `pages/index.js`)
- Editor container → Code editor: renders (evidence: `components/EditorContainer.js`)
- Code editor → Image renderer: renders image
- Image renderer → Line selection: renders selection (evidence: `components/Carbon.js`)
- Image renderer → Language modes: loads modes (evidence: `components/Carbon.js`)
- Visitor → Image settings: customizes image
- Image settings → Theme chooser: selects theme
- Theme chooser → Custom themes: opens creator (evidence: `components/Themes/index.js`)
- Theme chooser → Highlight styles: renders highlights (evidence: `components/Themes/index.js`)
- Image settings → Saved presets: uses presets
- Image settings → Font styles: chooses font
- Visitor → Image export: downloads image
- Visitor → Saved snippets: saves snippet
- Visitor → Embed view: embeds snippet
- ID embed route → Embed view: loads embed view (evidence: `pages/embed/[id].js`)
- Embed view → Image renderer: renders code (evidence: `pages/embed/index.js`)
- Embed view → URL state: reads URL state (evidence: `pages/embed/index.js`)
- Visitor → Sign-in UI: signs in
- Sign-in UI → Auth context: provides identity
- Auth context → Firebase auth: observes auth (evidence: `components/AuthContext.js`)
- Auth context → API client: sets auth header (evidence: `components/AuthContext.js`)
- API context → API client: provides client (evidence: `components/ApiContext.js`)
- API client → Hosted services: makes requests
- Firebase auth → Hosted services: authenticates
- Page layout → Auth context: wraps content (evidence: `components/Page.js`)
- Page layout → Visitor: serves pages
- Theme chooser → Theme definitions: uses definitions (evidence: `components/Themes/index.js`)
- URL state → Browser state: escapes route values (evidence: `lib/routing.js`)
- Visitor → Snippet route: opens shared link
- Snippet route → Image renderer: renders snippet
- Visitor → oEmbed metadata: requests metadata
