Skip to content

josemlopez/gemini_md_tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 The Complete Guide to Creating Effective GEMINI.md Files

graph TB
    A[πŸ€– Generic AI Assistant] --> B[πŸ“ GEMINI.md]
    B --> C[🎯 Project-Aware Collaborator]
    
    A --> D[General Assumptions<br/>Inconsistent Responses<br/>Repetitive Context]
    
    C --> E[Contextual Accuracy<br/>Consistent Patterns<br/>Efficient Workflow]
    
    style A fill:#4a5568,stroke:#68d391,stroke-width:2px,color:#e2e8f0
    style B fill:#2d3748,stroke:#f6ad55,stroke-width:2px,color:#e2e8f0
    style C fill:#1a202c,stroke:#68d391,stroke-width:2px,color:#e2e8f0
    style D fill:#4a5568,stroke:#fc8181,stroke-width:2px,color:#e2e8f0
    style E fill:#1a202c,stroke:#68d391,stroke-width:2px,color:#e2e8f0
Loading

πŸ“š Table of Contents

  1. What is GEMINI.md and Why It Matters
  2. Understanding the Hierarchical Memory System
  3. Essential Components of a Good GEMINI.md
  4. Step-by-Step Creation Process
  5. Platform-Specific Configurations
  6. Advanced Techniques and Best Practices
  7. Common Mistakes to Avoid
  8. Testing and Optimization
  9. Real-World Examples
  10. Maintenance and Updates

🎯 What is GEMINI.md and Why It Matters

🧠 Your Project's AI Memory Bank

GEMINI.md is a special Markdown file that serves as a persistent instruction set for Google's Gemini CLI. Think of it as your project's AI memory bank - it provides context, rules, and guidance that helps Gemini understand your project's unique requirements and maintain consistency across all interactions.

⚠️ Why GEMINI.md is Critical

❌ Without GEMINI.md

  • Inconsistent code style and architecture decisions
  • Misaligned responses that don't match your project's goals
  • Repetitive explanations of project context
  • Generic solutions that don't fit your specific tech stack

βœ… With GEMINI.md

  • Contextual Accuracy: Gemini understands your project's purpose and constraints
  • Consistency: All generated content follows your established patterns
  • Efficiency: No need to re-explain project basics in every conversation
  • Quality Control: Built-in guardrails prevent common mistakes

πŸ—οΈ Understanding the Hierarchical Memory System

graph TD
    A[🌐 Global Context] --> B[πŸ“‹ Project Context]
    B --> C[πŸ“ Component Context]
    
    A --> D[~/.gemini/GEMINI.md<br/>Universal Preferences<br/>General Standards]
    
    B --> E[./GEMINI.md<br/>Project-Wide Rules<br/>Tech Stack Info]
    
    C --> F[./subdirectory/GEMINI.md<br/>Specific Module Rules<br/>Component Guidelines]
    
    style A fill:#2d3748,stroke:#81c784,stroke-width:2px,color:#e2e8f0
    style B fill:#2d3748,stroke:#ba68c8,stroke-width:2px,color:#e2e8f0
    style C fill:#2d3748,stroke:#ffb74d,stroke-width:2px,color:#e2e8f0
    style D fill:#1a202c,stroke:#81c784,stroke-width:2px,color:#e2e8f0
    style E fill:#1a202c,stroke:#ba68c8,stroke-width:2px,color:#e2e8f0
    style F fill:#1a202c,stroke:#ffb74d,stroke-width:2px,color:#e2e8f0
Loading

Gemini CLI uses a hierarchical approach to load GEMINI.md files, combining context from multiple locations:

Loading Order (General β†’ Specific):

  1. Global Context: ~/.gemini/GEMINI.md
  2. Project Root: ./GEMINI.md (at .git directory level)
  3. Subdirectory: ./subdirectory/GEMINI.md

πŸ—οΈ Practical Application

# Global configuration (applies to all projects)
~/.gemini/GEMINI.md

# Project-specific configuration
my-project/
β”œβ”€β”€ .git/
β”œβ”€β”€ GEMINI.md                    # Project-wide rules
β”œβ”€β”€ frontend/
β”‚   └── GEMINI.md               # Frontend-specific rules
└── backend/
    └── api/
        └── GEMINI.md           # API-specific rules

