Skip to content

Repository files navigation

Vahini Education Book Builder

A comprehensive Flask web application for creating, customizing, and ordering high-quality educational books for children ages 3-10.

Overview

Vahini Education Book Builder empowers parents, teachers, and schools to:

  • Create custom educational books with AI-generated illustrations
  • Choose from multiple book types (pre-writing, coloring, subject learning, practice)
  • Customize content for different age groups and learning objectives
  • Get transparent pricing with instant cost calculation
  • Order print-ready books delivered to your door
  • Track orders and manage fulfillment

Features

For Users

  • 5-Step Book Builder: Intuitive wizard for creating custom books

    • Step 1: Choose book type, age group, difficulty
    • Step 2: Set title, topic, number of pages
    • Step 3: Customize language, size, purpose
    • Step 4: Review details and adjust quantity
    • Step 5: Save draft or proceed to checkout
  • Dynamic Pricing: Real-time cost calculation including:

    • Per-page printing costs
    • Shipping to 50+ countries
    • Tax calculations
    • Bulk discounts
  • Book Preview: See page-by-page layout before ordering

  • Order Management: Track order status from processing to delivery

For Administrators

  • Print Job Dashboard: Manage fulfillment pipeline
  • Order Management: View, update, and fulfill orders
  • Analytics: Order statistics and revenue reports
  • Courier Integration: Track shipments and delivery status

Architecture

Project Structure

vahini-book-builder/
├── app/
│   ├── __init__.py                 # Application factory
│   ├── models/
│   │   └── __init__.py             # SQLAlchemy models
│   │       ├── User                # User accounts
│   │       ├── BookOrder           # Orders
│   │       ├── Page                # Book pages
│   │       └── PrintJob            # Print jobs
│   ├── routes/
│   │   ├── book_builder.py         # 5-step form & APIs
│   │   ├── preview.py              # Book preview
│   │   ├── order.py                # Checkout & tracking
│   │   └── admin.py                # Admin dashboard
│   ├── services/
│   │   ├── prompt_builder.py       # Prompt generation
│   │   ├── image_service.py        # DALL-E 3 integration
│   │   ├── pdf_service.py          # PDF compilation
│   │   └── pricing_service.py      # Cost calculation
│   ├── templates/
│   │   ├── base.html               # Base layout
│   │   ├── index.html              # Landing page
│   │   ├── book_builder/           # Builder forms
│   │   ├── order/                  # Order forms
│   │   ├── preview/                # Preview pages
│   │   ├── admin/                  # Admin pages
│   │   └── errors/                 # Error pages
│   └── static/
│       ├── css/
│       │   └── style.css           # Main styles
│       └── js/
│           └── main.js             # Frontend JS
├── config.py                        # Configuration
├── wsgi.py                         # Gunicorn entry point
├── requirements.txt                # Dependencies
└── README.md                       # This file

Technology Stack

Backend:

  • Flask 2.3.3 - Web framework
  • Flask-SQLAlchemy 3.0.5 - ORM
  • SQLAlchemy 2.0.21 - Database abstraction
  • Gunicorn 21.2.0 - Production server
  • Python-dotenv 1.0.0 - Environment configuration

Database:

  • SQLite (development)
  • PostgreSQL (production-ready)

Frontend:

  • Bootstrap 5.3 - UI framework
  • Vanilla JavaScript - No dependencies

Services:

  • OpenAI DALL-E 3 - Image generation
  • ReportLab 4.0.7 - PDF generation
  • Pillow 10.0.0 - Image processing
  • Requests 2.31.0 - HTTP client

Installation

Prerequisites

  • Python 3.9+
  • pip or conda
  • OpenAI API key (for DALL-E 3, optional)

Setup

  1. Clone Repository

    git clone https://github.com/vahinitech/vahini-book-builder.git
    cd vahini-book-builder
  2. Create Virtual Environment

    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install Dependencies

    pip install -r requirements.txt
  4. Configure Environment

    cp .env.example .env
    # Edit .env with your settings:
    # - FLASK_ENV=development
    # - SECRET_KEY=your-secret-key
    # - DATABASE_URL=sqlite:///vahini_books.db
    # - OPENAI_API_KEY=your-openai-key (optional)
  5. Initialize Database

    flask db upgrade
    # Or manually with:
    # python -c "from app import create_app, db; app = create_app(); app.app_context().push(); db.create_all()"
  6. Run Development Server

    python wsgi.py
    # Or:
    flask run

    Server runs at: http://localhost:5000

Usage

Create a Book

  1. Go to Book Builder at /builder/
  2. Follow the 5-step wizard:
    • Select book type and target age
    • Set title, topic, page count
    • Customize language, size, purpose
    • Review details and pricing
    • Save draft or checkout
  3. Proceed to checkout for order placement
  4. Track order status from dashboard

Admin Dashboard

  1. Navigate to /admin/dashboard
  2. View order statistics and recent orders
  3. Manage print jobs at /admin/print-jobs
  4. Edit orders and update fulfillment status

API Endpoints

Book Builder

  • GET /builder/ - Landing page
  • POST /builder/step1-5 - Form submissions
  • GET /builder/api/book-types - Book types
  • GET /builder/api/topics - Available topics
  • POST /builder/api/pricing - Calculate pricing

Order Management

  • GET /order/checkout/<id> - Checkout page
  • POST /order/checkout/<id> - Submit order
  • GET /order/confirmation/<id> - Order confirmation
  • GET /order/tracking/<id> - Order tracking

