A one-file starter: a pn junction with a bias slider

This is the smallest complete page that uses driftlet: a silicon pn junction, solved as you drag the slider, with its band diagram drawn energy-up (band edges and the electron and hole quasi-Fermi levels). Each slider position is a full self-consistent drift–diffusion solve (Poisson with electron and hole transport and recombination), run in the browser. The page loads driftlet from a pinned CDN URL, with no install and no build step. Copy the source below into a file, open it, and change the device.

Checks before you build on it

At 0 V the potential step across the junction, sol.phi[0] - sol.phi.at(-1), is 0.795 V. That is the textbook (kT/q)·ln(NAND/ni²), with ni = √(NcNv)·e−Eg/2kT = 6.7×10⁹ cm⁻³ from the same band data. (The often-quoted ni = 1×10¹⁰ cm⁻³ would give 0.774 V.) sol.current is along +x, and here n is on the left, so forward current, p to n, comes out negative: the readout flips its sign. A failed solve keeps the last good solution and sets info.failed.

The whole page

<!doctype html>
<meta charset="utf-8">
<title>pn junction</title>
<label>bias <input id="V" type="range" min="-0.5" max="0.7" step="0.01" value="0"></label>
<span id="readout"></span>
<div id="figure"></div>
<script type="module">
import { units } from 'https://cdn.jsdelivr.net/npm/driftlet@1.23.0/src/index.js';
import { build, layer, ohmic, semiconductor, live } from 'https://cdn.jsdelivr.net/npm/driftlet@1.23.0/src/kit.js';
import { bandDiagram } from 'https://cdn.jsdelivr.net/npm/driftlet@1.23.0/src/plot.js';

const def = build({
  T: 300,
  library: [semiconductor('Si')],
  stack: [ohmic(0), layer('Si', 1e-6, { donors: units.perCm3(1e17) }), layer('Si', 1e-6, { acceptors: units.perCm3(1e16) }), ohmic(0)],
  bulkReactions: [{ equation: 'e- + h+ = 0', kf: { Si: 1e8 } }],
  grid: { hmin: 1e-9, hmax: 20e-9 },
});
const slider = document.getElementById('V');
const dev = live(def, {
  onsolution(sol, info) {
    document.getElementById('figure').innerHTML = bandDiagram(sol, { energy: true, range: [-1.2, 1.7], title: `V = ${sol.terminals.right.V.toFixed(2)} V` });
    document.getElementById('readout').textContent = info.failed ? 'no solution here' : `I = ${(-sol.current).toExponential(2)} A/m², p to n`; // sol.current is along +x, and n is on the left
  },
});
slider.addEventListener('input', () => dev.set({ contacts: { right: { V: +slider.value } } }));
</script>

Next: the guide for coding agents has templates for a solar cell, a MOS capacitor, an electrochemical cell, a battery particle and a cell membrane; the demos show their whole scripts at the bottom of each page; and the device reference has every option.