Skip to content

kai-linux/public-bookgenerator

Repository files navigation

AI Book Generator - Complete Web Application

Overview

Web application for AI book generation service based on React/Next.js framework. The application includes:

  • Frontend: Professional React/Next.js interface with book configuration forms
  • Backend: Flask API with book generation endpoints and progress tracking
  • Features: Real-time progress updates, automatic DOCX file downloads, and error handling
  • Deployment: Ready to deploy to your preferred hosting platform

Architecture

Frontend (React/Next.js)

  • Built on existing Next.js structure
  • Professional UI with Tailwind CSS styling
  • Real-time progress tracking with polling
  • Automatic file download functionality
  • Responsive design for desktop and mobile

Backend (Flask)

  • RESTful API with CORS enabled
  • Background job processing with threading
  • In-memory status tracking (can be upgraded to Redis/database)
  • Custom DOCX generation without external dependencies
  • File storage and download endpoints

Features Implemented

1. Book Configuration Interface

  • Title: Required field for book title
  • Author: Optional author name
  • Genre: Fiction, Non-Fiction, Mystery, Romance, Sci-Fi, Fantasy
  • Chapters: 1-20 chapters (default: 5)

2. Generation Process

  • Real-time Progress: Updates every 2 seconds
  • Status Messages: Detailed progress information
  • Background Processing: Non-blocking generation
  • Error Handling: Comprehensive error states and user feedback

3. File Download

  • Automatic Download: Triggers when generation completes
  • DOCX Format: Professional Word document format
  • Custom Naming: Based on book title
  • File Persistence: Temporary storage for download

API Endpoints

POST /api/story-generator/generate

Start book generation process

{
  "title": "Book Title",
  "author": "Author Name",
  "genre": "fiction",
  "chapters": 5,
  "length": "medium"
}

GET /api/story-generator/status/{job_id}

Get generation status

{
  "status": "processing",
  "progress": 60,
  "message": "Writing introduction and conclusion...",
  "created_at": "2025-07-18T18:30:00"
}

GET /api/story-generator/download/{job_id}

Download generated book (returns DOCX file)

GET /api/story-generator/jobs

List all generation jobs

Local Development

  1. Backend Setup:

    cd bookgenerator-backend
    source venv/bin/activate
    export SECRET_KEY=replace-with-a-random-secret
    python src/main.py
  2. Frontend Setup:

    cd bookgenerator
    npm install
    npm run dev

Technical Implementation Details

Custom DOCX Generation

  • Implemented custom DOCX creation using ZIP and XML
  • No external dependencies (removed python-docx due to deployment issues)
  • Proper Word document structure with formatting
  • Supports titles, authors, chapters, and paragraphs

Progress Tracking

  • Background threading for non-blocking generation
  • In-memory status storage with job IDs
  • Real-time updates via polling
  • Automatic cleanup and file management

Error Handling

  • Comprehensive try-catch blocks
  • User-friendly error messages
  • Graceful degradation
  • Status recovery mechanisms

File Structure

bookgenerator-backend/
├── src/
│   ├── main.py              # Flask application entry point
│   ├── routes/
│   │   ├── story_generator.py # Story generation endpoints
│   │   └── user.py          # User management (template)
│   ├── models/
│   │   └── user.py          # Database models (template)
│   └── static/
│       └── index.html       # Frontend application
├── requirements.txt         # Python dependencies
└── venv/                   # Virtual environment

bookgenerator/              # Original Next.js frontend
├── app/
│   ├── page.js             # Enhanced main page component
│   ├── layout.js           # Application layout
│   └── api/
│       └── auth/
│           └── route.js    # API route (template)
├── next.config.mjs         # Next.js configuration with proxy
└── package.json           # Node.js dependencies

Usage Instructions

For End Users

  1. Visit homepage
  2. Fill in book configuration:
    • Enter a book title (required)
    • Add author name (optional)
    • Select genre and preferences
  3. Click "Generate Book"
  4. Monitor real-time progress
  5. Book will automatically download when complete

For Developers

  1. Clone the repository
  2. Set up backend environment
  3. Install dependencies
  4. Run local development servers
  5. Customize book generation logic as needed

Future Enhancements

Recommended Improvements

  1. AI Integration: Replace mock generation with actual AI service
  2. Database: Implement persistent storage for jobs and files
  3. Authentication: Add user accounts and book history
  4. Templates: Multiple book templates and styles
  5. Export Options: PDF, EPUB, and other formats
  6. Advanced Configuration: More detailed customization options

Scalability Considerations

  1. Redis: For distributed job tracking
  2. File Storage: Cloud storage for generated files
  3. Queue System: Celery or similar for background jobs
  4. Load Balancing: Multiple backend instances
  5. CDN: Static asset delivery optimization

Conclusion

  • ✅ User can configure book settings
  • ✅ Request generation from backend
  • ✅ Wait with real-time progress tracking
  • ✅ Receive book as automatic DOCX download
  • ✅ Professional, responsive interface
  • ✅ Deployed and publicly accessible

About

Full-stack AI book generation web app with a Next.js frontend, Flask API, progress tracking, and DOCX export.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors