The synapse uses three interlocking signal systems to translate present activity into future behavioral bias. Ca²⁺ is the universal event recorder — each compartment reads its concentration dynamics differently (amplitude and speed of rise in the postsynapse, residual accumulation in the presynapse, IP3-triggered waves in the astrocyte), so the same ion encodes distinct instructions depending on where and how it appears. cAMP/PKA is the contextual gate: driven by neuromodulatory broadcast (dopamine, norepinephrine), it doesn't write changes itself but determines whether the Ca²⁺ signal gets committed to permanent structure — by priming AMPA receptor insertion, silencing the LTD phosphatase machinery via DARPP-32, and activating CREB-driven gene expression for structural proteins. mGluRs provide the overflow sensing layer: when glutamate spills beyond the cleft, group II/III mGluRs on the presynapse activate a Gi-mediated autoinhibitory brake, while group I mGluRs on the astrocyte trigger the IP3→Ca²⁺→D-serine cascade that amplifies NMDA coincidence detection — a push-pull architecture that simultaneously throttles excessive release and widens the postsynaptic learning window.
Together these three systems form a hierarchical filter: Ca²⁺ asks did something happen?, mGluRs ask was it excessive?, and cAMP/PKA asks was it worth saving? — and only when all three align does the synapse commit to rewriting its future response.
The key architectural decision in this pseudocode is the separation into three explicit layers that feed into a single commit_to_structural_change function. Each layer answers one question independently before the final AND-gate runs — Ca²⁺ detects the event, mGluRs assess its magnitude, and cAMP/PKA validates its context. Notice also that mGluR layer has a push-pull side effect that feeds back into the Ca²⁺ layer (astro_Ca_local is updated by mGluR5_activation), making the system not a strict pipeline but a loop — the overflow sensor actively reshapes what the event recorder sees next.
Dopamine is produced primarily by neurons in the Substantia Nigra pars compacta (projecting to the striatum, relevant for motor learning and habit formation) and the Ventral Tegmental Area (VTA) (projecting to the prefrontal cortex and limbic system via the mesolimbic and mesocortical pathways, relevant for reward, motivation, and the "save button" function in your model).
### Norepinephrine
Norepinephrine is produced almost exclusively by the Locus Coeruleus, a tiny nucleus in the brainstem pons. Despite its small size it projects diffusely across virtually the entire brain — cortex, hippocampus, cerebellum, spinal cord. It's essentially the brain's arousal and signal-to-noise broadcaster, firing tonically at low rates during calm wakefulness and phasically during novel or stressful events.
### Acetylcholine
Acetylcholine has two main sources: the basal forebrain nuclei (including the nucleus basalis of Meynert) projecting to the cortex and hippocampus — relevant for attention and learning gating — and the medial septum projecting specifically to the hippocampus, where it strongly modulates theta rhythms and memory encoding.
What's striking in the context of your model is that all three systems share the same architectural logic: a tiny, localized cell population broadcasts a global contextual signal that shifts the operational threshold of millions of synapses simultaneously — none of them carrying specific content, all of them modulating how content gets written.