diff --git a/doc/bitbake-user-manual/bitbake-user-manual-execution.rst b/doc/bitbake-user-manual/bitbake-user-manual-execution.rst
index 7fdf61c23..38cbc56ab 100644
--- a/doc/bitbake-user-manual/bitbake-user-manual-execution.rst
+++ b/doc/bitbake-user-manual/bitbake-user-manual-execution.rst
@@ -281,6 +281,69 @@ recursively try to find recipes or append files in this directory.
    The ``dynamic-recipes/`` directory cannot contain classes or configuration
    files. Its content is limited to recipes or bbappends.
 
+Parsing Order And Priorities
+============================
+
+Layers are parsed by BitBake using the :term:`BBLAYERS` variable. The
+:term:`BBLAYERS` variable contains a list of paths pointing to the currently
+enabled layers. BitBake uses the value of this variable to construct the
+:term:`BBPATH` variable: a colon-separated list of paths that is crucial to
+understand how assignments and file inclusion priorities work with BitBake.
+
+The principle is that a layer is prioritized compared to all the layers it
+depends on. If two or more layers have exactly the same list of dependencies,
+then they are alphabetically ordered, and the last one is prioritized.
+
+For example, in the following graph:
+
+.. figure:: svg/layer-dependencies-1.*
+   :align: center
+   :width: 70%
+
+The ``meta-custom-1`` and ``meta-custom-2`` layers both depend on
+``openembedded-core``, they have the same dependencies, so the resulting
+:term:`BBPATH` will contain the layer paths in this order:
+
+.. code-block:: text
+
+   /path/to/meta-custom-2:/path/to/meta-custom-1:/path/to/openembedded-core
+
+.. note::
+
+   :term:`BBPATH` is iterated from left to right.
+
+In this context, the ``meta-custom-2`` layer always wins in the following situations:
+
+-  Both layers provide the same machine or distro configuration file.
+
+-  Both layers provide the same recipe with the same version (unless one of them
+   sets a higher :term:`DEFAULT_PREFERENCE` than the other, or
+   :term:`PREFERRED_VERSION` selects a specific version for the recipe).
+
+-  Both layers provide the same class.
+
+If, however, we now change the dependency graph to:
+
+.. figure:: svg/layer-dependencies-2.*
+   :align: center
+   :width: 100%
+
+Here, we added the information that ``meta-custom-1`` depends on
+``meta-custom-2`` (both still depend on ``openembedded-core``). Therefore
+``meta-custom-1`` is now prioritized over ``meta-custom-2`` and
+``openembedded-core``, because it depends on both. :term:`BBPATH` will now
+contain the layer paths in this order:
+
+.. code-block:: text
+
+   /path/to/meta-custom-1:/path/to/meta-custom-2:/path/to/openembedded-core
+
+This sort method is called :wikipedia:`topological sorting
+<Topological_sorting>`, and is explained in the Python official documentation
+for the `graphlib.TopologicalSorter
+<https://docs.python.org/3/library/graphlib.html#graphlib.TopologicalSorter>`__
+class, which BitBake uses internally.
+
 .. _bb-bitbake-providers:
 
 Providers
