# Amharic Book Generator
A full-stack AI-powered application that generates complete, multi-chapter books in Amharic based on a title and description. It features precise length control, strict language adherence, and DOCX export.
## Features
- **Language Strictness**: Guaranteed 100% Amharic output. Automatically detects and translates/removes English accidentally generated by the AI.
- **Length Control**: Specify target page counts (10-300 pages). The AI plans chapters and word budgets to meet this target.
- **Streaming Generation**: Real-time progress updates as the AI writes the outline, chapters, and polishes the text.
- **History**: Autosaves every generated book. View, read, or delete past projects.
- **Export**: Download any book as a formatted `.docx` file.
## Tech Stack
- **Framework**: Next.js 14 (App Router)
- **Language**: TypeScript
- **AI Model**: Google Gemini Pro (via `@google/generative-ai`)
- **Styling**: Vanilla CSS (Premium Dark Theme)
- **Persistence**: Local JSON file (`data/history.json`) - Easy to deploy, no database setup required.
- **Document Generation**: `docx` library
## Setup & Run
1. **Install Dependencies**
```bash
npm install
```
2. **Environment Setup**
Create a `.env.local` file in the root directory and add your Google Gemini API Key:
```bash
GOOGLE_API_KEY=AIzSy...
```
*Get a key at aistudio.google.com*
3. **Run Development Server**
```bash
npm run dev
```
Open
localhost
4. **Build for Production**
```bash
npm run build
npm start
```
## Page Targeting Logic
The app uses a deterministic word-count strategy to approximate page length:
1. **Definition**: 1 Page ≈ 300 Amharic words.
2. **Budgeting**:
- Total Target Words = `Page Count` * 300.
- Outline Stage: The AI creates a chapter plan.
- Budget Per Chapter: `(Total Words * 0.9) / Chapter Count`. (10% reserved for Intro/Conclusion).
3. **Execution**: During generation, the prompting engine explicitly requests the specific word count for each chapter.
4. * …