How ansn07/book-gen works
File structure
• Top-level files:
• main.py (the orchestration script)
• requirements.txt (Python dependencies)
• README.md (project description & setup)
• generated-books/… (output directories & book.md)
• External integrations: GitHub API (via --repo URL or local path), Ollama HTTP inference server.
README for additional insights
• Key steps: clone/read repo → parse .py files → generate prompts → call local LLM → post-process LLM output → merge Markdown.
• Dependencies: Python 3, pip packages, Ollama server hosting Mistral (~4–6 GB).
Components & relationships
a. Main Components
1. CLI Interface (user runs python main.py --repo …)
2. Repo Fetcher
• GitHub client (HTTPS clone or local FS reader)
3. File Discovery & Parser
• Walks directory, finds .py, optionally builds AST
4. Prompt Generator
• Takes each .py file’s content → constructs a prompt template
5. LLM Inference Engine
• Ollama server (HTTP endpoint) hosting Mistral model
6. Post-Processor & Markdown Generator
7. Chapter Assembler
• Collates individual chapter files into a single book.md + TOC
8. File System I/O
• Writes to generated-books/<project>/book.md and /explained/ subfolder
9. External Services
• GitHub API (rate-limited; optionally authenticated via .env), Ollama local server
b. Relationships & data flows
• CLI → Repo Fetcher (HTTP clone or local FS)
• Repo Fetcher → File Discovery → Parser
• Parser → Prompt Generator → LLM Inference (HTTP request to Ollama)
• LLM Inference → Post-Processor → Markdown files
• Markdown files → Chapter Assembler → Final book.md
• All steps read/write to local file system; errors bubble back to CLI user
Architectural patterns & principles
• Pipelines & staged processing (each file goes through the same sequence)
• Modular separation of concerns (fetching, parsing, prompting, inference, formatting)
• Externalizing heavy computation to a service (Ollama)
• Idempotent file outputs for caching / re-runs