diff --git a/doc/bitbake-user-manual/svg/layer-dependencies-1.mmd b/doc/bitbake-user-manual/svg/layer-dependencies-1.mmd
new file mode 100644
index 000000000..d8a66267d
--- /dev/null
+++ b/doc/bitbake-user-manual/svg/layer-dependencies-1.mmd
@@ -0,0 +1,14 @@
+---
+config:
+  theme: base
+  look: classic
+  fontFamily: '"Nimbus Sans", Helvetica, Arial, sans-serif'
+  flowchart:
+    wrappingWidth: 200
+---
+flowchart LR
+    openembedded-core["`openembedded-core`"]
+    meta-custom-1["`meta-custom-1`"]
+    meta-custom-2["`meta-custom-2`"]
+    meta-custom-1 -- depends on --> openembedded-core
+    meta-custom-2 -- depends on --> openembedded-core
diff --git a/doc/bitbake-user-manual/svg/layer-dependencies-1.svg b/doc/bitbake-user-manual/svg/layer-dependencies-1.svg
new file mode 100644
index 000000000..b9c7405a5
--- /dev/null
+++ b/doc/bitbake-user-manual/svg/layer-dependencies-1.svg
@@ -0,0 +1 @@
+<svg id="my-svg" width="100%" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="flowchart" style="max-width: 567.234px; background-color: white;" viewBox="4 4 567.234375 164" role="graphics-document document" aria-roledescription="flowchart-v2"><style>#my-svg{font-family:"Nimbus Sans",Helvetica,Arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#my-svg .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#my-svg .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#my-svg .error-icon{fill:hsl(220.5882352941, 100%, 98.3333333333%);}#my-svg .error-text{fill:rgb(8.5000000002, 5.7500000001, 0);stroke:rgb(8.5000000002, 5.7500000001, 0);}#my-svg .edge-thickness-normal{stroke-width:1px;}#my-svg .edge-thickness-t
 hick{stroke-width:3.5px;}#my-svg .edge-pattern-solid{stroke-dasharray:0;}#my-svg .edge-thickness-invisible{stroke-width:0;fill:none;}#my-svg .edge-pattern-dashed{stroke-dasharray:3;}#my-svg .edge-pattern-dotted{stroke-dasharray:2;}#my-svg .marker{fill:#0b0b0b;stroke:#0b0b0b;}#my-svg .marker.cross{stroke:#0b0b0b;}#my-svg svg{font-family:"Nimbus Sans",Helvetica,Arial,sans-serif;font-size:16px;}#my-svg p{margin:0;}#my-svg .label{font-family:"Nimbus Sans",Helvetica,Arial,sans-serif;color:#333;}#my-svg .cluster-label text{fill:rgb(8.5000000002, 5.7500000001, 0);}#my-svg .cluster-label span{color:rgb(8.5000000002, 5.7500000001, 0);}#my-svg .cluster-label span p{background-color:transparent;}#my-svg .label text,#my-svg span{fill:#333;color:#333;}#my-svg .node rect,#my-svg .node circle,#my-svg .node ellipse,#my-svg .node polygon,#my-svg .node path{fill:#fff4dd;stroke:hsl(40.5882352941, 60%, 83.3333333333%);stroke-width:1px;}#my-svg .rough-node .label text,#my-svg .node .label text,#my-svg .
 image-shape .label,#my-svg .icon-shape .label{text-anchor:middle;}#my-svg .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#my-svg .rough-node .label,#my-svg .node .label,#my-svg .image-shape .label,#my-svg .icon-shape .label{text-align:center;}#my-svg .node.clickable{cursor:pointer;}#my-svg .root .anchor path{fill:#0b0b0b!important;stroke-width:0;stroke:#0b0b0b;}#my-svg .arrowheadPath{fill:#0b0b0b;}#my-svg .edgePaths .path{stroke:#0b0b0b;stroke-width:1px;}#my-svg .flowchart-link{stroke:#0b0b0b;fill:none;}#my-svg .edgeLabel{background-color:hsl(-79.4117647059, 100%, 93.3333333333%);text-align:center;}#my-svg .edgeLabel p{background-color:hsl(-79.4117647059, 100%, 93.3333333333%);}#my-svg .edgeLabel rect{opacity:0.5;background-color:hsl(-79.4117647059, 100%, 93.3333333333%);fill:hsl(-79.4117647059, 100%, 93.3333333333%);}#my-svg .labelBkg{background-color:rgba(243.9999999999, 220.9999999998, 255, 0.5);}#my-svg .cluster rect{fill:hsl(220.5882352941, 100%, 98.3333333333%);stro
 ke:hsl(220.5882352941, 60%, 88.3333333333%);stroke-width:1px;}#my-svg .cluster text{fill:rgb(8.5000000002, 5.7500000001, 0);}#my-svg .cluster span{color:rgb(8.5000000002, 5.7500000001, 0);}#my-svg .node .collapsed-indicator{fill:hsl(220.5882352941, 60%, 88.3333333333%);stroke:none;opacity:0.6;}#my-svg .node .collapsed-separator{stroke:hsl(220.5882352941, 60%, 88.3333333333%);stroke-width:0.75px;}#my-svg div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"Nimbus Sans",Helvetica,Arial,sans-serif;font-size:12px;background:hsl(220.5882352941, 100%, 98.3333333333%);border:1px solid hsl(220.5882352941, 60%, 88.3333333333%);border-radius:2px;pointer-events:none;z-index:100;}#my-svg .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#my-svg rect.text{fill:none;stroke-width:0;}#my-svg .icon-shape,#my-svg .image-shape{background-color:hsl(-79.4117647059, 100%, 93.3333333333%);text-align:center;}#my-svg .icon-shape p,#my-svg .image-shap
 e p{background-color:hsl(-79.4117647059, 100%, 93.3333333333%);padding:2px;}#my-svg .icon-shape .label rect,#my-svg .image-shape .label rect{opacity:0.5;background-color:hsl(-79.4117647059, 100%, 93.3333333333%);fill:hsl(-79.4117647059, 100%, 93.3333333333%);}#my-svg .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#my-svg .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#my-svg .node .neo-node{stroke:hsl(40.5882352941, 60%, 83.3333333333%);}#my-svg [data-look="neo"].node rect,#my-svg [data-look="neo"].cluster rect,#my-svg [data-look="neo"].node polygon{stroke:url(#my-svg-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#my-svg [data-look="neo"].swimlane.cluster rect{filter:none;}#my-svg [data-look="neo"].node path{stroke:url(#my-svg-gradient);stroke-width:1px;}#my-svg [data-look="neo"].node .outer-path{filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#my-svg [data-look="neo"].node .neo-line path{str
 oke:hsl(40.5882352941, 60%, 83.3333333333%);filter:none;}#my-svg [data-look="neo"].node circle{stroke:url(#my-svg-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#my-svg [data-look="neo"].node circle .state-start{fill:#000000;}#my-svg [data-look="neo"].icon-shape .icon{fill:url(#my-svg-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#my-svg [data-look="neo"].icon-shape .icon-neo path{stroke:url(#my-svg-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#my-svg :root{--mermaid-font-family:"Nimbus Sans",Helvetica,Arial,sans-serif;}</style><g><marker id="my-svg_flowchart-v2-pointEnd" class="marker flowchart-v2" viewBox="0 0 10 10" refX="5" refY="5" markerUnits="userSpaceOnUse" markerWidth="8" markerHeight="8" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowMarkerPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-pointStart" class="marker flowchart-v2" viewBox="0 0 10 10" refX="4.5" refY
 ="5" markerUnits="userSpaceOnUse" markerWidth="8" markerHeight="8" orient="auto"><path d="M 0 5 L 10 10 L 10 0 z" class="arrowMarkerPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-pointEnd-margin" class="marker flowchart-v2" viewBox="0 0 11.5 14" refX="11.5" refY="7" markerUnits="userSpaceOnUse" markerWidth="10.5" markerHeight="14" orient="auto"><path d="M 0 0 L 11.5 7 L 0 14 z" class="arrowMarkerPath" style="stroke-width: 0; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-pointStart-margin" class="marker flowchart-v2" viewBox="0 0 11.5 14" refX="1" refY="7" markerUnits="userSpaceOnUse" markerWidth="11.5" markerHeight="14" orient="auto"><polygon points="0,7 11.5,14 11.5,0" class="arrowMarkerPath" style="stroke-width: 0; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-circleEnd" class="marker flowchart-v2" viewBox="0 0 10 10" refX="11" refY="5" markerUnits="userSpaceOnUse" markerWidth="11" markerHe
 ight="11" orient="auto"><circle cx="5" cy="5" r="5" class="arrowMarkerPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-circleStart" class="marker flowchart-v2" viewBox="0 0 10 10" refX="-1" refY="5" markerUnits="userSpaceOnUse" markerWidth="11" markerHeight="11" orient="auto"><circle cx="5" cy="5" r="5" class="arrowMarkerPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-circleEnd-margin" class="marker flowchart-v2" viewBox="0 0 10 10" refY="5" refX="12.25" markerUnits="userSpaceOnUse" markerWidth="14" markerHeight="14" orient="auto"><circle cx="5" cy="5" r="5" class="arrowMarkerPath" style="stroke-width: 0; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-circleStart-margin" class="marker flowchart-v2" viewBox="0 0 10 10" refX="-2" refY="5" markerUnits="userSpaceOnUse" markerWidth="14" markerHeight="14" orient="auto"><circle cx="5" cy="5" r="5" class="arrowMarkerPath" sty
 le="stroke-width: 0; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-crossEnd" class="marker cross flowchart-v2" viewBox="0 0 11 11" refX="12" refY="5.2" markerUnits="userSpaceOnUse" markerWidth="11" markerHeight="11" orient="auto"><path d="M 1,1 l 9,9 M 10,1 l -9,9" class="arrowMarkerPath" style="stroke-width: 2; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-crossStart" class="marker cross flowchart-v2" viewBox="0 0 11 11" refX="-1" refY="5.2" markerUnits="userSpaceOnUse" markerWidth="11" markerHeight="11" orient="auto"><path d="M 1,1 l 9,9 M 10,1 l -9,9" class="arrowMarkerPath" style="stroke-width: 2; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-crossEnd-margin" class="marker cross flowchart-v2" viewBox="0 0 15 15" refX="17.7" refY="7.5" markerUnits="userSpaceOnUse" markerWidth="12" markerHeight="12" orient="auto"><path d="M 1,1 L 14,14 M 1,14 L 14,1" class="arrowMarkerPath" style="stroke-width: 2.5;"/></marker><marker 
 id="my-svg_flowchart-v2-crossStart-margin" class="marker cross flowchart-v2" viewBox="0 0 15 15" refX="-3.5" refY="7.5" markerUnits="userSpaceOnUse" markerWidth="12" markerHeight="12" orient="auto"><path d="M 1,1 L 14,14 M 1,14 L 14,1" class="arrowMarkerPath" style="stroke-width: 2.5; stroke-dasharray: 1, 0;"/></marker><g class="root"><g class="clusters"/><g class="edges edgePaths"><path d="M192,39L328.5539321881345,39Q335.625,39 335.625,46.071067811865476L335.625,73.26226552146787Q335.625,80.33333333333334 342.6960678118655,80.33333333333334L351.625,80.33333333333334" id="my-svg-L_meta-custom-1_openembedded-core_0" class="edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link" style=";" data-edge="true" data-et="edge" data-id="L_meta-custom-1_openembedded-core_0" data-points="W3sieCI6MTkyLCJ5IjozOX0seyJ4IjozMzUuNjI1LCJ5IjozOX0seyJ4IjozMzUuNjI1LCJ5Ijo4MC4zMzMzMzMzMzMzMzMzNH0seyJ4IjozNTUuNjI1LCJ5Ijo4MC4zMzMzMzMzMzMzMzMzNH1d" data-look="classi
 c" marker-end="url(#my-svg_flowchart-v2-pointEnd)"/><path d="M192,133L328.5539321881345,133Q335.625,133 335.625,125.92893218813452L335.625,98.73773447853215Q335.625,91.66666666666667 342.6960678118655,91.66666666666667L351.625,91.66666666666667" id="my-svg-L_meta-custom-2_openembedded-core_0" class="edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link" style=";" data-edge="true" data-et="edge" data-id="L_meta-custom-2_openembedded-core_0" data-points="W3sieCI6MTkyLCJ5IjoxMzN9LHsieCI6MzM1LjYyNSwieSI6MTMzfSx7IngiOjMzNS42MjUsInkiOjkxLjY2NjY2NjY2NjY2NjY3fSx7IngiOjM1NS42MjUsInkiOjkxLjY2NjY2NjY2NjY2NjY3fV0=" data-look="classic" marker-end="url(#my-svg_flowchart-v2-pointEnd)"/></g><g class="edgeLabels"><g class="edgeLabel" transform="translate(273.8125, 38.5)"><g class="label" data-id="L_meta-custom-1_openembedded-core_0" transform="translate(-41.8125, -12)"><foreignObject width="83.625" height="24"><div xmlns="http://www.w3.org/1999/xhtml" class
 ="labelBkg" style="display: table-cell; white-space: nowrap; line-height: 1.5; max-width: 200px; text-align: center;"><span class="edgeLabel"><p>depends on</p></span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(273.8125, 132.5)"><g class="label" data-id="L_meta-custom-2_openembedded-core_0" transform="translate(-41.8125, -12)"><foreignObject width="83.625" height="24"><div xmlns="http://www.w3.org/1999/xhtml" class="labelBkg" style="display: table-cell; white-space: nowrap; line-height: 1.5; max-width: 200px; text-align: center;"><span class="edgeLabel"><p>depends on</p></span></div></foreignObject></g></g></g><g class="nodes"><g class="node default" id="my-svg-flowchart-openembedded-core-0" data-look="classic" transform="translate(459.4296875, 86)"><rect class="basic label-container" style="" x="-103.8046875" y="-27" width="207.609375" height="54"/><g class="label" style="" transform="translate(-73.8046875, -12)"><rect/><foreignObject width="147.609375" h
 eight="24"><div xmlns="http://www.w3.org/1999/xhtml" style="display: table-cell; white-space: nowrap; line-height: 1.5; max-width: 200px; text-align: center;"><span class="nodeLabel markdown-node-label"><p>openembedded-core</p></span></div></foreignObject></g></g><g class="node default" id="my-svg-flowchart-meta-custom-1-1" data-look="classic" transform="translate(102, 39)"><rect class="basic label-container" style="" x="-90" y="-27" width="180" height="54"/><g class="label" style="" transform="translate(-60, -12)"><rect/><foreignObject width="120" height="24"><div xmlns="http://www.w3.org/1999/xhtml" style="display: table; white-space: nowrap; line-height: 1.5; max-width: 200px; text-align: center; width: 120px;"><span class="nodeLabel markdown-node-label"><p>meta-custom-1</p></span></div></foreignObject></g></g><g class="node default" id="my-svg-flowchart-meta-custom-2-2" data-look="classic" transform="translate(102, 133)"><rect class="basic label-container" style="" x="-90" y="-2
 7" width="180" height="54"/><g class="label" style="" transform="translate(-60, -12)"><rect/><foreignObject width="120" height="24"><div xmlns="http://www.w3.org/1999/xhtml" style="display: table; white-space: nowrap; line-height: 1.5; max-width: 200px; text-align: center; width: 120px;"><span class="nodeLabel markdown-node-label"><p>meta-custom-2</p></span></div></foreignObject></g></g></g></g></g><defs><filter id="my-svg-drop-shadow" height="130%" width="130%"><feDropShadow dx="4" dy="4" stdDeviation="0" flood-opacity="0.06" flood-color="#000000"/></filter></defs><defs><filter id="my-svg-drop-shadow-small" height="150%" width="150%"><feDropShadow dx="2" dy="2" stdDeviation="0" flood-opacity="0.06" flood-color="#000000"/></filter></defs><linearGradient id="my-svg-gradient" gradientUnits="objectBoundingBox" x1="0%" y1="0%" x2="100%" y2="0%"><stop offset="0%" stop-color="hsl(40.5882352941, 60%, 83.3333333333%)" stop-opacity="1"/><stop offset="100%" stop-color="hsl(-79.4117647059, 60%
 , 83.3333333333%)" stop-opacity="1"/></linearGradient></svg>
