Transform any topic into a fully researched, professionally formatted academic assignment in minutes β powered by Groq LLM, Google Imagen 3, and Tavily web search.
- What is this?
- How it works
- Key Benefits
- Full Tech Stack
- Project Structure
- Quick Start
- Environment Variables
- API Reference
- Generation Pipeline
- Document Templates
- Security
- Local vs Production
AI Assignment Generator is a full-stack web application that automates the creation of academic assignments from scratch. You simply enter a topic, choose your settings, and the system does everything else:
- π Researches the topic using live web search
- π§ Generates a structured outline using AI
- βοΈ Writes full academic content with proper citations
- πΌοΈ Creates relevant images for each section
- π Exports a professionally formatted DOCX and PDF with a cover page
No more spending hours writing assignments. The AI handles research, writing, formatting, and document generation β all in one click.
The entire orchestration pipeline runs asynchronously using a non-blocking background thread (or an optional production-ready Celery task queue). The Next.js frontend initiates the request, receives an instant confirmation, and then polls the status periodically to display a dynamic, real-time progress bar.
graph TD
%% Define Styles
classDef client fill:#3b82f6,stroke:#1d4ed8,stroke-width:2px,color:#fff;
classDef server fill:#10b981,stroke:#047857,stroke-width:2px,color:#fff;
classDef db fill:#f59e0b,stroke:#d97706,stroke-width:2px,color:#fff;
classDef pipeline fill:#8b5cf6,stroke:#6d28d9,stroke-width:2px,color:#fff;
User([π Student User]) -->|1. Enters Topic & Settings| FE[Next.js App Router Frontend]
FE -->|2. POST /api/v1/assignments/generate| BE[Flask RESTful API Backend]
subgraph Backend Core
BE -->|3. Starts Background Thread / Queue| Pipeline[Pipeline Service Orchestrator]
BE -->|4. Instantly Returns 202 Accepted| FE
subgraph 7-Step AI Orchestration Pipeline
Pipeline -->|Step 1: Sanitize| Guard[Prompt Guard / HTML Bleach]
Guard -->|Step 2: Tavily Search| Web[Tavily Search: Live Web Research]
Web -->|Step 3: Groq LLM| Outline[Groq: Outline Generation JSON]
Outline -->|Step 4: Groq LLM| Content[Groq: Content & Citations Writer]
Content -->|Step 5: Imagen 3 / Gemini| Images[Google Imagen 3: Section Illustration]
Images -->|Step 6: python-docx| Word[Word Document Builder]
Word -->|Step 7: ReportLab| PDF[PDF Document Builder]
end
Word -->|Save generated doc paths| DB[(SQLite / PostgreSQL Database)]
PDF -->|Save generated doc paths| DB
end
FE -->|5. GET /api/v1/assignments/:id polling| BE
BE -->|Query Status & Progress| DB
DB -->|Progress 0% - 100%| FE
FE -->|6. Ready for Download| Download[β¬οΈ Download DOCX / PDF with Custom Templates]
%% Assign classes
class FE client;
class BE server;
class DB db;
class Pipeline,Guard,Web,Outline,Content,Images,Word,PDF pipeline;
Note
The background orchestration is designed to run asynchronously using Flask's multi-threading capabilities, meaning no extra dependencies like Redis or Celery are required for local development. For production, Celery is fully supported and configured.
| Benefit | Description |
|---|---|
| β‘ Fast | Full assignment generated in 2β5 minutes |
| π¨ 5 Templates | Professional, Academic, Modern, Minimal, Colorful |
| π 4 Citation Styles | APA, MLA, Harvard, IEEE |
| πΌοΈ AI Images | Auto-generated images per section via Imagen 3 |
| βοΈ Editable | Edit any section inline after generation |
| π₯ Dual Export | Download as DOCX or PDF |
| π Secure | JWT auth, bcrypt passwords, prompt injection guard |
| π» Local-first | Runs fully on SQLite β no Docker, no PostgreSQL needed |
| Technology | Version | Purpose |
|---|---|---|
| Python | 3.11+ | Runtime language |
| Flask | 3.1.0 | Web framework |
| SQLAlchemy | 2.0.36 | ORM for database |
| Flask-SQLAlchemy | 3.1.1 | Flask + SQLAlchemy bridge |
| Flask-JWT-Extended | 4.7.1 | JWT access + refresh tokens |
| Flask-Limiter | 3.8.0 | Rate limiting |
| Flask-CORS | 5.0.1 | Cross-origin requests |
| Flask-Migrate | 4.1.0 | Database migrations |
| Marshmallow | 3.23.2 | Input validation & serialization |
| Pydantic | 2.10.4 | Settings management via .env |
| Groq | 0.13.1 | LLM β llama-3.3-70b-versatile |
| google-generativeai | 0.8.4 | Imagen 3 image generation |
| tavily-python | 0.5.0 | Live web research API |
| python-docx | 1.1.2 | DOCX document generation |
| ReportLab | 4.2.5 | PDF document generation |
| Pillow | 11.1.0 | Image processing |
| bcrypt | 4.2.1 | Password hashing (rounds=12) |
| bleach | 6.2.0 | HTML sanitization |
| tenacity | 9.0.0 | Retry logic for API calls |
| python-dotenv | 1.0.1 | Load .env variables |
| SQLite | built-in | Local database (zero setup) |
| Celery + Redis | 5.4.0 | Optional β production task queue |
| Technology | Version | Purpose |
|---|---|---|
| Next.js | 15.1.0 | React framework with App Router |
| React | 19.0.0 | UI library |
| Tailwind CSS | 3.4.17 | Utility-first CSS framework |
| Framer Motion | 11.15.0 | Animations and transitions |
| Axios | 1.7.9 | HTTP client with JWT interceptors |
| js-cookie | 3.0.5 | Cookie management for tokens |
| lucide-react | 0.468.0 | Icon library |
| react-hot-toast | 2.4.1 | Toast notifications |
| @tailwindcss/typography | 0.5.15 | Prose styling for content |
| Service | Model | Purpose |
|---|---|---|
| Groq | llama-3.3-70b-versatile |
Outline + full content generation |
| Google Imagen 3 | imagen-3.0-generate-002 |
Section image generation |
| Google Gemini Flash | gemini-2.0-flash-exp |
Image fallback |
| Tavily | Search API | Live web research (5 sources) |
ai-assignment-generator/
β
βββ Backend/ # Flask REST API
β βββ app/
β β βββ api/
β β β βββ assignment_api.py # Generate, list, download, edit, regenerate
β β β βββ auth_api.py # Register, login, refresh, me
β β β βββ health_api.py # Health check endpoint
β β β βββ routes.py # Blueprint registration
β β β βββ user_api.py # User profile
β β β
β β βββ models/
β β β βββ assignment.py # Assignment model (topic, template, student info)
β β β βββ user.py # User model with bcrypt
β β β βββ section.py # Section model (title, content, order)
β β β βββ image.py # Image model (path, caption)
β β β βββ reference.py # Reference model (citation text)
β β β
β β βββ schemas/
β β β βββ assignment_schema.py # Marshmallow validation schemas
β β β βββ user_schema.py # User register/login schemas
β β β
β β βββ services/
β β β βββ pipeline_service.py # 7-step pipeline orchestrator
β β β βββ research_service.py # Tavily web research
β β β βββ outline_service.py # Groq outline generation
β β β βββ text_generation_service.py # Groq content generation
β β β βββ image_generation_service.py # Imagen 3 + Gemini fallback
β β β βββ document_service.py # DOCX + PDF with 5 templates
β β β
β β βββ utils/
β β β βββ logger.py # Structured logging
β β β βββ prompt_guard.py # Prompt injection detection
β β β βββ validators.py # Input sanitization
β β β βββ file_helpers.py # File path utilities
β β β
β β βββ errors/
β β β βββ handlers.py # Global error handlers (422, 500, etc.)
β β β
β β βββ extensions.py # Flask extensions init
β β βββ factory.py # App factory + auto table creation
β β
β βββ config/
β β βββ settings.py # Pydantic settings (SQLite path fix)
β β
β βββ instance/
β β βββ app.db # SQLite database (auto-created)
β β
β βββ storage/
β β βββ documents/ # Generated .docx and .pdf files
β β βββ images/ # Generated .png images
β β
β βββ tests/ # Pytest test suite
β βββ .env.example # Environment template
β βββ requirements.txt # Python dependencies
β
βββ Frontend/ # Next.js App
β βββ src/
β β βββ app/
β β β βββ page.js # Landing page
β β β βββ login/page.js # Login
β β β βββ register/page.js # Register
β β β βββ generate/page.js # Assignment generator form
β β β βββ dashboard/
β β β βββ page.js # Assignment history list
β β β βββ [id]/page.js # Assignment detail + viewer
β β β
β β βββ components/
β β β βββ GenerateForm.js # 4-step wizard form
β β β βββ AssignmentViewer.js # Detail view + inline editing
β β β βββ AssignmentCard.js # Dashboard card
β β β βββ Navbar.js # Glassmorphism navbar
β β β βββ HeroSection.js # Landing hero
β β β βββ FeaturesSection.js # Features grid
β β β βββ HowItWorks.js # Steps section
β β β βββ StatusBadge.js # Colored status pill
β β β
β β βββ hooks/
β β β βββ useAuth.js # Auth state management
β β β βββ useAssignments.js # Assignment fetch + generate
β β β
β β βββ lib/
β β βββ api.js # Axios + JWT interceptor + auto-refresh
β β βββ auth.js # Login/register/logout helpers
β β βββ constants.js # Templates, levels, citation styles
β β
β βββ next.config.js # Proxy /api/* β localhost:5000
β βββ package.json
β
βββ .gitignore # Root gitignore
βββ README.md # This file
βββ LICENSE # MIT License
- Python 3.11+
- Node.js 18+
- API keys for: Groq, Google Gemini, Tavily
git clone https://github.com/muzammaldeveloper/ai-assignment-generator.git
cd ai-assignment-generatorcd Backend
# Create virtual environment
python -m venv .venv
# Activate β Windows PowerShell
.\.venv\Scripts\Activate.ps1
# Activate β Linux / macOS
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Create .env from template
copy .env.example .env # Windows
cp .env.example .env # Linux/macOSEdit .env and fill in your API keys (see Environment Variables).
# Run backend
flask run --host=0.0.0.0 --port=5000 --debugβ Database (
instance/app.db) is created automatically on first run. No migrations needed.
cd Frontend
npm install
npm run dev| Service | URL |
|---|---|
| π Frontend | http://localhost:3000 |
| βοΈ Backend API | http://localhost:5000 |
| π Health Check | http://localhost:5000/api/v1/health |
Create Backend/.env from Backend/.env.example:
# ββ Flask ββ
FLASK_APP=app.factory:create_app
FLASK_ENV=development
SECRET_KEY=your-secret-key-minimum-32-chars
DEBUG=true
# ββ JWT ββ
JWT_SECRET_KEY=your-jwt-secret-minimum-32-chars
JWT_ACCESS_TOKEN_EXPIRES_MINUTES=60
JWT_REFRESH_TOKEN_EXPIRES_DAYS=30
# ββ Database (SQLite β no PostgreSQL needed locally) ββ
DATABASE_URL=sqlite:///instance/app.db
# ββ Redis (not needed locally) ββ
REDIS_URL=redis://localhost:6379/0
# ββ Groq (text generation) ββ
GROQ_API_KEY=your-groq-api-key
GROQ_MODEL=llama-3.3-70b-versatile
GROQ_MAX_TOKENS=4096
GROQ_TEMPERATURE=0.7
# ββ Google Gemini (image generation) ββ
GEMINI_API_KEY=your-gemini-api-key
GEMINI_MODEL=gemini-2.0-flash-exp
# ββ Tavily (web research) ββ
TAVILY_API_KEY=your-tavily-api-key
TAVILY_MAX_RESULTS=5
# ββ Rate Limiting (memory:// = no Redis needed locally) ββ
RATE_LIMIT_DEFAULT=100/hour
RATE_LIMIT_GENERATION=10/hour
RATE_LIMIT_STORAGE_URI=memory://
# ββ CORS ββ
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
# ββ Storage ββ
STORAGE_BACKEND=local
STORAGE_LOCAL_PATH=storage
MAX_CONTENT_LENGTH_MB=10| Service | Free Tier | Get Key |
|---|---|---|
| Groq | β Fast LLM inference | https://console.groq.com |
| Google Gemini | β Imagen 3 included | https://aistudio.google.com |
| Tavily | β 1000 searches/month | https://tavily.com |
Base URL: http://localhost:5000/api/v1
| Method | Endpoint | Auth | Description |
|---|---|---|---|
POST |
/auth/register |
β | Register new user |
POST |
/auth/login |
β | Login, get tokens |
POST |
/auth/refresh |
Refresh token | Rotate access token |
GET |
/auth/me |
β | Get current user |
Register / Login body:
{
"name": "Ali Hassan",
"email": "ali@example.com",
"password": "SecurePass123"
}Response:
{
"success": true,
"data": {
"user": { "id": "uuid", "name": "Ali Hassan", "email": "ali@example.com" },
"access_token": "eyJ...",
"refresh_token": "eyJ..."
}
}| Method | Endpoint | Auth | Description |
|---|---|---|---|
POST |
/assignments/generate |
β | Start generation |
GET |
/assignments |
β | List all (paginated) |
GET |
/assignments/{id} |
β | Get full details + poll status |
GET |
/assignments/{id}/download?format=pdf |
β | Download DOCX or PDF |
PATCH |
/assignments/{id}/update-info |
β | Update student name, roll, department |
PATCH |
/assignments/{id}/sections/{sid} |
β | Edit section content |
POST |
/assignments/{id}/regenerate-docs |
β | Rebuild DOCX + PDF after edits |
Generate request body:
{
"topic": "Artificial Intelligence in Healthcare",
"academic_level": "university",
"word_count": 1500,
"citation_style": "apa",
"template": "professional",
"student_name": "Ali Hassan",
"roll_number": "CS-2021-001",
"department": "Department of Computer Science"
}Valid field values:
| Field | Options |
|---|---|
academic_level |
school college university research |
word_count |
800 1000 1200 1500 2000 3000 5000 |
citation_style |
apa mla harvard ieee |
template |
professional academic modern minimal colorful |
Generate response (202 Accepted):
{
"success": true,
"data": {
"assignment_id": "uuid",
"status": "pending",
"status_url": "/api/v1/assignments/uuid"
}
}Poll for completion:
curl http://localhost:5000/api/v1/assignments/{id} \
-H "Authorization: Bearer <access_token>"| Method | Endpoint | Auth | Description |
|---|---|---|---|
GET |
/health |
β | Health check |
Step 1 β Input Validation
βββ Prompt injection guard
βββ Topic sanitization with bleach
Step 2 β Web Research [10%]
βββ Tavily fetches 5 live sources
βββ Extracts relevant academic content
Step 3 β Outline Generation [25%]
βββ Groq LLM creates JSON outline
βββ Title, abstract, 5-8 sections, image hints
Step 4 β Content Generation [40%]
βββ Groq writes Introduction
βββ Groq writes each body section
βββ Groq writes Conclusion
βββ Groq formats References (APA/MLA/Harvard/IEEE)
Step 5 β Image Generation [60%]
βββ Google Imagen 3 β one image per section
βββ Fallback: Gemini 2.0 Flash
βββ Graceful β assignment continues without images
Step 6 β DOCX Generation [80%]
βββ python-docx builds Word document
βββ Cover page + sections + images + references
Step 7 β PDF Generation [100%]
βββ ReportLab builds PDF
βββ Cover page + colored headings + images + page numbers
| Template | Primary Color | Font | Style |
|---|---|---|---|
| Professional | Navy #003366 |
Calibri | Clean corporate |
| Academic | Dark Slate #2C3E50 + Dark Red |
Times New Roman | Traditional scholarly |
| Modern | Violet #6C63FF + Pink |
Calibri | Bold contemporary |
| Minimal | Near-black #1A1A1A |
Arial | Ultra clean |
| Colorful | Purple #7B2D8B + Magenta |
Calibri | Vibrant eye-catching |
βββββββββββββββββββββββββββββββββββββββ
β ββββββββββββββββββββββββββββββββ β β Colored header bar
β β
β ASSIGNMENT SUBMISSION β
β β
β Artificial Intelligence in β
β Healthcare β β Assignment title
β β
β βββββββββββββββββββββββββββββββββ β β Divider
β β
β Student Name: Ali Hassan β
β Roll Number: CS-2021-001 β β Student info (editable)
β Department: Computer Science β
β Date: January 01, 2025 β
β β
β ββββββββββββββββββββββββββββββββ β β Colored footer bar
βββββββββββββββββββββββββββββββββββββββ
- Section headings with colored underline dividers
- Images with captions (never split across pages β
KeepTogether) - Footer on every page: title left + page number right
- Hanging-indent formatted references
| Feature | Implementation |
|---|---|
| Prompt Injection Guard | Blocks LLM hijacking via topic input |
| Input Sanitization | All user content cleaned with bleach |
| Password Hashing | bcrypt with rounds=12 |
| JWT Tokens | 60min access + 30day refresh tokens |
| Rate Limiting | 100 req/hour default, 20/hour for generation |
| CORS | Restricted to configured origins only |
| No Secrets in Code | All config via .env |
Production: Set
DEBUG=false, use Redis for rate limiting, PostgreSQL for database, AWS S3 for file storage, and strong random keys forSECRET_KEYandJWT_SECRET_KEY.
| Feature | Local | Production |
|---|---|---|
| Database | SQLite (auto-created) | PostgreSQL |
| Task Queue | Background thread | Celery + Redis |
| Rate Limiting | In-memory | Redis |
| File Storage | storage/ folder |
AWS S3 |
| Debug | DEBUG=true |
DEBUG=false |
| Workers | Single thread | Gunicorn multi-worker |
- PythonAnywhere (Free Plan): Detailed step-by-step instructions are available in DEPLOY_PYTHONANYWHERE.md.
- Vercel: Configuration is provided in vercel.json using the
@vercel/pythonbuilder, withindex.pyas the entry point.
- Vercel: Fully optimized for Next.js out-of-the-box. Ensure your environment variables are configured in Vercel settings (see
Frontend/.env.example).
# Backend tests
cd Backend
pytest tests/ -v --cov=app --cov-report=term-missing
# Frontend lint
cd Frontend
npm run lintMIT β see LICENSE for details.
Built with β€οΈ using Flask Β· Next.js Β· Groq Β· Google Imagen 3 Β· Tavily