Gemini AI Integration
Relevant source files
The following files were used as context for generating this wiki page:
The Gemini AI Integration within the pcstyledev project is a backend automation system designed to streamline the management of portfolio projects. By leveraging Google's Gemini generative AI models, the system automatically analyzes local project directories to extract metadata, identify technology stacks, and generate descriptive summaries for the portfolio website.
This integration is primarily exposed through a Command Line Interface (CLI) tool. It handles the scanning of source code, construction of an analysis context (including "signals" like file trees and dependency lists), and structured data generation via a predefined JSON schema.
Architecture and Data Flow
The integration follows a linear pipeline that starts with a local directory path and ends with a structured ProjFile object. The process involves three main stages: gathering files, building a technical context, and performing the AI analysis.
The system identifies critical project files and "signals" to provide the LLM with enough context to make accurate technical inferences.
Sources: projects-cli/src/lib/gemini.ts:1-50, projects-cli/src/commands/add.ts:25-45
Core Components
| Component | Description | File Path |
|---|---|---|
gatherProjectFiles | Scans directories for READMEs, package manifests, and source entries using priority patterns. | projects-cli/src/lib/gemini.ts:52-113 |
buildSignals | Generates a summary of file counts, extensions, directory structures, and detected dependencies. | projects-cli/src/lib/gemini.ts:149-261 |
analyzeWithGemini | Interface for the GoogleGenAI client to request content generation with a strict JSON schema. | projects-cli/src/lib/gemini.ts:289-309 |
PROJECT_SCHEMA | A strict JSON schema defining required fields: id, name, desc, stack, status, and icon. | projects-cli/src/lib/gemini.ts:26-38 |
Technical Implementation
Context Generation and "Signals"
To minimize token usage while maximizing accuracy, the system builds a "signals" summary before reading full files. It scans for specific patterns to identify frameworks (e.g., React, Next.js, Electron) and language-specific dependencies from package.json, requirements.txt, Cargo.toml, and go.mod.
The buildContext function consolidates the directory name, signals, and truncated file contents (limited to 4000 characters per file) into a single prompt payload.
Sources: projects-cli/src/lib/gemini.ts:115-141, projects-cli/src/lib/gemini.ts:205-245
CLI Command Integration
The AI integration is utilized by two primary commands: add and update.
- Add Command: Analyzes a new directory, generates metadata, allows for interactive editing, and saves the result to a
.projfile and the centralprojects.json. - Update Command: Uses the
--autoflag to re-analyze an existing project directory and propose updates to fields that have changed.
Configuration and Security
API keys for the integration are managed via environment variables or local configuration files. The utility ensures that a GEMINI_API_KEY is present before attempting any analysis.
| Setting | Source | Description |
|---|---|---|
GEMINI_API_KEY | .env.local or process.env | Google Generative AI access token. |
REPO_PATH | PCSTYLE_REPO_PATH | Path to the website repository for syncing data. |
model | Static string | Currently utilizes gemini-2.5-flash. |
Sources: projects-cli/src/utils/config.ts:7-40, projects-cli/src/lib/gemini.ts:293
Data Structures
The system relies on the ProjFile interface, which maps directly to the AI's output schema.
// Sources: lib/types.ts:3-18
export interface Project {
id: string
name: string
desc: string
stack: string[]
link?: string
github?: string
status: ProjectStatus
icon: string
createdAt: string
updatedAt: string
}
The AI is specifically instructed to generate lowercase, one-sentence descriptions without periods and to select Lucide icons such as "Cpu", "Monitor", or "Globe".
Sources: projects-cli/src/lib/gemini.ts:13-24
Summary
The Gemini AI Integration acts as an automated "project librarian." By combining local file system analysis with structured LLM output, it ensures that project metadata remains consistent and technically accurate with minimal manual data entry. This system is central to the project's maintenance workflow, allowing the portfolio to evolve as the underlying source code changes.