Skip to content

ErnieAtLYD/reflect-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

137 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Reflect App

A modern journaling application with AI-powered reflection capabilities. Built with Next.js, TypeScript, and OpenAI integration to provide users with meaningful insights into their journal entries.

πŸš€ Features

Core Functionality

  • AI-Powered Journaling - Get automated reflections, pattern detection, and actionable suggestions
  • Journal Entry Input - Enhanced textarea with auto-resize, validation, and character counting
  • Real-time Feedback - Instant validation and feedback on journal entries
  • Responsive Design - Optimized experience across all devices and screen sizes
  • Dark/Light Mode - Full theme support with system preference detection

Technical Features

  • Next.js 15 with App Router
  • OpenAI Integration - GPT-4 Turbo with GPT-3.5 Turbo fallback
  • TypeScript for type safety
  • Tailwind CSS v4 with CSS variables for theming
  • shadcn/ui for beautiful, accessible UI components
  • Rate Limiting & Caching - Optimized AI API usage with cost reduction
  • Comprehensive Testing - Unit tests with Vitest + E2E tests with Playwright
  • Code Quality - ESLint, Prettier, Husky pre-commit hooks
  • Path aliases (@/*) configured
  • Vercel deployment ready

Architecture Philosophy

This application follows a simplified, standard-first approach:

  • Standard HTML elements for accessibility (no over-engineered custom focus management)
  • Component simplicity over complex abstractions
  • Testing reliability with standard patterns
  • Maintainability through clear, readable code

Note: A comprehensive custom focus management system was removed in September 2025 to reduce complexity and improve maintainability.

πŸ“¦ Package Manager

This project uses pnpm for faster, more efficient dependency management.

πŸ› οΈ Getting Started

Prerequisites

  • Node.js 18+ and pnpm
  • OpenAI API key (required for AI features)

Installation

# Install dependencies
pnpm install

# Set up environment variables
cp .env.example .env.local

# Add your OpenAI API key to .env.local
echo "OPENAI_API_KEY=your_openai_api_key_here" >> .env.local

# Start development server
pnpm dev

Environment Setup

The application requires several environment variables for full functionality:

Required:

OPENAI_API_KEY=your_openai_api_key_here

Optional (with defaults):

# AI Model Configuration
OPENAI_MODEL=gpt-4-1106-preview
OPENAI_FALLBACK_MODEL=gpt-3.5-turbo-1106
OPENAI_MAX_TOKENS=500
OPENAI_TEMPERATURE=0.7

# Rate Limiting
AI_RATE_LIMIT_RPM=10

# Caching
AI_CACHE_TTL=3600

Get your OpenAI API key from: https://platform.openai.com/api-keys

Available Scripts

# Development
pnpm dev              # Start development server
pnpm build            # Build for production
pnpm start            # Start production server

# Code Quality
pnpm lint             # Run ESLint
pnpm format           # Format code with Prettier
pnpm format:check     # Check code formatting

# Testing
pnpm test             # Run unit tests
pnpm test:ui          # Run tests with UI
pnpm test:coverage    # Run tests with coverage
pnpm test:e2e         # Run e2e tests
pnpm test:e2e:ui      # Run e2e tests with UI
pnpm test:e2e:debug   # Debug e2e tests

πŸ§ͺ Testing

Unit Tests

  • Vitest for fast unit testing
  • @testing-library/react for React component testing
  • jsdom environment for DOM testing
  • Test files: **/__tests__/**/*.test.{ts,tsx}

E2E Tests

  • Playwright for end-to-end testing
  • Tests across Chrome, Firefox, and Safari
  • Test files: e2e/**/*.spec.ts

🎨 UI Components

This application includes custom and shadcn/ui components:

Custom Components

  • JournalEntryInput - Enhanced textarea for journal writing with auto-resize, validation, and character counting
  • LoadingSpinner - Animated loading indicators with size/color variants
  • ErrorMessage - Accessible error display with icons and variants
  • Feedback - Thumbs up/down rating component for user feedback
  • ThemeToggle - Light/dark/system mode switching

shadcn/ui Components

  • Button, Card, Input, Label, Textarea, Dialog

Add more shadcn/ui components with:

pnpm dlx shadcn@latest add [component-name]

πŸ“ Project Structure

src/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   └── reflect/           # AI processing endpoint
β”‚   β”‚   └── page.tsx              # Main application page
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ ui/                   # UI components (buttons, inputs, etc.)
β”‚   └── __tests__/           # Component unit tests
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ openai.ts            # OpenAI service utilities
β”‚   β”œβ”€β”€ ai-client.ts         # Client-side AI utilities
β”‚   └── utils.ts             # General utilities
β”œβ”€β”€ types/
β”‚   └── ai.ts                # AI service type definitions
└── test/                    # Test setup and utilities

e2e/                         # Playwright end-to-end tests
.taskmaster/                 # Project task management

πŸ”§ Configuration

  • ESLint: Extends Next.js config
  • Prettier: Includes Tailwind plugin for class sorting
  • Tailwind: v4 with CSS variables for theming
  • TypeScript: Strict mode enabled
  • Path Aliases: @/* maps to src/*

πŸ€– AI Integration

The app uses OpenAI's API to provide intelligent reflections on journal entries:

API Endpoint

  • POST /api/reflect - Process journal entries with AI

Features

  • Dual Model Support - GPT-4 Turbo primary, GPT-3.5 Turbo fallback
  • Rate Limiting - 10 requests/minute per IP (configurable)
  • Caching - Reduces API costs for similar entries
  • Error Handling - Comprehensive error types and recovery
  • Response Format - Summary, pattern detection, actionable suggestions

Client Usage

import { aiClient } from '@/lib/ai-client'

const response = await aiClient.processEntry({
  content: 'Your journal entry here...',
})

console.log(response.summary) // Brief summary
console.log(response.pattern) // Detected pattern/theme
console.log(response.suggestion) // Actionable suggestion

πŸš€ Deployment

Vercel (Recommended)

  1. Push to GitHub
  2. Import project in Vercel
  3. Add environment variables:
    • OPENAI_API_KEY (required)
    • Other optional AI configuration variables
  4. Deploy automatically

Other Platforms

Works on any platform supporting Next.js. Ensure environment variables are configured properly.

πŸ›‘οΈ Code Quality

  • Pre-commit hooks with Husky
  • Lint-staged for staged file linting
  • ESLint + Prettier integration
  • TypeScript strict mode

πŸ“Š Performance

  • Next.js 15 performance optimizations
  • Static generation where possible
  • Optimal bundle splitting
  • Image optimization built-in

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and linting
  5. Submit a pull request

πŸ“ License

MIT License - see LICENSE file for details.

About

A modern journaling application with AI-powered reflection capabilities.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors