Brifing

Teaching AI to Write Android Code Your Way: A Team Playbook Approach

How we trained AI to generate Kotlin code that matches our team's exact standards

Medium Engineering2 min

1Problem: Generic AI Outputs

Medium's small Android team faced issues with AI assistants producing generic Kotlin code. The AI didn't understand their Clean Architecture principles, Jetpack Compose standards, or testing approach. They needed to centralize knowledge scattered across PR comments and Slack threads.

2Solution: The AGENTS.md File

This document at the project root serves as an AI playbook. It contains 30+ critical standards including module structure, Hilt injection, and StateFlow usage. Now AI automatically uses @HiltViewModel and sealed interfaces when creating ViewModels.

3Deep Learning with Skill Files

13 Markdown files in .agents/skills/ teach step-by-step workflows. For example, the create-compose-screen skill automatically generates 6-8 files for a new screen, including both ViewModel-injected and test-friendly composable versions.

4Scaffolding Skills

These automate 30-60 minute tasks like creating new screens or modules. create-feature-module handles everything from Gradle configuration to dependency wiring. create-use-case implements Clean Architecture layers with operator functions returning Result<T>.

5AI in Migration Processes

For long migrations like Material 2 to 3, AI uses a 60+ component mapping table. The compose-viewmodel-migration skill transforms Fragment-based structures to modern hiltViewModel composables, minimizing human error in complex transitions.

6Pattern Enforcement Skills

Skills like viewmodel-flags-usage mandate critical rules such as checking feature flags only during ViewModel initialization. This prevents repetitive flag checks in composables and potential bugs.

7Dynamic Context Management

While AGENTS.md is passive reference, skill files provide proactive instructions. Details like using the safeExecuteNotNull Apollo wrapper or analytics event logging are automatically applied.

8Maintaining Test Standards

The AI now uses MockK instead of Mockito, Turbine instead of LiveData for tests. Test tags and @VisibleForTesting annotations are added automatically, eliminating ViewModel dependency issues in UI tests.

96-Month Transformation

PR review times decreased by 40%. New engineers learned coding standards in 2 days instead of 2 weeks. 85% of AI-generated code gets merged on first attempt, showing significant quality improvement.

10Scalable Knowledge Management

This system preserves institutional memory as teams grow. The 'how do we do this?' question from new engineers became obsolete. The AI now writes not just Kotlin, but Medium's Kotlin - a revolutionary approach for large codebases.

Original article: Medium Engineering — AI ile Android Kod Yazma Rehberi: Takım Standartlarını Öğretmek