A Notion-like diary application with AI-powered insights, built with React, TypeScript, and Supabase.
- Rich Text Editor: Markdown-style formatting with real-time preview
- AI-Powered Insights: Generate intelligent insights about your diary entries
- Document Management: Create, edit, and organize your diary entries
- Google Authentication: Secure login with Google OAuth
- Cross-Device Sync: Data syncs across devices via Supabase
- Memory Context: AI remembers your past entries for better insights
- Template System: Pre-built templates for different types of entries
- Fish Tank Animation: Delightful UI element with interactive animations
- Frontend: React 18 + TypeScript + Vite
- Styling: Tailwind CSS
- Authentication: Supabase Auth (Google OAuth)
- Database: Supabase (PostgreSQL)
- AI Services: OpenAI GPT-4
- Memory/Vector DB: Pinecone
- Deployment: Vercel
success-diary/
βββ src/
β βββ components/ # React components
β βββ services/ # API and external service integrations
β βββ types/ # TypeScript type definitions
β βββ utils/ # Utility functions
β βββ App.tsx # Main application component
β βββ main.tsx # Application entry point
βββ public/ # Static assets
βββ dist/ # Build output
βββ Configuration files
Location: src/App.tsx
Purpose: Main application orchestrator and state management
Key Responsibilities:
- User authentication state management
- Document CRUD operations
- AI insight generation coordination
- Memory context management
- Local/Supabase data synchronization
Key State Variables:
const [documents, setDocuments] = useState<Document[]>([]);
const [currentDocument, setCurrentDocument] = useState<Document | null>(null);
const [insights, setInsights] = useState<Insight[]>([]);
const [user, setUser] = useState<any>(null);
const [memoryContext, setMemoryContext] = useState<MemoryContext | undefined>();Key Functions:
handleGoogleLogin()- Initiates Google OAuth flowhandleLogout()- Signs out user and clears statehandleSaveDocument()- Saves document to local storage and SupabasehandleGenerateInsight()- Generates AI insights for current documentloadMemoryContext()- Loads relevant past entries for AI context
Location: src/components/Editor.tsx
Purpose: Main text editing interface with formatting tools
Features:
- Real-time markdown-style formatting
- Template system integration
- Auto-save functionality
- Preview mode for non-authenticated users
- Authentication UI in toolbar
Key Props:
interface EditorProps {
document: Document | null;
onSave: (document: Document) => void;
onUpdate: (document: Document) => void;
isPreviewMode?: boolean;
user?: any;
onLogout?: () => void;
onLogin?: () => void;
}Key Functions:
handleSave()- Saves current document with sanitizationinsertText()- Inserts formatted text at cursor positionhandleSelectTemplate()- Applies template to current document
Location: src/components/Sidebar.tsx
Purpose: Document list and navigation interface
Features:
- Document list with search functionality
- Document preview snippets
- Create new document button
- Authentication buttons (login/logout)
- Delete document functionality
Key Props:
interface SidebarProps {
documents: Document[];
currentDocument: Document | null;
onNewDocument: () => void;
onSelectDocument: (document: Document) => void;
onDeleteDocument: (documentId: string) => void;
isPreviewMode?: boolean;
user?: any;
onLogout?: () => void;
onLogin?: () => void;
}Location: src/components/InsightsPanel.tsx
Purpose: AI-powered insights generation and display
Features:
- Single-turn insight generation
- Multi-turn conversation insights
- Insight export (JSON/Text)
- Insight sharing
- Memory context display
- Resizable panel
Key Props:
interface InsightsPanelProps {
documentId: string;
documentContent: string;
insights: Insight[];
onGenerateInsight: (request: InsightRequest) => Promise<void>;
onDeleteInsight: (insightId: string) => void;
onSyncInsights: () => Promise<void>;
isLoading: boolean;
memoryContext?: MemoryContext;
}Location: src/components/FishTank.tsx
Purpose: Delightful UI animation element
Features:
- Expandable fish tank animation
- Interactive fish movement
- Bubble generation
- Click interactions
- Performance-optimized animations
Location: src/services/supabase.ts
Purpose: Handles all Supabase interactions
Key Functions:
// Authentication
export const signInWithGoogle = async () => Promise<AuthResponse>
export const signOut = async () => Promise<{ data: null, error: any }>
export const handleAuthCallback = async () => Promise<{ data: any, error: any }>
// Document Operations
export const saveDocumentToSupabase = async (document: Document) => Promise<void>
export const loadDocumentsFromSupabase = async () => Promise<Document[]>
export const deleteDocumentFromSupabase = async (documentId: string) => Promise<void>
// Insight Operations
export const saveInsightToSupabase = async (insight: Insight) => Promise<void>
export const loadInsightsFromSupabase = async (documentId: string) => Promise<Insight[]>
export const deleteInsightFromSupabase = async (insightId: string) => Promise<void>Location: src/services/ai.ts
Purpose: OpenAI GPT-4 integration for insight generation
Key Functions:
export const generateInsight = async (request: InsightRequest) => Promise<Insight>
export const generateEnhancedInsight = async (request: EnhancedInsightRequest) => Promise<Insight>AI Prompt Engineering:
- Context-aware prompts using memory system
- Structured output for consistent insights
- Multi-turn conversation support
- Error handling and fallbacks
Location: src/services/memory.ts
Purpose: Vector-based memory system for AI context
Key Functions:
export const storeMemory = async (memory: Memory) => Promise<string>
export const searchMemories = async (query: string, userId: string) => Promise<MemorySearchResult[]>
export const getMemoryContext = async (currentContent: string, userId: string) => Promise<MemoryContext>
export const extractMemoryFromContent = async (content: string, userId: string) => Promise<string>Memory System Features:
- Semantic search using embeddings
- Context summarization
- Suggestion generation
- Local storage fallback
Location: src/services/templates.ts
Purpose: Pre-built document templates
Key Functions:
export const getTemplates = (): Template[]
export const getTemplateById = (id: string): Template | undefined// Document Model
interface Document {
id: string;
title: string;
content: string;
createdAt: Date;
updatedAt: Date;
tags?: string[];
insights?: Insight[];
}
// Insight Model
interface Insight {
id: string;
documentId: string;
type: 'single' | 'multi';
content: string;
createdAt: Date;
conversationHistory?: any[];
metadata?: any;
}
// Memory Model
interface Memory {
id: string;
userId: string;
content: string;
tags: string[];
context: string;
createdAt: Date;
embedding?: number[];
}
// AI Request Models
interface InsightRequest {
documentId: string;
type: 'single' | 'multi';
prompt?: string;
conversationHistory?: any[];
}
interface EnhancedInsightRequest extends InsightRequest {
memoryContext?: MemoryContext;
previousInsights?: Insight[];
}- Google OAuth Console: Configure authorized origins and redirect URIs
- Supabase Auth Settings: Set up site URL and redirect URLs
- Environment Variables: Configure Supabase URL and keys
- Unauthenticated: Preview mode with sample documents
- Authenticated: Full functionality with data persistence
- Framework: Vite
- Build Command:
npm run build - Node Version: 18+
- Environment Variables: Required for Supabase and OpenAI
VITE_SUPABASE_URL=your_supabase_url
VITE_SUPABASE_ANON_KEY=your_supabase_anon_key
VITE_OPENAI_API_KEY=your_openai_api_key
VITE_PINECONE_API_KEY=your_pinecone_api_key
VITE_PINECONE_ENVIRONMENT=your_pinecone_environment- Follow existing component patterns in
src/components/ - Use TypeScript interfaces for props
- Implement proper error handling
- Add loading states where appropriate
- Add new services to
src/services/ - Follow existing error handling patterns
- Implement local storage fallbacks
- Add proper TypeScript types
- Use React hooks for local state
- Follow existing patterns in
App.tsx - Consider data persistence requirements
- Implement proper cleanup
- TypeScript: Strict mode enabled
- ESLint: Configured for React and TypeScript
- Prettier: Consistent code formatting
- Error Handling: Comprehensive error boundaries
- Performance: Optimized re-renders and animations
- Unit Tests: Component and utility function testing
- Integration Tests: Service and API testing
- E2E Tests: User flow testing
- Performance Tests: Animation and rendering optimization
- Check Google OAuth configuration
- Verify Supabase auth settings
- Check environment variables
- Review browser console for errors
- Verify OpenAI API key
- Check Pinecone configuration
- Review memory service logs
- Test with simple prompts
- Check Supabase connection
- Verify local storage permissions
- Review network connectivity
- Check data validation
- Browser DevTools: Network and console monitoring
- Supabase Dashboard: Real-time database monitoring
- OpenAI API: Usage and error monitoring
- Vercel Analytics: Performance monitoring
- Code Splitting: Vendor and utility chunks
- Lazy Loading: Component-level code splitting
- Memoization: React.memo for expensive components
- Animation Optimization: RequestAnimationFrame usage
- Bundle Optimization: Tree shaking and minification
- Service Worker: Offline functionality
- Virtual Scrolling: Large document lists
- Image Optimization: Asset compression
- Caching Strategy: Intelligent data caching
- Clone repository
- Install dependencies:
npm install - Set up environment variables
- Start development server:
npm run dev - Build for production:
npm run build
- Create feature branch
- Implement changes with tests
- Update documentation
- Submit pull request
- Code review and approval
MIT License - see LICENSE file for details
For AI Coders: This documentation provides a comprehensive overview of the Success Diary application architecture. Key areas to focus on when making changes:
- State Management: All main state is managed in
App.tsx - Service Layer: External integrations are in
src/services/ - Component Structure: Follow existing patterns in
src/components/ - Type Safety: All interfaces are defined in
src/types/ - Error Handling: Implement comprehensive error handling
- Performance: Consider impact on animations and user experience