Skip to content

DefangSamples/sample-repo-base-template

Repository files navigation

Repo Base

1-click-deploy

This sample shows how to deploy an AI-powered GitHub repository chat tool using Mastra, a TypeScript AI framework. Repo Base allows you to chat with and understand any GitHub repository by fetching file trees, contents, pull requests, and issues, making it easy to navigate and understand codebases of any size.

Features

  • Repository Analysis: Enter a GitHub repository URL and instantly start a conversation about it
  • Code Exploration: Navigate file trees, view file contents, and understand code structure
  • PR & Issue Access: Query information about pull requests and issues directly in chat
  • Large Codebase Support: Powered by Google's Gemini Flash model with its large context window
  • Intuitive UI: Built with assistant-UI for a seamless chat experience with retries, copy, and message branching

Prerequisites

  1. Download Defang CLI
  2. (Optional) If you are using Defang BYOC authenticate with your cloud provider account
  3. (Optional for local development) Docker CLI

Development

To run the application locally for development, use the development compose file:

docker compose -f compose.dev.yaml up

This will:

  • Start PostgreSQL with volume persistence for local development
  • Expose PostgreSQL on port 5432 for direct access if needed
  • Start the Next.js application on port 3000 with hot reload

You can access Repo Base at http://localhost:3000 once the containers are running.

Configuration

For this sample, you will need to provide the following configuration. Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.

GOOGLE_GENERATIVE_AI_API_KEY

Your Google Generative AI API key for accessing the Gemini Flash model. You can get this from the Google AI Studio.

DB_URL

The PostgreSQL database connection string. This will be automatically configured when using Defang's managed database services.

DB_SSL

Set to true to enable SSL. Set to false to disable SSL. (Can be set directly in the docker compose file)

GITHUB_TOKEN (Optional)

A GitHub personal access token to increase API rate limits when fetching repository data. This is optional but recommended for better performance.

Usage

  1. Enter a GitHub repository URL in the input field (e.g., https://github.com/facebook/react)
  2. Start chatting with Repo Base about the repository
  3. Use commands like:
    • "Show me the file structure"
    • "What are the recent pull requests?"
    • "Explain the purpose of [filename]"
    • "How many open issues are there?"

How It Works

Repo Base uses a tool-based approach rather than traditional RAG systems, making it more efficient for large codebases. When you provide a repository URL, Repo Base uses tools to:

  1. Fetch the repository's file tree
  2. Access file contents on demand
  3. Retrieve information about pull requests and issues
  4. Store conversation history using Mastra's memory package

The large context window of Gemini Flash allows the agent to hold more code in memory, making the conversation more coherent and informed.

Deployment

Note

Download Defang CLI

Defang Playground

Deploy your application to the Defang Playground by opening up your terminal and typing:

defang compose up

BYOC (Deploy to your own AWS or GCP cloud account)

If you want to deploy to your own cloud account, you can use Defang BYOC.

[!WARNING] > Extended deployment time: This sample creates a managed PostgreSQL database which may take upwards of 20 minutes to provision on first deployment. Subsequent deployments are much faster (2-5 minutes).

This sample was base off of mastra's repo-chat sample.


Title: Repo Base

Short Description: An AI-powered tool for chatting with GitHub repositories using Mastra and Google Gemini.

Tags: AI, GitHub, Mastra, Next.js, PostgreSQL, TypeScript

Languages: TypeScript, JavaScript, Docker

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages