Skip to content

Syamgith/ai-dream-journal

Repository files navigation

Dream Journal AI πŸŒ™βœ¨

An AI-powered dream journal that helps you record, analyze, and explore your dreams with advanced natural language processing and semantic search.

🌐 Quick Links

Login Dream List Add Dream

🎯 Overview

Dream Journal AI combines cutting-edge AI technology with psychological dream analysis to help users record, interpret, and explore their dreams. Using Google's Gemini AI and vector embeddings, it provides personalized dream insights and pattern discovery.

✨ Key Features

πŸ€– AI-Powered Interpretation

  • Smart Dream Analysis: Google Gemini AI generates personalized dream interpretations
  • Auto-Title Generation: AI creates meaningful titles for your dreams

πŸ” Dream Explorer

  • Conversational Interface: Chat with your dream history using natural language
  • Semantic Search: Find dreams by meaning, not just keywords (pgvector + sentence transformers)
  • Pattern Analysis: Discover recurring themes, symbols, and emotions
  • Dream Comparison: Compare two dreams to find connections and insights
  • Smart Fallback: 3-level search (semantic β†’ keyword β†’ text) ensures results

πŸ” Security & Authentication

  • JWT-based authentication
  • Google OAuth integration
  • Secure password hashing with bcrypt

πŸ›  Technology Stack

Backend

  • Framework: FastAPI (async/await)
  • AI Models: Google Gemini (gemini-2.5-flash-lite), LangChain
  • Database: PostgreSQL with AsyncSQLAlchemy ORM
  • Vector Search: pgvector extension
  • Embeddings: Sentence Transformers (all-MiniLM-L6-v2, 384-dim)
  • Authentication: JWT + OAuth2 (Google)

Frontend

  • React Native mobile app
  • Modern web interface

πŸ— Architecture

RAG System Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Dream Journal AI - RAG Flow                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

User Query ──► Embedding Model ──► Vector Search ──► Context ──► LLM
                (all-MiniLM-L6)     (pgvector)      (dreams)     (Gemini)
                                                                   β”‚
                                                                   β–Ό
                                                              AI Response

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ User Dreams     β”‚      β”‚ PGVector         β”‚      β”‚ Google      β”‚
β”‚ (PostgreSQL)    │◄────►│                  │─────►│ Gemini API  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Database Schema

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    Users     β”‚         β”‚   DreamEntry    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€         β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ id (PK)      │────┐    β”‚ id (PK)         β”‚
β”‚ email        β”‚    β”‚    β”‚ user_id (FK)    │◄────┐
β”‚ username     β”‚    └───►│ title           β”‚     β”‚
β”‚ password     β”‚         β”‚ description     β”‚     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚ interpretation  β”‚     β”‚
                         β”‚ emotion_tags    β”‚     β”‚
                         β”‚ timestamp       β”‚     β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
                                  β”‚              β”‚
                                  β”‚              β”‚
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
                         β”‚  DreamVector    β”‚     β”‚
                         β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€     β”‚
                         β”‚ id (PK)         β”‚     β”‚
                         β”‚ dream_id (FK)   β”‚β”€β”€β”€β”€β”€β”˜
                         β”‚ user_id (FK)    β”‚
                         β”‚ embedding       │◄─── pgvector (384-dim)
                         β”‚ created_at      β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Structure

src/backend/
β”œβ”€β”€ api/
β”‚   β”œβ”€β”€ endpoints/
β”‚   β”‚   β”œβ”€β”€ dreams.py            # Dream CRUD operations
β”‚   β”‚   β”œβ”€β”€ dream_explorer.py    # Conversational search
β”‚   β”‚   └── users.py             # User management
β”‚   └── routes.py                # Router aggregation
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ dream_service.py         # Dream business logic
β”‚   β”œβ”€β”€ dream_explorer_service.py # Dream history exploration
β”‚   └── dream_retrieval_service.py # Vector search & embeddings
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ dreamentry.py            # Dream SQLAlchemy model
β”‚   β”œβ”€β”€ dream_vector.py          # Embedding storage model
β”‚   β”œβ”€β”€ user.py                  # User model
β”‚   └── schemas.py               # Pydantic validation schemas
β”œβ”€β”€ ai_interpreters/
β”‚   └── gemini_interpreter.py    # Google Gemini integration
└── utils/
    β”œβ”€β”€ auth.py                  # JWT authentication
    └── config.py                # Settings management

πŸš€ Quick Start

Prerequisites

  • Python 3.10+
  • PostgreSQL 12+ (with pgvector extension)
  • Google Gemini API Key

Installation

# Clone and setup
git clone https://github.com/Syamgith/ai-dream-journal.git
cd ai-dream-journal
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt

# Configure environment (.env file)
PostgreSQL_URL=postgresql+asyncpg://user:password@localhost:5432/dream_journal
GOOGLE_API_KEY=your_gemini_api_key
JWT_SECRET=your_jwt_secret
LLM_MODEL_NAME=gemini-2.5-flash-lite

# Initialize database
alembic upgrade head

# Run server
uvicorn main:app --host 0.0.0.0 --port 8000 --reload

Docker Deployment

docker-compose up --build

πŸ“‘ API Documentation

Interactive Docs:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

Core Endpoints

Dreams Management

  • POST /dreams/ - Create dream with AI interpretation
  • GET /dreams/ - List user's dreams
  • GET /dreams/{id} - Get specific dream
  • PUT /dreams/{id} - Update dream
  • DELETE /dreams/{id} - Delete dream

Dream Explorer πŸ”

  • POST /dream-explorer/ask - Chat with your dream history

    {
      "question": "What do my flying dreams mean?",
      "chat_history": [],
      "top_k": 5
    }
  • POST /dream-explorer/search - Semantic search across dreams

    {
      "query": "dreams about water and oceans",
      "top_k": 5,
      "emotion_tags": ["calm"]
    }
  • GET /dream-explorer/similar/{dream_id} - Find similar dreams

  • POST /dream-explorer/patterns - Discover recurring patterns

    {
      "pattern_query": "recurring nightmares",
      "top_k": 10
    }
  • POST /dream-explorer/compare - Compare two dreams

    {
      "dream_id_1": 123,
      "dream_id_2": 456
    }

Authentication

  • POST /token - Login (JWT)
  • POST /users/register - Register new user
  • POST /auth/google - Google OAuth

πŸ§ͺ Testing

# Run all tests
pytest

# Run specific test suites
pytest tests/test_dream_explorer_endpoints.py
pytest tests/test_dream_service.py

🎨 How It Works

  1. Dream Entry: User creates a dream β†’ AI generates interpretation using Gemini
  2. Embedding Creation: Dream description β†’ Sentence Transformer β†’ 384-dim vector β†’ Stored in pgvector
  3. Semantic Search: Query β†’ Embedded β†’ Similarity search in pgvector β†’ Ranked results
  4. Dream Explorer: Question β†’ Retrieves relevant dreams β†’ LangChain + Gemini β†’ Conversational response
  5. Fallback Search: Semantic β†’ Keyword matching β†’ Text pattern search (ensures results)

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

MIT License - see LICENSE for details

πŸ™ Acknowledgments

Built with: Google Gemini AI β€’ FastAPI β€’ LangChain β€’ pgvector β€’ Sentence Transformers


Made with ❀️ for dreamers everywhere

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors