# aiwithrajan/touchgrass architecture

> Architecture diagram of the GitHub repository aiwithrajan/touchgrass, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aiwithrajan/touchgrass
- Repository: https://github.com/aiwithrajan/touchgrass

## Overview

TouchGrass is a real-world mission and habit-building app: it turns a user’s preferences, history, difficulty, and available time into a safe outdoor or social challenge, then supports an offline interval, reflection, and progression rewards. The documented frontend states are Attract, Release, and Reward; the product also exposes Social Mode, Journey Cards, voice, vitality forecasts, and agent observability. The graph follows the README’s architecture and sampled backend routes; unsampled UI and service wiring is shown only where documented, so some links are omitted.

Main entry points: [`backend/app/main.py`](https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/main.py) (FastAPI Routes), [`frontend/src/App.tsx`](https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/App.tsx) (TouchGrass UI), [`backend/app/services/memory_service.py`](https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/services/memory_service.py) (Memory Service), [`backend/app/agent/gemma_orchestrator.py`](https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/agent/gemma_orchestrator.py) (Mission Orchestrator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User Experience"]
  node_web_app["TouchGrass UI<br/>[App.tsx]"]
  node_attract["Attract State<br/>[AttractState.tsx]"]
  node_release["Release State<br/>[ReleaseState.tsx]"]
  node_reward_ui["Reward State<br/>[RewardState.tsx]"]
  node_social["Social Mode<br/>[SocialMode.tsx]"]
  node_journey["Journey View<br/>[JourneyView.tsx]"]
  node_observability_ui["Observability Drawer"]
  node_api_client["API Client<br/>[api.ts]"]
end

subgraph group_mission["Mission Agent"]
  node_orchestrator["Mission Orchestrator"]
  node_policy["Safety &amp; Diversity<br/>[policy_engine.py]"]
  node_reflection["Reflection Evaluator<br/>[reflection_eval.py]"]
end

subgraph group_progress["Progress &amp; Memory"]
  node_memory["Memory Service<br/>[memory_service.py]"]
  node_local_store[("Local JSON Store<br/>[user_memory.json]")]
  node_reward["Progression Rewards<br/>[reward_service.py]"]
end

subgraph group_platform["API &amp; Integrations"]
  node_api["FastAPI Routes<br/>[main.py]"]
  node_schemas["Domain Schemas<br/>[schemas.py]"]
  node_voice["Voice Service<br/>[voice_service.py]"]
  node_vitality["Vitality Forecast<br/>[tabpfn_service.py]"]
  node_tracing["Agent Tracing<br/>[sentry_service.py]"]
end

node_user(("User"))
node_gemma["Local Gemma Runtime"]
node_elevenlabs["ElevenLabs"]
node_browser_speech["Browser Speech"]
node_mongodb[("MongoDB Atlas")]

node_user -->|"uses"| node_web_app
node_web_app -->|"shows mission"| node_attract
node_web_app -->|"starts release"| node_release
node_web_app -->|"shows reward"| node_reward_ui
node_web_app -->|"requests data"| node_api_client
node_api_client -->|"calls routes"| node_api
node_api -->|"loads user"| node_memory
node_api -->|"generates challenge"| node_orchestrator
node_orchestrator -->|"validates challenge"| node_policy
node_orchestrator -.->|"requests generation"| node_gemma
node_api -->|"uses models"| node_schemas
node_api -->|"requests speech"| node_voice
node_voice -.->|"synthesizes speech"| node_elevenlabs
node_voice -->|"offers fallback"| node_browser_speech
node_api -->|"evaluates reflection"| node_reflection
node_api -->|"calculates reward"| node_reward
node_api -->|"records completion"| node_memory
node_memory -->|"reads and writes"| node_local_store
node_memory -.->|"syncs data"| node_mongodb
node_api -->|"forecasts conditions"| node_vitality
node_api -->|"records spans"| node_tracing
node_api -->|"serves feed"| node_social
node_api -->|"serves journey card"| node_journey
node_api -->|"serves trace data"| node_observability_ui
node_reward -->|"returns progression"| node_reward_ui

click node_web_app "https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/App.tsx"
click node_attract "https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/components/AttractState.tsx"
click node_release "https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/components/ReleaseState.tsx"
click node_reward_ui "https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/components/RewardState.tsx"
click node_social "https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/components/SocialMode.tsx"
click node_journey "https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/components/JourneyView.tsx"
click node_observability_ui "https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/components/ObservabilityDrawer.tsx"
click node_api_client "https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/api.ts"
click node_api "https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/main.py"
click node_schemas "https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/models/schemas.py"
click node_orchestrator "https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/agent/gemma_orchestrator.py"
click node_policy "https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/agent/policy_engine.py"
click node_reflection "https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/agent/reflection_eval.py"
click node_memory "https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/services/memory_service.py"
click node_local_store "https://github.com/aiwithrajan/touchgrass/blob/main/backend/data/user_memory.json"
click node_reward "https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/services/reward_service.py"
click node_voice "https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/services/voice_service.py"
click node_vitality "https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/services/tabpfn_service.py"
click node_tracing "https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/services/sentry_service.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web_app,node_attract,node_release,node_reward_ui,node_social,node_journey,node_observability_ui,node_api_client,node_user,node_browser_speech toneBlue
class node_orchestrator,node_policy,node_reflection,node_mongodb toneAmber
class node_memory,node_local_store,node_reward toneMint
class node_api,node_schemas,node_voice,node_vitality,node_tracing toneRose
class node_gemma,node_elevenlabs toneIndigo
```

## Components

### User Experience

- [TouchGrass UI](https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Attract State](https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/components/AttractState.tsx): `frontend/src/components/AttractState.tsx`
- [Release State](https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/components/ReleaseState.tsx): `frontend/src/components/ReleaseState.tsx`
- [Reward State](https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/components/RewardState.tsx): `frontend/src/components/RewardState.tsx`
- [Social Mode](https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/components/SocialMode.tsx): `frontend/src/components/SocialMode.tsx`
- [Journey View](https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/components/JourneyView.tsx): `frontend/src/components/JourneyView.tsx`
- [Observability Drawer](https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/components/ObservabilityDrawer.tsx): `frontend/src/components/ObservabilityDrawer.tsx`
- [API Client](https://github.com/aiwithrajan/touchgrass/blob/main/frontend/src/api.ts): `frontend/src/api.ts`

### Mission Agent

- [Mission Orchestrator](https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/agent/gemma_orchestrator.py): `backend/app/agent/gemma_orchestrator.py`
- [Safety & Diversity](https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/agent/policy_engine.py): `backend/app/agent/policy_engine.py`
- [Reflection Evaluator](https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/agent/reflection_eval.py): `backend/app/agent/reflection_eval.py`

### Progress & Memory

- [Memory Service](https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/services/memory_service.py): `backend/app/services/memory_service.py`
- [Local JSON Store](https://github.com/aiwithrajan/touchgrass/blob/main/backend/data/user_memory.json): `backend/data/user_memory.json`
- [Progression Rewards](https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/services/reward_service.py): `backend/app/services/reward_service.py`

### API & Integrations

- [FastAPI Routes](https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/main.py): `backend/app/main.py`
- [Domain Schemas](https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/models/schemas.py): `backend/app/models/schemas.py`
- [Voice Service](https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/services/voice_service.py): `backend/app/services/voice_service.py`
- [Vitality Forecast](https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/services/tabpfn_service.py): `backend/app/services/tabpfn_service.py`
- [Agent Tracing](https://github.com/aiwithrajan/touchgrass/blob/main/backend/app/services/sentry_service.py): `backend/app/services/sentry_service.py`

### Other components

- **User**
- **Local Gemma Runtime**
- **ElevenLabs**
- **Browser Speech**
- **MongoDB Atlas**

## Connections

- User → TouchGrass UI: uses (evidence: `README.md`)
- TouchGrass UI → Attract State: shows mission (evidence: `README.md`)
- TouchGrass UI → Release State: starts release (evidence: `README.md`)
- TouchGrass UI → Reward State: shows reward (evidence: `README.md`)
- TouchGrass UI → API Client: requests data (evidence: `README.md`)
- API Client → FastAPI Routes: calls routes (evidence: `README.md`)
- FastAPI Routes → Memory Service: loads user (evidence: `backend/app/main.py`)
- FastAPI Routes → Mission Orchestrator: generates challenge (evidence: `backend/app/main.py`)
- Mission Orchestrator → Safety & Diversity: validates challenge (evidence: `backend/app/agent/gemma_orchestrator.py`)
- Mission Orchestrator → Local Gemma Runtime: requests generation (evidence: `README.md`)
- FastAPI Routes → Domain Schemas: uses models (evidence: `backend/app/main.py`)
- FastAPI Routes → Voice Service: requests speech (evidence: `backend/app/main.py`)
- Voice Service → ElevenLabs: synthesizes speech (evidence: `backend/app/services/voice_service.py`)
- Voice Service → Browser Speech: offers fallback (evidence: `backend/app/services/voice_service.py`)
- FastAPI Routes → Reflection Evaluator: evaluates reflection (evidence: `backend/app/main.py`)
- FastAPI Routes → Progression Rewards: calculates reward (evidence: `backend/app/main.py`)
- FastAPI Routes → Memory Service: records completion (evidence: `backend/app/main.py`)
- Memory Service → Local JSON Store: reads and writes (evidence: `backend/app/services/memory_service.py`)
- Memory Service → MongoDB Atlas: syncs data (evidence: `backend/app/services/memory_service.py`)
- FastAPI Routes → Vitality Forecast: forecasts conditions (evidence: `backend/app/main.py`)
- FastAPI Routes → Agent Tracing: records spans (evidence: `backend/app/main.py`)
- FastAPI Routes → Social Mode: serves feed (evidence: `README.md`)
- FastAPI Routes → Journey View: serves journey card (evidence: `README.md`)
- FastAPI Routes → Observability Drawer: serves trace data (evidence: `README.md`)
- Progression Rewards → Reward State: returns progression (evidence: `README.md`)