πŸ”‘ Key Commands:

  • /memory show - View combined context from all loaded files
  • /memory refresh - Reload all GEMINI.md files

🧩 Essential Components of a Good GEMINI.md

graph TB
    A[πŸ“ GEMINI.md Architecture] --> B[Six Core Components]
    
    B --> C[🎯 Project Overview]
    B --> D[πŸ› οΈ Technology Stack]
    B --> E[πŸ—οΈ Architecture Patterns]
    B --> F[πŸ“‹ Coding Standards]
    B --> G[πŸ”„ Development Workflow]
    B --> H[πŸ€– AI Collaboration Rules]
    
    style A fill:#2d3748,stroke:#64b5f6,stroke-width:2px,color:#e2e8f0
    style B fill:#2d3748,stroke:#ba68c8,stroke-width:2px,color:#e2e8f0
    style C fill:#1a202c,stroke:#81c784,stroke-width:2px,color:#e2e8f0
    style D fill:#1a202c,stroke:#ffb74d,stroke-width:2px,color:#e2e8f0
    style E fill:#1a202c,stroke:#f06292,stroke-width:2px,color:#e2e8f0
    style F fill:#1a202c,stroke:#aed581,stroke-width:2px,color:#e2e8f0
    style G fill:#1a202c,stroke:#4dd0e1,stroke-width:2px,color:#e2e8f0
    style H fill:#1a202c,stroke:#f8bbd9,stroke-width:2px,color:#e2e8f0
Loading

🎯 1. Project Overview Section

# Project Context: [Project Name]

## 1. Project Overview & Purpose
**Primary Goal:** Clear, one-sentence description of what your project does
**Business Domain:** Industry or field (e.g., E-commerce, Fintech, Education)
**Target Audience:** Who uses this project

πŸ› οΈ 2. Technology Stack Section

## 2. Core Technologies & Stack
**Languages:** Primary programming languages with versions
**Frameworks & Runtimes:** Major frameworks (React 18, Node.js 20, etc.)
**Databases:** Database systems and their roles
**Key Libraries:** Critical dependencies that define functionality
**Package Manager:** npm, pip, Maven, etc.

πŸ—οΈ 3. Architecture Documentation

## 3. Architectural Patterns
**Overall Architecture:** Monolithic, microservices, serverless, etc.
**Directory Structure Philosophy:**
- `/src`: Primary source code
- `/tests`: All testing files
- `/config`: Configuration management

πŸ“‹ 4. Coding Standards

## 4. Coding Conventions & Style Guide
**Formatting:** Indentation, line length, style guides
**Naming Conventions:**
- Variables: camelCase
- Classes: PascalCase  
- Files: kebab-case
**Error Handling:** Standard patterns used in the project

πŸ€– 5. AI Collaboration Rules

## 5. Specific Instructions for AI Collaboration
**Prohibited Actions:**
- ❌ Never modify .env files
- ❌ Don't install dependencies without asking
- ❌ Avoid breaking changes to public APIs

**Required Practices:**
- βœ… Always include unit tests for new functions
- βœ… Follow existing error handling patterns
- βœ… Update documentation for API changes

πŸš€ Step-by-Step Creation Process

graph LR
    A[πŸ” Analyze Project] --> B[πŸ“ Start Template]
    B --> C[🎯 Fill Details]
    C --> D[βš–οΈ Define Boundaries]
    D --> E[βœ… Test & Refine]
    
    style A fill:#2d3748,stroke:#64b5f6,stroke-width:2px,color:#e2e8f0
    style B fill:#2d3748,stroke:#ba68c8,stroke-width:2px,color:#e2e8f0
    style C fill:#2d3748,stroke:#ffb74d,stroke-width:2px,color:#e2e8f0
    style D fill:#2d3748,stroke:#f06292,stroke-width:2px,color:#e2e8f0
    style E fill:#2d3748,stroke:#81c784,stroke-width:2px,color:#e2e8f0
Loading

Step 1: Analyze Your Project

Before writing your GEMINI.md, conduct a thorough analysis:

# Navigate to your project root
cd your-project

