Archetype System & Calculation logic
The Archetype system is a core psychological layer of DreamStream that uses Jungian psychology to categorize dream patterns and provide users with a "Dominant Archetype" on their home dashboard.
1. The Archetype Lifecycle
The archetype data follows a two-stage lifecycle: Generation (per dream) and Synthesis (per user).
flowchart LR
A[Dream Logged] --> B[AI Analysis]
B --> C["Archetype Assigned<br/>(Stored in Dream)"]
C --> D[Home Dashboard]
D --> E["Dominant Archetype<br/>(Modal Calculation)"]
2. Generation (AI Pipeline)
When a dream is analyzed by Google Gemini, the model is instructed to identify the most relevant Jungian archetype for that specific dream.
- System Instruction: The model evaluates the dream's narrative, emotional tone, and symbolic content.
- Output: A single string field
archetypeis returned in the analysis JSON. - Fallback: If the AI fails to provide an archetype, the system appends a fallback section to ensure data consistency.
The 12 Supported Archetypes
| Archetype | Core Motivation | Typical Dream Signs |
|---|---|---|
| The Innocent | Safety & Happiness | Paradise, childhood, simplicity, purification |
| The Everyman | Belonging & Connection | Normal life, groups, equality, shared struggle |
| The Hero | Mastery & Courage | Battles, challenges, winning, transformation |
| The Caregiver | Service & Protection | Helping others, family, nursing, safety |
| The Explorer | Freedom & Discovery | Travel, mountains, new lands, escaping traps |
| The Rebel | Liberation & Change | Revolution, breaking rules, fire, radical shifts |
| The Lover | Intimacy & Experience | Romance, sensory beauty, deep bonds, gardens |
| The Creator | Innovation & Expression | Building, art, architecture, vivid imagination |
| The Jester | Joy & Lightness | Humor, parties, trickery, dismantling logic |
| The Sage | Truth & Understanding | Books, teachers, mirrors, clear water, stars |
| The Magician | Vision & Transformation | Alchemy, magic, rapid morphing, manifestation |
| The Ruler | Order & Control | Thrones, castles, leadership, responsibility |
3. Synthesis (Dominant Archetype Calculation)
The "Dominant Archetype" shown on the Home Dashboard is calculated dynamically on the client side based on the user's logged history.
The Logic (HomeDashboard.tsx)
The function getDominantArchetype() performs the following steps:
- Filtering: It ignores sample and tutorial dreams.
- Collection: It gathers all
archetypevalues from the remaining "real" dreams. - Mode Calculation: It counts the frequency of each archetype and selects the one with the highest count (the mathematical mode).
- Tie-Breaking: If multiple archetypes have the same frequency, the most recent one takes precedence (implied by array order).
Empty & Early States
| State | Title | Description |
|---|---|---|
| No Dreams | The Dreamer | "Start logging dreams to discover your archetype." |
| No Archetypes | The Initiate | "Log dreams to reveal your archetype." |
4. UI/UX Mapping
Each archetype is mapped to a specific visual identity in the dashboard to provide immediate recognition.
| Archetype | Icon | Color (Light/Dark) | Background Gradient |
|---|---|---|---|
| The Innocent | Sun |
text-sky-600 / #9ECFE6 | from-sky-500/10 โ to-blue-500/10 |
| The Everyman | Home |
text-slate-600 / #90A4AE | from-slate-500/10 โ to-gray-500/10 |
| The Hero | Sword |
text-amber-600 / #FFD54F | from-amber-500/10 โ to-orange-500/10 |
| The Caregiver | HeartHandshake |
text-emerald-600 / #A5D6A7 | from-emerald-500/10 โ to-green-500/10 |
| The Explorer | Compass |
text-orange-600 / #FFCC80 | from-orange-500/10 โ to-red-500/10 |
| The Rebel | Flame |
text-red-600 / #EF9A9A | from-red-500/10 โ to-rose-500/10 |
| The Lover | Heart |
text-rose-600 / #F48FB1 | from-rose-500/10 โ to-pink-500/10 |
| The Creator | Sparkles |
text-purple-600 / #CE93D8 | from-purple-500/10 โ to-fuchsia-500/10 |
| The Jester | PartyPopper |
text-yellow-600 / #F2E5A0 | from-yellow-500/10 โ to-amber-500/10 |
| The Sage | Flower |
text-indigo-600 / #818FDC | from-indigo-500/10 โ to-violet-500/10 |
| The Magician | Wand2 |
text-violet-600 / #B39DDB | from-violet-500/10 โ to-purple-500/10 |
| The Ruler | Crown |
text-teal-700 / #80CBC4 | from-teal-500/10 โ to-cyan-500/10 |
Source of truth: components/HomeDashboard.tsx โ archetypeStyles mapping.
5. Technical Implementation Details
- Client Logic:
HomeDashboard.triggerHapticandgetDominantArchetype. - AI Prompting: See
docs/Feature_explanations/PROMPT_ENGINE_LOGIC.mdfor the Gemini system instructions. - Reference Data:
ARCHETYPE_DATAincomponents/LandingPage.tsxprovides static descriptions for marketing and SEO.