Gittodoc
repository·main·Indexed 42 days ago
https://github.com/filiksyos/gittodocA tool that transforms Git repositories into documentation links optimized for AI coding assistants like Cursor. It includes the gitingest CLI tool (v0.1.4) to analyze codebases and create text dumps consisting of a summary, directory tree, and concatenated file contents for LLM context.
What's inside Gittodoc
- Gittodoc is a tool designed to convert Git repositories into documentation links. These links are optimized to be fed into AI coding tools (such as Cursor) to provide them with repository context in a documentation-friendly format.
Gittodoc technical stack
mainGittodoc is built using the following technologies:
- Frontend: Tailwind CSS
- Backend: FastAPI
- Templating: Jinja2
- Token Estimation: tiktoken
Run Gittodoc using Docker Compose
mainThe recommended way to run Gittodoc is via Docker Compose, which handles the environment setup automatically.
# Or run with Docker Compose docker-compose up -dInstall and run Gittodoc via pip
mainTo run Gittodoc locally using Python, ensure you have Python 3.7+ installed. You must clone the repository first, as the application is not published on PyPI. Install the necessary dependencies using the provided
requirements.txtfile.# Install dependencies pip install -r requirements.txtRun Gittodoc with Docker Compose
mainYou can run the Gittodoc application using Docker Compose. The setup exposes the application on port
8000. To ensure the application functions correctly (especially for S3 storage or GitHub integration), you must provide several environment variables in your host environment or a.envfile.version: '3' services: app: build: context: . dockerfile: Dockerfile ports: - "8000:8000" environment: - GITINGEST_S3_BUCKET=${GITINGEST_S3_BUCKET} - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} - AWS_REGION=${AWS_REGION} - GITHUB_PAT=${GITHUB_PAT} volumes: - ./src:/app # Optional: Mount source code for developmentConfigure allowed hosts via ALLOWED_HOSTS environment variable
mainThe application uses
TrustedHostMiddlewareto restrict which host headers are accepted. You can control this by setting theALLOWED_HOSTSenvironment variable as a comma-separated list of domains. If this variable is not set, the application defaults to a predefined list includinglocalhost,127.0.0.1, and variousgittodoc.comoronrender.comsubdomains.Note: If you are running behind a proxy, ensure your proxy is correctly configured to handle
X-Forwarded-Hostheaders, otherwiseTrustedHostMiddlewaremay trigger 400 errors.# Example: Setting allowed hosts in your environment export ALLOWED_HOSTS="example.com,www.example.com,api.example.com"Format file system nodes with format_node()
mainThe
format_nodefunction generates a structured representation of a codebase for ingestion. It produces three distinct parts: a summary, a directory tree structure, and the concatenated file contents.If the provided
nodeis a directory, the function recursively processes all its children. If it is a single file, it summarizes that specific file.The returned tuple contains:
- Summary: Includes repository/directory metadata (name, commit, branch, subpath), file counts for directories, or file name and line counts for single files. It also includes an estimated token count (e.g., '1.2k', '1.2M') based on the
cl100k_baseencoding. - Directory Structure: A visual tree-like string representation of the file hierarchy.
- File Contents: A single concatenated string containing the contents of all files within the node.
from gitingest.output_formatters import format_node # node: FileSystemNode, query: IngestionQuery summary, tree, content = format_node(node, query)- Summary: Includes repository/directory metadata (name, commit, branch, subpath), file counts for directories, or file name and line counts for single files. It also includes an estimated token count (e.g., '1.2k', '1.2M') based on the
Access the Gittodoc home page via GET /
mainTheGET /endpoint serves the application's home page. It renders theindex.jinjatemplate and provides a list ofEXAMPLE_REPOSand adefault_file_sizeof 243 to the view context.GET /Check robots.txt for search engine crawlers
mainThe application serves a
robots.txtfile at the/robots.txtendpoint to guide search engine crawlers. This file is served as aFileResponsefrom thestatic/directory.GET /robots.txt HTTP/1.1 Host: your-domain.com # Response HTTP/1.1 200 OK Content-Type: text/plain User-agent: * Disallow: /private/FileSystemNode: Represent and extract content from filesystem nodes
mainThe
FileSystemNodeclass represents a single entity in the filesystem (a file, directory, or symlink). It is used to track properties like name, path, size, and depth, and to manage hierarchical relationships via achildrenlist.Key Capabilities
- Content Extraction: Use the
content_stringproperty to get a formatted string suitable for LLM context. This includes a separator, the path (normalized with/), and the actual file content. For non-text files, it returns[Non-text file]. For Jupyter notebooks (.ipynb), it usesprocess_notebookto extract content. - Hierarchical Sorting: Directories can have their children sorted using
sort_children(). This organizes nodes into a specific priority order:README.md(case-insensitive)- Regular files
- Hidden files (starting with
.) - Regular directories
- Hidden directories All groups are sorted alphanumerically within themselves.
Error Handling
- Calling
.contenton aDIRECTORYnode raises aValueError. - Calling
.sort_children()on a non-directory node raises aValueError. - If a file cannot be decoded,
contentreturns an error message instead of raising an exception.
# Example of accessing content from a node # Assuming 'node' is an instance of FileSystemNode if node.type == FileSystemNodeType.FILE: print(node.content_string)- Content Extraction: Use the
Access API documentation via /api
mainThe application provides a rendered HTML page containing API documentation at the
/api/or/apiendpoints. This is served using Jinja2 templates.GET /api/ HTTP/1.1 Host: your-domain.com # Response HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 <html>...API Documentation Content...</html>Use the /health endpoint for server monitoring
mainThe
/healthendpoint is a GET request used to verify that the server is running and healthy. It returns a JSON object containing the server status.GET /health HTTP/1.1 Host: your-domain.com # Response HTTP/1.1 200 OK Content-Type: application/json { "status": "healthy" }