# Examine the structure
ls -la
find . -name "*.json" -o -name "*.md" -o -name ".*rc"

# Check for existing documentation
cat README.md
cat CONTRIBUTING.md
cat package.json  # or requirements.txt, pom.xml, etc.

Step 2: Start with the Template

# GEMINI.md: AI Collaboration Guide for [Project Name]

## 1. Project Overview & Purpose
[Fill in project details]

## 2. Core Technologies & Stack
[List your tech stack]

## 3. Architectural Patterns
[Describe your architecture]

## 4. Coding Conventions & Style Guide
[Define your standards]

## 5. Development Workflow
[Explain how development works]

## 6. Specific Instructions for AI Collaboration
[Set clear rules and expectations]

Step 3: Fill in Project-Specific Details

Focus on what makes your project unique:

# Example for a Next.js E-commerce Project

## 1. Project Overview & Purpose
**Primary Goal:** Multi-vendor marketplace for handmade crafts with integrated payment processing
**Business Domain:** E-commerce/Marketplace
**Target Audience:** Artisan sellers and craft buyers

## 2. Core Technologies & Stack
**Languages:** TypeScript, JavaScript
**Frameworks:** Next.js 14 (App Router), React 18
**Database:** PostgreSQL with Prisma ORM
**Payment:** Stripe Connect for multi-vendor payments
**Styling:** Tailwind CSS with shadcn/ui components
**Package Manager:** npm

Step 4: Define Clear Boundaries

## AI Collaboration Rules

**Critical Restrictions:**
- ❌ NEVER modify payment processing logic without explicit approval
- ❌ Do NOT change database schema without migration planning
- ❌ Avoid modifying authentication/authorization without security review

**Standard Practices:**
- βœ… All new components must include TypeScript interfaces
- βœ… Use existing UI components from `/components/ui`
- βœ… Follow the established file naming convention
- βœ… Include error boundaries for new page components

πŸŽ›οΈ Platform-Specific Configurations

graph TB
    A[πŸŽ›οΈ Configuration Levels] --> B[🌐 Global Config]
    A --> C[πŸ“‹ Project Config]
    A --> D[🧩 Component Config]
    
    B --> E[Personal Preferences<br/>Universal Standards<br/>General Guidelines]
    
    C --> F[Project Requirements<br/>Tech Stack Rules<br/>Business Context]
    
    D --> G[Module-Specific Rules<br/>Component Standards<br/>Local Constraints]
    
    style A fill:#2d3748,stroke:#64b5f6,stroke-width:2px,color:#e2e8f0
    style B fill:#1a202c,stroke:#81c784,stroke-width:2px,color:#e2e8f0
    style C fill:#1a202c,stroke:#ffb74d,stroke-width:2px,color:#e2e8f0
    style D fill:#1a202c,stroke:#f06292,stroke-width:2px,color:#e2e8f0
    style E fill:#2d3748,stroke:#81c784,stroke-width:2px,color:#e2e8f0
    style F fill:#2d3748,stroke:#ffb74d,stroke-width:2px,color:#e2e8f0
    style G fill:#2d3748,stroke:#f06292,stroke-width:2px,color:#e2e8f0
Loading

🌐 Global Configuration (~/.gemini/GEMINI.md)

Use this for personal preferences and general standards:

# Global Gemini CLI Configuration

## General Coding Preferences
- **Communication Style:** Direct and technical, avoid excessive explanations
- **Documentation:** Always include JSDoc comments for functions
- **Testing:** Prefer unit tests over integration tests when possible
- **Dependencies:** Justify new dependencies and check for alternatives

## Language-Specific Rules
**JavaScript/TypeScript:**
- Use 2-space indentation
- Prefer functional components with hooks
- Use async/await over Promises.then()

**Python:**
- Follow PEP 8 strictly
- Use type hints for all function parameters
- Prefer dataclasses over regular classes when appropriate

πŸ“‹ Project-Level Configuration

Focus on project-specific requirements:

# Project: Customer Dashboard

## Business Context
This dashboard serves enterprise customers who manage large-scale operations.
Security and reliability are top priorities.

