Project Structure
Relevant source files
The following files were used as context for generating this wiki page:TestGenAI is an AI-powered test case generation platform with a monorepo structure containing a React frontend and a Go backend. The system is designed to clone a code repository, analyze its contents, and use Google's Gemini AI to generate a comprehensive test suite. The architecture has evolved to support both a traditional Go backend and a "client-side backend" implementation that runs entirely in the browser for simplified deployment.
The project is organized into two main directories: testgen/ for the frontend application and testgen-backend/ for the backend server. This separation allows for independent development and deployment of the client and server components.
Sources: README.md, CLIENT_BACKEND.md
High-Level Architecture
The system operates with three main components: a frontend UI, a backend processing service (which can be either the Go server or the client-side equivalent), and the external Google Gemini AI service.
This diagram illustrates the primary data flow: the frontend communicates with the backend, which in turn queries the Gemini AI to generate test cases.
Sources: README.md:16-22
Directory Structure
The monorepo is organized as follows:
| Directory | Description |
|---|---|
testgen/ | Contains the frontend application built with React, Vite, and TypeScript. |
testgen-backend/ | Contains the backend server written in Go. |
README.md | The main documentation file for the project. |
Sources: README.md:28-44
Frontend (testgen/)
The frontend is a modern single-page application (SPA) responsible for the user interface, state management, and communication with the backend services.
Sources: testgen/README.md, testgen/package.json
Technology Stack
- Framework/Library: React 18
- Build Tool: Vite
- Language: TypeScript
- Styling: Tailwind CSS with shadcn/ui components
- UI Components:
lucide-reactfor icons
Sources: testgen/README.md:4-11, testgen/package.json
Key Components & Logic
src/pages/Dashboard.tsx: The main application page that orchestrates the UI. It manages state for the repository URL, code input, and generated test cases. It contains handlers likehandleCloneRepositoryandhandleGenerateTeststo initiate the core workflows.src/components/TestRunner.tsx: An advanced test execution engine that runs the AI-generated tests. It includes a mock function library to simulate various operations like user management and API calls within a safe execution environment.src/lib/backend.ts: A client-side implementation of the backend logic. This allows the application to run serverlessly by interacting directly with the GitHub and Gemini APIs from the browser.src/lib/github.ts: Contains utility functions for interacting with the GitHub API, such as parsing URLs (parseGitHubUrl) and fetching repository files (fetchRepositoryFiles).
Sources: README.md:50-70, testgen/src/pages/Dashboard.tsx, testgen/src/components/TestRunner.tsx, testgen/src/lib/backend.ts, testgen/src/lib/github.ts
Client-Side Backend (src/lib/backend.ts)
To simplify deployment, a client-side backend was implemented. This TypeScript module replicates the Go backend's functionality, running entirely in the user's browser.
This diagram shows the static methods of the ClientBackend class, which handle repository fetching and test generation directly from the browser.
Sources: testgen/src/lib/backend.ts, testgen/CLIENT_BACKEND.md
The client-side repository "cloning" process avoids a full git clone by using the GitHub API.
This flow demonstrates how ClientBackend.cloneRepository fetches repository files without a local git clone, respecting exclusion rules and size limits.
Sources: testgen/src/lib/backend.ts:199-254, testgen/src/lib/github.ts:83-145
Backend (testgen-backend/)
The original backend is a Go server that exposes a REST API for the frontend to consume. It handles repository cloning, file processing, and proxying requests to the Gemini API.
Sources: testgen-backend/main.go
Technology Stack
- Language: Go (1.21+)
- Core Modules: Standard library (
net/http,os/exec,encoding/json) - Dependencies: None outside the standard library for core logic.
Sources: README.md:76-81, testgen-backend/main.go
API Endpoints
The Go backend provides the following endpoints:
| Method | Endpoint | Description |
|---|---|---|
POST | /api/clone-repo | Clones a public GitHub repository, reads its files, generates a context file, and returns file metadata. |
POST | /api/generate-tests | Takes code context and an API key, calls the Gemini API, and returns generated test cases. |
GET | /api/context/{owner}/{repo} | Retrieves the previously generated context file for a repository. |
Sources: README.md:83-125, testgen-backend/main.go:300-580
Core Logic: Repository Processing
The cloneRepoHandler function orchestrates the repository analysis workflow.
This diagram shows the sequence of operations performed by the Go backend when a request to clone a repository is received.
Sources: testgen-backend/main.go:300-362
A key part of this process is filtering out irrelevant files to keep the context provided to the AI concise and relevant.
// testgen-backend/main.go:70-81
var excludePatterns = []string{
"node_modules", ".git", "dist", "build", "coverage", ".next", ".nuxt",
".cache", "*.log", "*.tmp", ".DS_Store", "Thumbs.db", "*.min.js",
"*.min.css", "package-lock.json", "yarn.lock", "pnpm-lock.yaml",
"bun.lockb", ".env*", ".vscode", ".idea", "*.md", "LICENSE",
"README*", ".gitignore", ".eslintrc*", ".prettierrc*", "tsconfig.json",
"vite.config.*", "webpack.config.*", "rollup.config.*", "jest.config.*",
"vitest.config.*", "cypress", "e2e", "__tests__", "test", "tests",
"spec", "specs", "docs", "documentation", "assets", "images", "public", "static",
}
Sources: testgen-backend/main.go:70-81
Workflow Comparison: Go Backend vs. Client-Side
The core workflow of generating tests involves the UI, a backend layer, and the Gemini API. The sequence diagram below illustrates the process using the Go backend.
This diagram shows the multi-step process involving two separate user actions and multiple network requests.
Sources: README.md:131-137, testgen-backend/main.go, testgen/src/pages/Dashboard.tsx
In contrast, the client-side backend streamlines this by removing the Go server from the loop.
This diagram illustrates the serverless approach where the frontend directly communicates with external APIs.
Sources: testgen/CLIENT_BACKEND.md, testgen/src/lib/backend.ts
Summary
The testgenai project features a modular monorepo structure with a clear separation between its frontend (testgen/) and backend (testgen-backend/) components. The architecture is flexible, supporting both a traditional Go backend for server-based deployments and an innovative client-side backend that enables a fully serverless model. This dual approach allows for development and deployment versatility while maintaining a consistent user experience focused on AI-driven test case generation.
Sources: README.md, CLIENT_BACKEND.md