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
- What is GEMINI.md and Why It Matters
- Understanding the Hierarchical Memory System
- Essential Components of a Good GEMINI.md
- Step-by-Step Creation Process
- Platform-Specific Configurations
- Advanced Techniques and Best Practices
- Common Mistakes to Avoid
- Testing and Optimization
- Real-World Examples
- Maintenance and Updates
π§ 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.
- 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
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
Gemini CLI uses a hierarchical approach to load GEMINI.md files, combining context from multiple locations:
Loading Order (General β Specific):
- Global Context:
~/.gemini/GEMINI.md - Project Root:
./GEMINI.md(at .git directory level) - Subdirectory:
./subdirectory/GEMINI.md
# 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
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
# 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. 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. Architectural Patterns
**Overall Architecture:** Monolithic, microservices, serverless, etc.
**Directory Structure Philosophy:**
- `/src`: Primary source code
- `/tests`: All testing files
- `/config`: Configuration management## 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. 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 changesgraph 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
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.# 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]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## 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 componentsgraph 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
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 appropriateFocus 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 featuresFor 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 processorFor 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π§ Development Environment
- Use
npm run devfor 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
## 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## 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"Use 2-space indentation, prefer const over let, include JSDoc for exported functions"
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
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?"π Monitor & Analyze
- Monitor Gemini's responses for consistency
- Note recurring corrections needed
π Update & Refine
- Update GEMINI.md to prevent issues
- Review and refine regularly
# 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# 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 requiredgraph 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
## 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π 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
π― 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!