## Technical Constraints
- Must support IE11 (legacy customer requirement)
- All API calls must include audit logging
- Maximum bundle size: 2MB
- Required accessibility: WCAG 2.1 AA compliance

## Integration Requirements
- Uses internal auth service (contact @security-team for changes)
- Connects to legacy SOAP APIs (documentation in /docs/api)
- Must work offline for core features

🧩 Component-Level Configuration

For specific modules or components:

# Component: Payment Processing Module

## Security Requirements
- All payment data must be encrypted at rest
- PCI DSS compliance required
- No payment information in logs

## Testing Requirements
- Mock all external payment APIs
- Include integration tests with test payment gateways
- Validate all error handling paths

## Dependencies
- Use only approved payment libraries from security team
- Must support Stripe, PayPal, and internal payment processor

πŸ”§ Advanced Techniques and Best Practices

🧩 1. Modular Context with Imports

For large projects, organize GEMINI.md files by importing other Markdown files:

# Main GEMINI.md
@architecture.md
@coding-standards.md
@security-guidelines.md

# Project-specific additions
## Current Sprint Goals
- Implement user authentication
- Set up payment processing
- Create admin dashboard

🌍 2. Environment-Specific Instructions

πŸ”§ Development Environment

  • Use npm run dev for local development
  • Database runs on localhost:5432
  • Mock external APIs using MSW

πŸš€ Production Considerations

  • All changes require approval from @senior-dev
  • Database migrations must be backward compatible
  • No direct database access in production code

πŸ‘₯ 3. Role-Based Instructions

## Role-Based Guidelines

### When Acting as Code Reviewer
- Focus on security implications
- Check for proper error handling
- Verify test coverage meets 80% threshold
- Ensure documentation is updated

### When Acting as Bug Fixer
- Always create a test that reproduces the bug first
- Fix root cause, not just symptoms
- Update related documentation
- Consider impact on existing features

πŸ”„ 4. Dynamic Context Updates

## Current Project State

**Active Sprint:** Authentication Implementation (Week 2 of 3)
**Blockers:** Waiting for security team approval on auth flow
**Next Priority:** Payment integration after auth completion
**Testing Focus:** User registration and login flows

**Updated:** 2025-01-15
**Next Review:** 2025-01-22

⚠️ Common Mistakes to Avoid

❌ Being Too Vague

"Follow good coding practices"

βœ… Being Specific

"Use 2-space indentation, prefer const over let, include JSDoc for exported functions"

❌ Information Overload

Including every possible detail and configuration

βœ… Focused Content

Focus on what's unique to your project and most likely to cause confusion

❌ Outdated Information

Leaving old technology versions or deprecated practices

βœ… Current Information

Regular updates and version tracking


πŸ§ͺ Testing and Optimization

graph LR
    A[πŸ§ͺ Test Configuration] --> B[πŸ“Š Monitor Responses]
    B --> C[πŸ“ Note Corrections]
    C --> D[πŸ”„ Update GEMINI.md]
    D --> E[✨ Optimized System]
    
    style A fill:#2d3748,stroke:#64b5f6,stroke-width:2px,color:#e2e8f0
    style B fill:#2d3748,stroke:#ba68c8,stroke-width:2px,color:#e2e8f0
    style C fill:#2d3748,stroke:#ffb74d,stroke-width:2px,color:#e2e8f0
    style D fill:#2d3748,stroke:#f06292,stroke-width:2px,color:#e2e8f0
    style E fill:#2d3748,stroke:#81c784,stroke-width:2px,color:#e2e8f0
Loading

πŸ” Validate Your GEMINI.md

Test your configuration by asking Gemini specific questions:

# Test project understanding
> "Explain the architecture of this project"

# Test coding standards
> "Write a new API endpoint for user registration"

# Test boundaries
> "Should I modify the authentication middleware?"

πŸ”„ Iterative Improvement

πŸ“Š Monitor & Analyze

  • Monitor Gemini's responses for consistency
  • Note recurring corrections needed

πŸ”„ Update & Refine

  • Update GEMINI.md to prevent issues
  • Review and refine regularly

🌟 Real-World Examples

πŸš€ Startup MVP Project

# Quick MVP Development