\ No newline at end of file
diff --git a/doc/bitbake-user-manual/svg/layer-dependencies-2.mmd b/doc/bitbake-user-manual/svg/layer-dependencies-2.mmd
new file mode 100644
index 000000000..756a86032
--- /dev/null
+++ b/doc/bitbake-user-manual/svg/layer-dependencies-2.mmd
@@ -0,0 +1,15 @@
+---
+config:
+  theme: base
+  look: classic
+  fontFamily: '"Nimbus Sans", Helvetica, Arial, sans-serif'
+  flowchart:
+    wrappingWidth: 200
+---
+flowchart LR
+    openembedded-core["`openembedded-core`"]
+    meta-custom-1["`meta-custom-1`"]
+    meta-custom-2["`meta-custom-2`"]
+    meta-custom-1 -- depends on --> openembedded-core
+    meta-custom-1 -- depends on --> meta-custom-2
+    meta-custom-2 -- depends on --> openembedded-core
diff --git a/doc/bitbake-user-manual/svg/layer-dependencies-2.svg b/doc/bitbake-user-manual/svg/layer-dependencies-2.svg
new file mode 100644
index 000000000..fb619b586
--- /dev/null
+++ b/doc/bitbake-user-manual/svg/layer-dependencies-2.svg
@@ -0,0 +1 @@
+<svg id="my-svg" width="100%" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="flowchart" style="max-width: 910.859px; background-color: white;" viewBox="4 4 910.859375 135" role="graphics-document document" aria-roledescription="flowchart-v2"><style>#my-svg{font-family:"Nimbus Sans",Helvetica,Arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#my-svg .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#my-svg .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#my-svg .error-icon{fill:hsl(220.5882352941, 100%, 98.3333333333%);}#my-svg .error-text{fill:rgb(8.5000000002, 5.7500000001, 0);stroke:rgb(8.5000000002, 5.7500000001, 0);}#my-svg .edge-thickness-normal{stroke-width:1px;}#my-svg .edge-thickness-t
