PocketFlow-Tutorial-Codebase-Knowledge README

The project's README from github.com/The-Pocket/PocketFlow-Tutorial-Codebase-Knowledge. As one markdown file: README.md.

Turns Codebase into Easy Tutorial with AI

License: MIT

Ever stared at a new codebase written by others feeling completely lost? This tutorial shows you how to build an AI agent that analyzes GitHub repositories and creates beginner-friendly tutorials explaining exactly how the code works.

This is a tutorial project of Pocket Flow, a 100-line LLM framework. It crawls GitHub repositories and builds a knowledge base from the code. It analyzes entire codebases to identify core abstractions and how they interact, and transforms complex code into beginner-friendly tutorials with clear visualizations.

  🔸 🎉 Reached Hacker News Front Page (April 2025) with >900 up‑votes: Discussion »

🤯 All these tutorials are generated entirely by AI by crawling the GitHub repo!

🚀 Getting Started

  1. Clone this repository

    git clone https://github.com/The-Pocket/PocketFlow-Tutorial-Codebase-Knowledge
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Set up LLM in utils/call_llm.py by providing credentials. To do so, you can put the values in a .env file. By default, you can use the AI Studio key with this client for Gemini Pro 2.5 by setting the GEMINI_API_KEY environment variable. If you want to use another LLM, you can set the LLM_PROVIDER environment variable (e.g. XAI), and then set the model, url, and API key (e.g. XAI_MODEL, XAI_URL,XAI_API_KEY). If using Ollama, the url is http://localhost:11434/ and the API key can be omitted. You can use your own models. We highly recommend the latest models with thinking capabilities (Claude 3.7 with thinking, O1). You can verify that it is correctly set up by running:

    python utils/call_llm.py
    
  4. Generate a complete codebase tutorial by running the main script:

    # Analyze a GitHub repository
    python main.py --repo https://github.com/username/repo --include "*.py" "*.js" --exclude "tests/*" --max-size 50000
    
    # Or, analyze a local directory
    python main.py --dir /path/to/your/codebase --include "*.py" --exclude "*test*"
    
    # Or, generate a tutorial in Chinese
    python main.py --repo https://github.com/username/repo --language "Chinese"
    
    • --repo or --dir - Specify either a GitHub repo URL or a local directory path (required, mutually exclusive)
    • -n, --name - Project name (optional, derived from URL/directory if omitted)
    • -t, --token - GitHub token (or set GITHUB_TOKEN environment variable)
    • -o, --output - Output directory (default: ./output)
    • -i, --include - Files to include (e.g., "*.py" "*.js")
    • -e, --exclude - Files to exclude (e.g., "tests/*" "docs/*")
    • -s, --max-size - Maximum file size in bytes (default: 100KB)
    • --language - Language for the generated tutorial (default: "english")
    • --max-abstractions - Maximum number of abstractions to identify (default: 10)
    • --no-cache - Disable LLM response caching (default: caching enabled)

The application will crawl the repository, analyze the codebase structure, generate tutorial content in the specified language, and save the output in the specified directory (default: ./output).

🐳 Running with Docker

To run this project in a Docker container, you'll need to pass your API keys as environment variables.

  1. Build the Docker image

    docker build -t pocketflow-app .
    
  2. Run the container

    You'll need to provide your GEMINI_API_KEY for the LLM to function. If you're analyzing private GitHub repositories or want to avoid rate limits, also provide your GITHUB_TOKEN.

    Mount a local directory to /app/output inside the container to access the generated tutorials on your host machine.

    Example for analyzing a public GitHub repository:

    docker run -it --rm \
      -e GEMINI_API_KEY="YOUR_GEMINI_API_KEY_HERE" \
      -v "$(pwd)/output_tutorials":/app/output \
      pocketflow-app --repo https://github.com/username/repo
    

    Example for analyzing a local directory:

    docker run -it --rm \
      -e GEMINI_API_KEY="YOUR_GEMINI_API_KEY_HERE" \
      -v "/path/to/your/local_codebase":/app/code_to_analyze \
      -v "$(pwd)/output_tutorials":/app/output \
      pocketflow-app --dir /app/code_to_analyze
    

💡 Development Tutorial


Pocket Flow Codebase Tutorial

PocketFlow-Tutorial-Codebase-Knowledge (The-Pocket/PocketFlow-Tutorial-Codebase-Knowledge)

Searching Database…

这是什么?一个工具,它会抓取 GitHub 仓库(或本地目录),用 LLM 分析代码库,找出核心抽象以及它们之间的交互方式,并把分析结果整理成适合新手阅读、带可视化图示的教程。
这是我要导入的库,还是我要运行的脚本?它是一个可以直接运行的命令行脚本(main.py),基于作者自己开发的 Pocket Flow 构建。Pocket Flow 是一个约 100 行代码的 LLM 框架,用来串联智能体的各个步骤。
怎样为一个仓库生成教程?克隆仓库,安装依赖,在 utils/call_llm.py 中(或 .env 文件里)配置 LLM 凭证,然后用 --repo 或 --dir 参数运行主脚本。输出默认保存到 ./output。
使用前需要 API 密钥吗?需要,你得有一个 LLM API 密钥。默认使用 Google AI Studio 的 GEMINI_API_KEY 来调用 Gemini Pro 2.5。你也可以切换服务商(例如设置 LLM_PROVIDER=XAI),或者指向本地的 Ollama 服务器,这样就不需要 API 密钥。
它对任何 LLM 都能很好地工作吗?不能。作者建议使用最新的、具备推理/思考能力的模型(如带 thinking 的 Claude 3.7、O1),因为较弱的模型很难正确识别代码库中的抽象。
这对谁有用?需要快速理解一个陌生代码库的开发者,不必从头逐行阅读。
能分析我的私有仓库吗?可以。通过 --token 参数或 GITHUB_TOKEN 环境变量传入 GitHub 令牌,即可访问私有仓库,也能避免触发速率限制。
我能用 Docker 运行,而不是在本地安装 Python 依赖吗?可以,项目中有 Dockerfile。构建镜像后,通过环境变量传入 GEMINI_API_KEY(可选再加上 GITHUB_TOKEN),并把本地文件夹挂载到 /app/output,就能取回生成的教程。
生成的教程能用英语以外的语言吗?可以,--language 参数可以选择教程的输出语言,默认是英语。
什么是 Pocket Flow?它是作者开发的极简 LLM 框架,约 100 行代码,用来构建这个生成教程的智能体。它的设计目标是让智能体能够再去构建其他智能体。
有没有可以先看的示例教程?有。README 中链接了一些针对热门仓库生成的 AI 教程,包括 FastAPI、Flask、Requests、CrewAI、LangGraph 和 NumPy Core,都是用本工具抓取这些仓库后生成的。
Creator
The-Pocket
Size
11.6 MB
Stars
12.7K
Updated
CommitMay 31
Age
1y
Commits · 90 Days