## Goal: Social Media Analytics Tool
**Timeline:** MVP in 2 weeks
**Stack:** Next.js, Vercel, Supabase
**Priority:** Speed over perfection

## Rules
- βœ… Use shadcn/ui for quick UI
- βœ… Supabase Auth
- ❌ No custom styling until validated

🏒 Enterprise Application

# Bank Customer Dashboard

## Goal: Secure customer portal
**Compliance:** SOX, PCI DSS, GDPR

## Security Requirements
- Security team review required
- Audit logging for all actions
- Session timeout: 15 minutes
- MFA required

🌍 Open Source Project

# React UI Component Library

## Goal: Accessible, customizable components
**Community:** 50+ contributors

## Standards
- Storybook documentation required
- Accessibility tests (jest-axe)
- TypeScript interfaces for all props
- 100% test coverage

πŸ”„ Maintenance and Updates

graph TD
    A[πŸ“… Regular Review Schedule] --> B[πŸ“Š Weekly Updates]
    A --> C[πŸ“‹ Monthly Reviews]
    A --> D[πŸ” Quarterly Audits]
    
    B --> E[Sprint/Project Status<br/>Current Blockers<br/>Immediate Goals]
    
    C --> F[Technical Information<br/>Dependency Updates<br/>Process Changes]
    
    D --> G[Complete Guidelines Audit<br/>Standards Review<br/>Architecture Updates]
    
    style A fill:#2d3748,stroke:#64b5f6,stroke-width:2px,color:#e2e8f0
    style B fill:#1a202c,stroke:#81c784,stroke-width:2px,color:#e2e8f0
    style C fill:#1a202c,stroke:#ffb74d,stroke-width:2px,color:#e2e8f0
    style D fill:#1a202c,stroke:#f06292,stroke-width:2px,color:#e2e8f0
    style E fill:#2d3748,stroke:#81c784,stroke-width:2px,color:#e2e8f0
    style F fill:#2d3748,stroke:#ffb74d,stroke-width:2px,color:#e2e8f0
    style G fill:#2d3748,stroke:#f06292,stroke-width:2px,color:#e2e8f0
Loading

πŸ“Š Version Control Integration

## GEMINI.md Changelog

### v2.1.0 - 2025-01-15
- Added authentication guidelines
- Updated testing requirements
- Removed deprecated API references

### v2.0.0 - 2025-01-01
- Major refactor for new architecture
- Added security compliance requirements
- Updated technology stack information

πŸ‘₯ Team Collaboration

πŸ”„ Process Integration

  • Include GEMINI.md in code review
  • Document AI interaction decisions
  • Share updates with team members

πŸ“ Template Creation

  • Create templates for common project types
  • Standardize across team projects
  • Share best practices and lessons learned

πŸš€ Transform Gemini into Your Perfect AI Collaborator

A well-crafted GEMINI.md file transforms Gemini CLI from a generic AI assistant into a project-aware, context-intelligent collaborator. The key is to be specific, maintain current information, and continuously refine based on actual usage patterns.

graph LR
    A[πŸ“ Specific Guidelines] --> B[🎯 Clear Context]
    B --> C[πŸ”„ Continuous Evolution]
    C --> D[πŸš€ Perfect AI Collaborator]
    
    style A fill:#2d3748,stroke:#81c784,stroke-width:2px,color:#e2e8f0
    style B fill:#2d3748,stroke:#ffb74d,stroke-width:2px,color:#e2e8f0
    style C fill:#2d3748,stroke:#f06292,stroke-width:2px,color:#e2e8f0
    style D fill:#1a202c,stroke:#68d391,stroke-width:3px,color:#e2e8f0
Loading

πŸ”‘ Core Principles

🎯 Specificity over generality Focus on what makes your project unique

πŸ” Clarity over comprehensiveness Better to be clear about fewer things than vague about everything

πŸ”„ Evolution over perfection Start simple and improve based on real usage

πŸ“‹ Context over assumptions Provide the context Gemini needs to make good decisions

With these guidelines, your GEMINI.md will serve as an effective bridge between your project's requirements and AI assistance, resulting in more accurate, consistent, and valuable interactions. Happy collaboration!

About

Tutorial for the best possible Gemini.md

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published