The go-describe-repo
project is a tool developed in Go (Golang) designed to generate detailed descriptions of the structure and components of a given repository. Utilizing the OpenAI API, the project takes a directory path as input, analyzes the files within the directory, and synthesizes a description based on the interactions of these files, aiming to assist in understanding the purpose and structure of the project.
-
.gitignore
- Purpose: Specifies files and directories that should be ignored by Git. This includes build artifacts, temporary files, and other non-essential files.
- Role: This file keeps the repository clean by ensuring only necessary files are committed, which prevents unnecessary clutter from build artifacts and temporary files.
-
main.go
- Purpose: The main entry point for the Go application. It initializes the project, processes the repository’s files, and interacts with the OpenAI API to generate project descriptions.
- Role: It coordinates the overall process of loading environment variables, reading the file structure, generating prompts, calling the OpenAI API, and handling the output.
-
Initialization and Setup:
- The application begins by loading environment variables using the
godotenv
package. This includes the OpenAI API key necessary for making requests to the OpenAI platform. - The user must provide a directory path that contains the repository to be analyzed. This path is processed to deduce the project name and set up an output directory structure.
- The application begins by loading environment variables using the
-
Reading and Ignoring Files:
- The
readGitignore
function reads the.gitignore
file located in the provided directory. The file's patterns are compiled into agitignore
object, which is used to filter out files and directories during the repository analysis. - The
filepath.Walk
function traverses the directory, collecting files and filtering out those that match the patterns specified in.gitignore
.
- The
-
Language Identification and Entry Point Detection:
- The file extensions are tallied to determine the primary language of the repository. The most frequent extension is designated as the primary language.
- Based on the primary language, the entry point is inferred (e.g.,
main.go
for Go projects).
-
Generating Prompts and Calling OpenAI:
- A prompt string is formulated, encapsulating the primary language, file structure, and entry point. This prompt is used to query the OpenAI API for an initial project description.
- The response from the OpenAI API, which contains a detailed description of the project’s purpose and structure, is then processed.
-
Creating Project Context and Output:
- A
ProjectContext
struct is created, encapsulating the project name, the description generated by OpenAI, the file structure, and the contents of the current code files. - This struct is serialized into a JSON file (
project_context.json
) and saved to the output directory. - A new prompt is generated to create a detailed project description based on the JSON data, which is then sent to the OpenAI API for further refinement.
- A
-
Final Project Description:
- The detailed project description obtained from the OpenAI API is written to a Markdown file (
project_description.md
), providing a comprehensive overview of the project's components and their interactions.
- The detailed project description obtained from the OpenAI API is written to a Markdown file (
- User Modifies Repo Configuration: The developer ensures the
.gitignore
file is accurate and up-to-date. - Invoke the Tool: The developer runs the tool by executing
go run main.go /path/to/repository
, initiating the analysis process. - Generate Initial Description: The tool processes the repository, generates an initial prompt, and queries the OpenAI API for a preliminary project description.
- Refine and Save Descriptions: The detailed project descriptions (in JSON and Markdown format) are saved to the designated output directory, providing valuable documentation for the repository.
In summary, the go-describe-repo
project uses Go to automate the creation of detailed project documentation by analyzing repository structures and leveraging AI to generate insightful descriptions.