Document Analyzer Pro is a Streamlit-based web application that processes and analyzes documents (PDF, DOCX, TXT) using AI. The system extracts text from uploaded documents, generates comprehensive summaries, creates study questions, and produces interactive mind map visualizations using OpenAI's GPT models. The application includes admin authentication and stores document analysis results in a database for future reference.
Preferred communication style: Simple, everyday language.
Problem: Need an intuitive interface for document upload and analysis visualization
Solution: Streamlit framework with custom CSS for a polished user experience
Rationale: Streamlit provides rapid development of data-driven applications with minimal frontend code. Custom CSS styling creates a professional gradient-based design with white content containers.
Key Design Decisions:
- Wide layout mode for better utilization of screen space
- Sidebar for navigation and controls
- Custom purple gradient theme (#667eea to #764ba2)
- Responsive containers with rounded corners and shadow effects
Problem: Process multiple document formats and generate AI-powered analysis
Solution: Modular Python architecture with separate concerns for authentication, document processing, AI analysis, and visualization
Core Modules:
- auth.py - Admin authentication using bcrypt password hashing
- document_processor.py - Text extraction from PDF (PyPDF2), DOCX (python-docx), and TXT files
- ai_analyzer.py - OpenAI GPT-5 integration for summary, question, and mind map generation
- mindmap_visualizer.py - Plotly-based interactive mind map rendering
- app.py - Main Streamlit application orchestrating all components
Architectural Pattern: Service-oriented with clear separation between data access, business logic, and presentation layers
Problem: Persist documents, analysis results, and user authentication
Solution: SQLAlchemy ORM with configurable database backend via DATABASE_URL environment variable
Database Schema:
-
Admin Table:
- id (Primary Key)
- username (Unique, Indexed)
- password_hash (bcrypt)
- created_at (Timestamp)
-
Documents Table:
- id (Primary Key)
- filename
- file_type (pdf/docx/txt)
- content (Full extracted text)
- summary (AI-generated)
- questions (JSON array of study questions)
- mindmap_data (JSON structure for visualization)
- uploaded_by (Admin username)
- uploaded_at (Timestamp)
Design Decision: Store AI-generated content (summary, questions, mindmap_data) directly in the database to avoid regeneration costs and provide instant access to historical analyses.
Problem: Restrict document upload and management to authorized users
Solution: Password-based admin authentication with bcrypt hashing
Security Measures:
- Bcrypt password hashing with automatic salt generation
- Session-based authentication via Streamlit session state
- Admin creation validation to prevent duplicate usernames
Trade-offs: Single-tier admin system (no role-based access control) provides simplicity suitable for small teams. Can be extended to multi-role system if needed.
Problem: Generate intelligent document analysis including summaries, questions, and mind maps
Solution: OpenAI GPT-5 API integration with structured prompting
Implementation Details:
- Model: GPT-5 (as of August 7, 2025)
- API Key: Environment variable (OPENAI_API_KEY)
- Max tokens: 1000 for summaries, configurable for other operations
- Response format: JSON for structured data (questions, mind maps)
Functions:
generate_summary()- Comprehensive document summarizationgenerate_questions()- 10 study questions as JSON arraygenerate_mindmap_data()- Hierarchical structure with central topic and branches
Design Rationale: Direct API integration provides flexibility and access to latest model capabilities. Environment-based API key management ensures security.
Problem: Present mind map data in an interactive, user-friendly format
Solution: Plotly graph objects for dynamic, web-based visualizations
Visualization Features:
- Circular layout with central topic node
- Branch nodes positioned radially around center
- Subtopic nodes extending from branches
- Interactive hover information
- Color-coded nodes (central topic highlighted)
- Responsive sizing and positioning
Technical Approach: Mathematical positioning using polar coordinates (angle_step calculation) to evenly distribute branches in a circle.
- OpenAI API (GPT-5): Primary AI engine for text analysis, summarization, question generation, and mind map creation
- Authentication: API key via OPENAI_API_KEY environment variable
- Critical dependency for core functionality
- SQLAlchemy: ORM for database abstraction
- Connection: DATABASE_URL environment variable
- Supports multiple database backends (PostgreSQL, MySQL, SQLite, etc.)
- Database type not explicitly specified in code (runtime configuration)
- PyPDF2: PDF text extraction
- python-docx: Microsoft Word document processing
- io: In-memory file handling for uploaded documents
- bcrypt: Password hashing and verification
- Automatic salt generation
- Industry-standard security for credential storage
- Streamlit: Web application framework and UI components
- Plotly: Interactive graph visualizations for mind maps
- Uses graph_objects API for programmatic chart creation
- os: Environment variable access
- json: JSON parsing and serialization
- datetime: Timestamp management
- math: Geometric calculations for mind map positioning
Two critical environment variables must be set:
- OPENAI_API_KEY: OpenAI API authentication
- DATABASE_URL: Database connection string
The application will raise ValueError exceptions if these are not configured, preventing runtime failures.