# Arete Domain

> **Arete** - Personal Development and Life Mastery Platform

Arete is a library-only domain providing a comprehensive personal development
platform grounded in Stephen Covey's _7 Habits of Highly Effective People_
framework. It spans 11 libraries covering habit tracking, goal setting,
journaling, vision boards, time management, life balance assessment,
gamification, and AI-powered coaching.

The core library defines 58 Zod validation schemas, 42 Drizzle ORM database
tables with full relations, PostgreSQL triggers for automatic streak
calculation, aggregation functions for user statistics, and full-text search
indexes on journal content.

---

## Architecture

```
                         @arete/core
                  (schemas, DB schema, seeds)
                    /    |    |    |    \
                   /     |    |    |     \
     @arete/habits  @arete/goals  @arete/journal  @arete/time  @arete/vision
     @arete/balance  @arete/seven-habits  @arete/affirmations
                   \     |    |    /
                    \    |    |   /
              @arete/gamification
                       |
              @arete/ai-coach
```

All feature libraries depend on `@arete/core` as a peer dependency. The
`@arete/gamification` and `@arete/ai-coach` libraries sit on top of the feature
layer and provide cross-cutting concerns.

---

## Libraries (11)

### `@arete/core` - Core Framework

The foundation library providing all domain types, validation schemas, and
database definitions.

**Key exports:**

- **58 Zod schemas** with full validation rules and inferred TypeScript types
  covering: `UserProfile`, `PersonalMission`, `Value`, `Role`, `Goal`,
  `SMARTGoal`, `OKR`, `KeyResult`, `WOOPGoal`, `ImplementationIntention`,
  `Habit`, `HabitCue`, `HabitRoutine`, `HabitReward`, `HabitStack`,
  `HabitCompletion`, `Streak`, `StreakFreeze`, `JournalEntry`, `JournalPrompt`,
  `JournalTemplate`, `ThoughtRecord`, `GratitudeEntry`, `VisionBoard`,
  `VisionBoardItem`, `Task`, `BigRock`, `WeeklyPlan`, `DailyPlan`, `TimeBlock`,
  `PomodoroSession`, `DeepWorkSession`, `CircleOfInfluence`,
  `EmotionalBankAccount`, `EmotionalTransaction`, `WheelOfLife`, `MoodEntry`,
  `Affirmation`, `Achievement`, `Badge`, `Level`, `Points`,
  `AccountabilityPartner`, `CommitmentContract`, `Challenge`, and more.
- **42 Drizzle ORM table definitions** with 18 PostgreSQL enum types, foreign
  key relationships with cascading deletes, JSONB columns for flexible data, and
  comprehensive indexing.
- **Full Drizzle relations** for all tables enabling nested queries.
- **`STREAK_CALCULATION_TRIGGER_SQL`** - A PostgreSQL trigger function that
  automatically recalculates streak counts when habit completions are inserted,
  including forgiveness-day logic for missed days.
- **`STATISTICS_AGGREGATION_SQL`** - PostgreSQL functions for computing
  aggregated stats: `arete_total_completions`, `arete_average_mood`,
  `arete_average_energy`, `arete_goal_completion_rate`, `arete_total_xp`,
  `arete_habit_completion_rate`, `arete_journal_stats`,
  `arete_wheel_of_life_trend`, `arete_deep_work_hours`.
- **`JOURNAL_FULLTEXT_INDEX_SQL`** - GIN full-text search indexes on journal
  entry content and titles.
- **`ALL_ARETE_TABLES`**, **`ALL_ARETE_RELATIONS`**, **`ALL_ARETE_ENUMS`** -
  Arrays of all definitions for iteration/introspection.

**Dependencies:** `drizzle-orm`, `zod`

---

### `@arete/habits` - Comprehensive Habit Engine

10 modules implementing evidence-based habit formation techniques.

| Module        | Description                                |
| ------------- | ------------------------------------------ |
| `crud`        | Habit CRUD operations                      |
| `habit-loop`  | Atomic Habits cue-routine-reward model     |
| `four-laws`   | Four Laws of Behavior Change (James Clear) |
| `stacking`    | Habit Stacking (BJ Fogg's Tiny Habits)     |
| `celebration` | Celebration and reinforcement patterns     |
| `streaks`     | Streak system with forgiveness days        |
| `identity`    | Identity-based habits (becoming vs doing)  |
| `keystone`    | Keystone habit identification and tracking |
| `analytics`   | Habit analytics and insights               |
| `reminders`   | Reminder and notification scheduling       |

**Peer dependency:** `@arete/core`

---

### `@arete/goals` - Comprehensive Goal Management

8 modules for goal setting using multiple established frameworks.

| Module             | Description                            |
| ------------------ | -------------------------------------- |
| `crud`             | Goal CRUD with hierarchical nesting    |
| `hierarchy`        | Parent-child goal trees                |
| `smart`            | SMART criteria goal framework          |
| `okr`              | Objectives and Key Results (quarterly) |
| `woop`             | WOOP mental contrasting framework      |
| `twelve-week-year` | 12 Week Year periodization             |
| `progress`         | Progress tracking and milestones       |
| `analytics`        | Goal completion analytics              |

**Peer dependency:** `@arete/core`

---

### `@arete/journal` - Journaling and Reflection Engine

9 modules for structured journaling and cognitive reflection.

| Module                | Description                                                 |
| --------------------- | ----------------------------------------------------------- |
| `crud`                | Rich-text entries with tagging and version history          |
| `morning-pages`       | Julia Cameron's 750-word morning practice                   |
| `five-minute-journal` | Morning + evening reflection templates                      |
| `gratitude`           | Categorized gratitude entries with trends                   |
| `thought-records`     | CBT thought records for cognitive distortion identification |
| `worry-journal`       | Scheduled worry time with pattern analysis                  |
| `prompted-journal`    | 300+ prompts across 6 categories                            |
| `reflection`          | Daily, weekly, monthly, quarterly, annual reviews           |
| `analytics`           | Sentiment, emotion detection, and insights                  |

**Peer dependency:** `@arete/core`

---

### `@arete/time` - Time Management and Productivity

9 modules based on proven time management frameworks.

| Module           | Description                                         |
| ---------------- | --------------------------------------------------- |
| `eisenhower`     | Covey's Eisenhower Matrix (4 quadrants)             |
| `gtd-inbox`      | Getting Things Done capture and processing          |
| `gtd-review`     | GTD 3-phase weekly review process                   |
| `big-rocks`      | Covey's priorities-first approach                   |
| `time-blocking`  | Intentional scheduling with templates               |
| `pomodoro`       | Pomodoro technique focused work sessions            |
| `deep-work`      | Cal Newport's deep work methodology                 |
| `daily-planning` | MIT, 1:4:5 ratios, shutdown rituals                 |
| `time-audit`     | Time tracking, insights, planning fallacy detection |

**Peer dependency:** `@arete/core`

---

### `@arete/vision` - Vision and Purpose

6 modules for personal vision, purpose discovery, and legacy planning.

| Module                 | Description                                         |
| ---------------------- | --------------------------------------------------- |
| `vision-board`         | Visual goal board builder (image, text, goal links) |
| `mission-statement`    | Personal mission statement builder                  |
| `values-clarification` | Core values identification and prioritization       |
| `ikigai`               | Japanese Ikigai framework                           |
| `golden-circle`        | Simon Sinek's Why/How/What model                    |
| `legacy`               | Legacy and long-term impact planning                |

**Peer dependency:** `@arete/core`

---

### `@arete/balance` - Life Balance and Wellness

7 modules for holistic life balance assessment.

| Module                | Description                                  |
| --------------------- | -------------------------------------------- |
| `wheel-of-life`       | 10-dimension life satisfaction assessment    |
| `wellness-dimensions` | 8 dimensions of wellness tracking            |
| `perma`               | Seligman's PERMA model (Positive Psychology) |
| `mood-tracking`       | Mood and energy check-ins (1-5 scale)        |
| `sleep-tracking`      | Sleep quality and duration tracking          |
| `energy-management`   | Energy level management throughout the day   |
| `life-satisfaction`   | Satisfaction With Life Scale (SWLS)          |

**Peer dependency:** `@arete/core`

---

### `@arete/seven-habits` - Covey's 7 Habits Framework

8 modules implementing all 7 habits plus the Emotional Bank Account concept.

| Module                   | Description                                      |
| ------------------------ | ------------------------------------------------ |
| `be-proactive`           | Habit 1 - Circle of Influence vs Concern         |
| `begin-with-end`         | Habit 2 - Personal Leadership and vision         |
| `put-first-things-first` | Habit 3 - Personal Management and prioritization |
| `think-win-win`          | Habit 4 - Interpersonal Leadership               |
| `seek-to-understand`     | Habit 5 - Empathic Communication                 |
| `synergize`              | Habit 6 - Creative Cooperation                   |
| `sharpen-the-saw`        | Habit 7 - Balanced Self-Renewal (4 dimensions)   |
| `emotional-bank-account` | Relationship trust deposits/withdrawals          |

**Peer dependency:** `@arete/core`

---

### `@arete/affirmations` - Affirmation Engine

2 modules for affirmation management and generation.

| Module            | Description                                                            |
| ----------------- | ---------------------------------------------------------------------- |
| `management`      | 500+ curated affirmations, CRUD, scheduling, widgets, reminders, stats |
| `ai-affirmations` | Rule-based generation, templates, personalization, suggestions         |

**Peer dependency:** `@arete/core`

---

### `@arete/gamification` - Gamification Engine

8 modules for gamifying personal development.

| Module           | Description                                                                       |
| ---------------- | --------------------------------------------------------------------------------- |
| `points`         | XP, coins, gems, multipliers, consistency bonuses                                 |
| `badges`         | 50+ badges, unlock tracking, seasonal badges, tiers (bronze/silver/gold/platinum) |
| `levels`         | 20 levels with XP curve and feature unlocks                                       |
| `leaderboards`   | Global/friend views, privacy controls, rank detection                             |
| `accountability` | Accountability partnerships, check-ins, encouragement                             |
| `contracts`      | Commitment contracts with stakes, referees, anti-charities                        |
| `challenges`     | Community challenge templates, progress tracking, rewards                         |
| `rewards`        | Reward suggestions, custom rewards, redemption system                             |

**Peer dependency:** `@arete/core`

---

### `@arete/ai-coach` - AI-Powered Coaching

5 modules for intelligent personal development coaching.

| Module            | Description                                                                       |
| ----------------- | --------------------------------------------------------------------------------- |
| `coaching`        | Conversational coaching with CBT, goals, habits, reflection, and motivation modes |
| `recommendations` | Personalized recommendations for habits, goals, content, timing, and challenges   |
| `patterns`        | Pattern recognition across habits, moods, energy, and productivity                |
| `nlp-analytics`   | Journal NLP analytics: sentiment, emotions, topics, trends                        |
| `notifications`   | Smart notification timing, personalization, nudges, effectiveness tracking        |

**Peer dependency:** `@arete/core`

---

## Database

**PostgreSQL** with the `arete_` table prefix.

- **42 tables** across habits, goals, journals, vision boards, time management,
  life balance, gamification, and accountability
- **18 enum types** for strongly-typed status fields
- **Full relational model** with foreign keys and cascading deletes
- **Automatic streak calculation** via PostgreSQL trigger on habit completions
- **Full-text search** via GIN indexes on journal entries
- **Aggregation functions** for user statistics (completions, mood, energy, XP,
  goals, deep work hours, wheel of life trends)

---

## Technology Stack

| Layer      | Technology               |
| ---------- | ------------------------ |
| Language   | TypeScript (ESM)         |
| Validation | Zod (58 schemas)         |
| ORM        | Drizzle ORM (PostgreSQL) |
| Build      | `@nx/js:tsc`             |
| Testing    | Vitest                   |
| Database   | PostgreSQL               |

---

## Configuration

**Project tags:** `["scope:arete", "layer:domain", "type:lib"]`

**Build executor:** `@nx/js:tsc`

**Test executor:** `@nx/vite:test` with per-library vitest configs

---

## Development

```bash
# Run tests for a single library
pnpm nx test @arete/core
pnpm nx test @arete/habits

# Build a single library
pnpm nx build @arete/core

# Lint a single library
pnpm nx lint @arete/core

# Run all arete tests
pnpm nx run-many --target=test --projects=tag:scope:arete

# Build all arete libraries
pnpm nx run-many --target=build --projects=tag:scope:arete
```

---

## Related Domains

- **Tara** - Meditation and mindfulness app that could integrate Arete for habit
  tracking and goal setting features
- **Kuanyin** - Compassion and ethics domain providing complementary wellness
  frameworks