Preview

  • GET /preview/book/<id> - View book
  • GET /preview/gallery - Sample gallery
  • GET /preview/api/pages/<id> - Get page list

Admin

  • GET /admin/dashboard - Dashboard
  • GET /admin/orders - Order list
  • GET /admin/print-jobs - Print jobs
  • POST /admin/api/print-job/<id> - Update print job

Database Models

User

id, email, name, user_type, phone, organization, created_at, updated_at

BookOrder

id, user_id, title, book_type, topic, num_pages, age_group, difficulty_level,
language, book_size, purpose, config_json, status, prompt_file, pdf_file,
page_cost, shipping_cost, total_cost, quantity, delivery_address, phone_number,
created_at, updated_at

Page

id, book_order_id, page_number, title, content_prompt, image_prompt,
image_url, image_file, status, created_at, updated_at

PrintJob

id, book_order_id, job_number, status, courier_name, tracking_number,
created_at, shipped_at, delivered_at, updated_at

Configuration

Environment Variables

# Flask
FLASK_ENV=development                          # development, production, testing
SECRET_KEY=your-super-secret-key              # For session security
DEBUG=False                                    # Debug mode

# Database
DATABASE_URL=sqlite:///vahini_books.db        # SQLite or PostgreSQL

# OpenAI
OPENAI_API_KEY=sk-...                         # For DALL-E 3

# Pricing (optional, uses defaults from config)
PRICE_PER_PAGE=0.50
SHIPPING_BASE=5.00

Configuration Classes

Edit config.py to customize:

  • Database settings
  • Upload folders
  • Image generation options (model, size, quality)
  • PDF specifications (DPI, margins)
  • Pricing (per-page, shipping by region)

Development

Database Migrations

# Create migration
flask db migrate -m "description"

# Apply migration
flask db upgrade

# Revert migration
flask db downgrade

Testing

# Run tests
pytest

# With coverage
pytest --cov=app

Code Quality

# Format code
black app/

# Lint
flake8 app/

# Type checking
mypy app/

Deployment

Production with Gunicorn

# Install production dependencies
pip install gunicorn

# Run with Gunicorn
gunicorn -w 4 -b 0.0.0.0:8000 wsgi:app

# Or with systemd service:
# [Unit]
# Description=Vahini Book Builder
# After=network.target
#
# [Service]
# User=www-data
# WorkingDirectory=/var/www/vahini-book-builder
# Environment="PATH=/var/www/vahini-book-builder/venv/bin"
# ExecStart=/var/www/vahini-book-builder/venv/bin/gunicorn --workers 4 wsgi:app
#
# [Install]
# WantedBy=multi-user.target

Environment Setup (Production)

# Use PostgreSQL
DATABASE_URL=postgresql://user:password@localhost/vahini_books

# Enable SSL/TLS
FLASK_ENV=production
DEBUG=False
PREFERRED_URL_SCHEME=https

Docker

FROM python:3.11-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . .

ENV FLASK_ENV=production
EXPOSE 5000

CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "wsgi:app"]

TODO & Future Features

High Priority

  • User authentication (Flask-Login)
  • Payment integration (Stripe/Razorpay)
  • Email notifications (order confirmations, tracking)
  • Courier API integration (Shiprocket/DHL)
  • Image generation queue (background tasks with Celery)

Medium Priority

  • User dashboard (order history, favorites)
  • Book customization (upload images, custom text)
  • Bulk ordering discounts
  • Subscription plans
  • Multi-language support (i18n)

Nice to Have

  • Mobile app (iOS/Android)
  • Social sharing (Pinterest, Instagram)
  • Affiliate program
  • Educational partnerships
  • Accessibility (WCAG 2.1)

Performance Optimization

Caching

from flask_caching import Cache

cache = Cache(app, config={'CACHE_TYPE': 'simple'})

@app.route('/api/book-types')
@cache.cached(timeout=3600)
def get_book_types():
    ...

Database Indexing

  • User.email (unique)
  • BookOrder.user_id, status, created_at
  • Page.book_order_id, page_number
  • PrintJob.status, courier_name

CDN Integration

<!-- Use CDN for Bootstrap/jQuery -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

Security

CSRF Protection

from flask_wtf.csrf import CSRFProtect
csrf = CSRFProtect(app)

Input Validation

  • All user inputs validated server-side
  • SQL injection prevention via SQLAlchemy ORM
  • XSS prevention via Jinja2 auto-escaping

Rate Limiting

from flask_limiter import Limiter
limiter = Limiter(app)

@app.route('/api/pricing', methods=['POST'])
@limiter.limit("10/minute")
def get_pricing():
    ...

Troubleshooting

Database Lock

# Remove SQLite database and reinitialize
rm vahini_books.db
python -c "from app import create_app, db; app = create_app(); db.create_all()"

Import Errors

# Ensure app/ has __init__.py files
touch app/routes/__init__.py
touch app/services/__init__.py
touch app/models/__init__.py

OpenAI API Errors

Support

Email: support@vahinitech.com
Website: https://vahinitech.com
LinkedIn: https://linkedin.com/company/vahini-technologies

License

Vahini Technologies 2026 License - See LICENSE.md

Contributing

Contributions welcome! Please:

  1. Fork repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

Changelog

v1.0.0 (Current)

  • Initial release
  • 5-step book builder
  • Order management system
  • Admin dashboard
  • Dynamic pricing calculator
  • Database models for users, orders, pages, print jobs

Company

Vahini Technologies
Startup India: DIPP201621
Patents: #202541020023, #202541020024

"Creating educational excellence through technology"

Releases

Packages

Used by

Contributors

Languages