Setup and context
Antigravity can multiply your development productivity several times over. However, simply using the tool isn't enough—understanding best practices is essential. This guide presents 20 proven techniques organized into five categories, applicable to developers of all levels.
Workspace Setup (5 Tips)
Tip 1: Plan Your Project Structure in Advance
Define your project structure before coding. This helps Antigravity generate consistent code that fits your architecture.
my-app/
├── src/
│ ├── components/ # UI Components
│ ├── pages/ # Page-level Components
│ ├── services/ # API & External Services
│ ├── hooks/ # Custom Hooks
│ ├── utils/ # Utility Functions
│ ├── types/ # TypeScript Definitions
│ └── styles/ # Global Styles
├── tests/ # Test Files
├── docs/ # Documentation
└── scripts/ # Build & Deploy Scripts
Tip 2: Document Your Tech Stack in README
# Project Name
## Technology Stack
- **Language**: TypeScript
- **Framework**: Next.js 14 (App Router)
- **Styling**: Tailwind CSS
- **State**: React Context + useReducer
- **Database**: PostgreSQL + Prisma
- **Testing**: Vitest + React Testing Library
## Coding Standards
- Auto-format with ESLint and Prettier
- Functional components only
- Functional programming preferred
- Strict TypeScript mode
- Minimum 80% test coverageWhen Antigravity references this, it generates code aligned with your standards.
Tip 3: Create and Save a System Prompt
At project start, create a system prompt file for consistent AI guidance.
# .antigravity/system-prompt.md
You are a senior full-stack TypeScript/React developer with 15+ years experience.
## Non-Negotiable Rules
1. TypeScript strict mode always
2. Functional components exclusively
3. Implement Error Boundaries
4. Accessibility WCAG 2.1 AA minimum
5. Production-ready code only (no placeholders)
6. Comprehensive error handling
7. Security-first mindset
8. Performance optimized
9. Fully tested codeTip 4: Define Code Style Configuration Files
Create .eslintrc.json and .prettierrc to enforce consistent formatting.
// .prettierrc
{
"singleQuote": true,
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"arrowParens": "always"
}Antigravity respects these configurations and generates conforming code.
Tip 5: Create a Project Glossary
Document project-specific terminology and concepts.
# Project Glossary
- **Resource**: Items managed within the system
- **Caching Strategy**: In-memory with 5-minute TTL
- **Error Boundary**: Always use try-catch in async functions
- **API Base URL**: https://api.example.com/v1
- **Rate Limit**: 100 requests/minute per user
- **Session Timeout**: 30 minutes of inactivityPrompt Optimization (5 Tips)
Tip 6: Divide Requests into Stages
Never request everything at once. Break large requests into logical stages.
# ❌ Wrong: All at once
> Build a complete app with database, API, UI, tests, and deployment
# ✅ Right: Staged
> Stage 1: Design Prisma schema
> Stage 2: Implement API routes
> Stage 3: Create React components
> Stage 4: Write unit tests
> Stage 5: Create E2E tests
Tip 7: Reference Existing Files Explicitly
Use @ notation to ensure Antigravity understands your existing code patterns.
Implement this component following the styling from @components/ui/Button.tsx
and the data patterns used in @lib/api-client.ts
Tip 8: Make Constraints Crystal Clear
Explicitly state all constraints and requirements.
# Implementation Constraints
## Performance Requirements
- Bundle size: < 100KB
- First Contentful Paint: < 1.5s
- Lighthouse score: > 90
## Browser Support
- Chrome/Edge: Latest 2 versions
- Safari: Latest 2 versions
- Mobile: iOS 14+, Android 12+
## Accessibility
- WCAG 2.1 Level AA
- Keyboard navigation complete
- Screen reader compatible
## Security
- No hardcoded secrets
- Input validation on all fields
- SQL injection prevention via ORMTip 9: Specify Error Scenarios Explicitly
Don't just say "handle errors"—list specific scenarios.
# Error Handling Requirements
## Network Errors
- Timeout: Auto-retry up to 3 times with exponential backoff
- Connection failure: Show user-friendly error message
- Invalid response: Log error and display fallback UI
## Business Logic Errors
- Invalid input: Display field-level validation errors
- Insufficient permissions: Return 403, redirect to login
- Resource not found: Show 404 message with recovery options
## Graceful Degradation
- If feature unavailable: Hide option rather than error
- If API slow: Show loading state, allow cancellationTip 10: Specify Output Format
Be explicit about code format and structure.
# Output Specifications
## File Details
- Filename: UserProfileCard.tsx
- Language: TypeScript
- Export: Named export only
- Location: src/components/profile/
## Documentation
- JSDoc for all public functions
- Props interface documented
- Inline comments for complex logic
## Testing
- Include test file: UserProfileCard.test.tsx
- Minimum coverage: 90%
- Test framework: VitestAgent Management (3 Tips)
Tip 11: Divide Responsibilities Across Agents
For complex projects, use separate agents for different concerns.
Agent 1: Frontend UI Components
Focus: SwiftUI views, state management, styling
Agent 2: Backend API Development
Focus: Routes, business logic, database
Agent 3: DevOps & Infrastructure
Focus: Configuration, deployment, monitoring
This separation keeps each agent focused and produces higher quality code.
Tip 12: Share Context Between Agents
Create shared documentation that all agents reference.
# Shared Project Context
## API Specification
- Base URL: https://api.example.com/v1
- Auth: Bearer token in Authorization header
- Response format: { success: boolean, data?: T, error?: { code, message } }
## Data Models
- User: id (UUID), email, name, createdAt, updatedAt
- Post: id, userId (FK), title, content, published, createdAt
- Comment: id, postId (FK), userId (FK), content, createdAt
## Environment Variables Required
- DATABASE_URL
- JWT_SECRET
- API_RATE_LIMITTip 13: Set Checkpoints in Long Conversations
Periodically validate progress in extended work.
> Let me review what we've built so far...
> (Review generated code)
> Are there any issues or refinements needed?
> Should we refactor this section?
> (Make adjustments)
> Proceeding with next phase...
Keyboard Efficiency & Acceleration (2 Tips)
Tip 14: Create Template Prompts
Save frequently used prompts as reusable templates.
# Template: React Component
Component Name: [NAME]
Purpose: [DESCRIPTION]
Props:
- [PROP]: [TYPE] - [DESCRIPTION]
Styling: Tailwind CSS
Features:
- [FEATURE 1]
- [FEATURE 2]
- [FEATURE 3]
Include: TypeScript types, JSDoc, test file
Register these in your editor as snippets for instant access.
Tip 15: Use Implementation Checklists
Include checklists in prompts to verify completeness.
# Implementation Checklist
- [ ] TypeScript interfaces defined
- [ ] Error boundaries implemented
- [ ] Loading states handled
- [ ] Empty states handled
- [ ] Accessibility features
- [ ] Unit tests (80%+ coverage)
- [ ] Storybook stories
- [ ] Performance optimization
- [ ] Security review
- [ ] Code review readyFile & Version Management (3 Tips)
Tip 16: Record Generation Metadata
Document AI-generated code origins.
/**
* @generated by Antigravity
* @date 2026-03-10
* @model claude-opus-4-6
* @prompt "ProductCard component with image, title, price, rating"
* @lastModified 2026-03-11 (Manual fixes applied)
*/
export default function ProductCard(props: ProductCardProps) {
// Implementation
}Tip 17: Use Feature Branches for Generated Code
Keep generated code changes isolated.
# Create branch for AI-generated features
git checkout -b feat/generated-components
# Make necessary customizations
# Add tests and documentation
git add .
git commit -m "feat: generate and customize components"
# Code review before merging
git push origin feat/generated-components
# Create pull requestTip 18: Mark Deprecated Code
When replacing AI-generated code, clearly mark deprecation.
/**
* @deprecated Use useModernHook instead
* @removal Date: 2026-04-15
* @migration See docs/migration-guide.md
*/
export function useOldHook() {
// Implementation
}Testing & Validation (2 Tips)
Tip 19: Always Validate Generated Code Before Use
Never use AI-generated code directly in production without verification.
# Code Validation Checklist
- [ ] Logic correctness verified
- [ ] Performance tested (profiler)
- [ ] Unit tests: 80%+ coverage, all passing
- [ ] Edge cases handled (null, undefined, empty)
- [ ] Security review: No vulnerabilities
- [ ] No console errors/warnings
- [ ] Accessibility audit passed
- [ ] Code reviewed by peer
- [ ] TypeScript types strict and correct
- [ ] Ready for productionTip 20: Learn From Failures
Analyze unexpected outputs to improve future prompts.
# Failure Analysis Template
## What Happened?
[Describe generated output and how it differed from expectation]
## Root Cause
[What was missing or unclear in the prompt?]
- Was context insufficient?
- Were requirements ambiguous?
- Was constraint not mentioned?
## Improvement Plan
[How will you modify the prompt next time?]
## Prevention
[What can you document to prevent this in future?]Summary by Category
Workspace Setup (Tips 1-5)
- Plan structure in advance
- Document tech stack in README
- Create system prompt file
- Define code style config
- Create project glossary
Prompt Optimization (Tips 6-10)
- Divide requests into stages
- Reference existing files with @
- State constraints explicitly
- Specify error scenarios
- Define output format clearly
Agent Management (Tips 11-13)
- Separate agents by responsibility
- Share context between agents
- Set periodic checkpoints
Efficiency (Tips 14-15)
- Create prompt templates
- Use implementation checklists
File & Version Management (Tips 16-18)
- Record generation metadata
- Use feature branches
- Mark deprecated code
Testing & Validation (Tips 19-20)
- Validate before production use
- Learn from failures
Practical Workflow: Putting It All Together
Phase 1: Preparation (Tips 1-5)
1. Define project structure
2. Write comprehensive README
3. Create system prompt
4. Configure ESLint/Prettier
5. Document glossary
Phase 2: Development (Tips 6-15)
6. Break features into stages
7. Reference existing files
8. State all constraints
9. Define error scenarios
10. Specify output format
11-15: Use templates, checklists, multi-agent approach
Phase 3: Validation & Integration (Tips 16-20)
16. Record generation metadata
17. Use feature branches
18. Mark deprecated code
19. Run validation checklist
20. Document lessons learned
Conclusion
These 20 best practices transform Antigravity from a code generation tool into a true development partner. The key is flexibility—adapt these guidelines to your workflow rather than treating them as rigid rules.
Success comes from consistent practice and iteration. Start with a few tips that resonate with your development style, gradually add more, and continuously refine your approach. As you internalize these practices, Antigravity becomes an increasingly powerful force multiplier for your productivity.
The most successful teams using Antigravity share one trait: they invest time in proper setup and prompting. This upfront investment pays enormous dividends in code quality and development velocity.