refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조

에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Antigravity Agent
2026-07-11 11:05:56 +09:00
parent 6549ead309
commit c24165b8bc
6193 changed files with 1717 additions and 31 deletions
@@ -0,0 +1,125 @@
---
id: android-room-patterns
title: Android Room — 안전한 SQLite ORM
category: Coding
status: draft
source_trust_level: B
verification_status: conceptual
created_at: 2026-05-09
updated_at: 2026-05-09
tags: [android, room, sqlite, persistence, vibe-coding]
tech_stack: { language: "Kotlin / Room", applicable_to: ["Android"] }
applied_in: []
aliases: [Room, DAO, Entity, Migration, Flow]
---
# Android Room
> 컴파일 타임 SQL 검증 + Flow 기반 reactive 쿼리. **Entity / DAO / Database** 3종. Migration 제대로 안 하면 사용자 데이터 손실 사고.
## 📖 핵심 개념
- Entity: @Entity 클래스 = 테이블.
- DAO: @Dao 인터페이스 = 쿼리 모음.
- Database: @Database — abstract class.
- Coroutines + Flow 자동 통합.
## 💻 코드 패턴
### Entity + DAO + DB
```kotlin
@Entity(tableName = "users", indices = [Index(value = ["email"], unique = true)])
data class UserEntity(
@PrimaryKey val id: String,
val email: String,
val name: String,
val createdAt: Long,
)
@Dao
interface UserDao {
@Query("SELECT * FROM users WHERE id = :id")
suspend fun findById(id: String): UserEntity?
@Query("SELECT * FROM users ORDER BY created_at DESC LIMIT :limit")
fun observeRecent(limit: Int): Flow<List<UserEntity>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun upsert(user: UserEntity)
@Update
suspend fun update(user: UserEntity)
@Query("DELETE FROM users WHERE id = :id")
suspend fun delete(id: String)
}
@Database(entities = [UserEntity::class], version = 2, exportSchema = true)
abstract class AppDb : RoomDatabase() {
abstract fun userDao(): UserDao
}
```
### Migration
```kotlin
val MIGRATION_1_2 = object : Migration(1, 2) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE users ADD COLUMN avatar_url TEXT")
}
}
Room.databaseBuilder(ctx, AppDb::class.java, "app.db")
.addMigrations(MIGRATION_1_2)
.build()
```
### Repository + Flow
```kotlin
class UserRepository(private val dao: UserDao, private val api: UserApi) {
fun observeUser(id: String): Flow<User> = dao.observeUser(id).map { it.toDomain() }
suspend fun refresh(id: String) {
val u = api.fetch(id)
dao.upsert(u.toEntity())
}
}
```
### Type converters
```kotlin
class Converters {
@TypeConverter fun fromInstant(t: Instant?): Long? = t?.toEpochMilli()
@TypeConverter fun toInstant(ms: Long?): Instant? = ms?.let { Instant.ofEpochMilli(it) }
}
@Database(entities = [...], version = 1)
@TypeConverters(Converters::class)
abstract class AppDb : RoomDatabase() { ... }
```
## 🤔 의사결정 기준
| 데이터 | 도구 |
|---|---|
| 구조화 데이터, 쿼리 필요 | Room |
| Key-value 설정 | DataStore |
| 큰 파일 | File API |
| 비밀 (token) | EncryptedSharedPreferences / Keystore |
| Sync (서버) | Room + WorkManager |
| 검색 | FTS5 (Room 지원) |
## ❌ 안티패턴
- **main thread 에서 DB 호출**: ANR. suspend / Flow 만.
- **migration 안 쓰고 fallbackToDestructiveMigration**: 사용자 데이터 손실.
- **DB schema 변경 후 version 안 올림**: crash on launch.
- **거대 트랜잭션 + 외부 API 호출 안에**: lock 길어짐.
- **Entity 노출 (UI 까지)**: domain 과 결합. mapper 권장.
- **인덱스 누락**: 큰 테이블 query 느림.
- **exportSchema = false**: schema 변경 검증 못 함. CI 에서 schema diff.
## 🤖 LLM 활용 힌트
- 신규 = Room. 단순 KV = DataStore.
- migration 매 version 마다.
- Flow + collectAsStateWithLifecycle 패턴.
## 🔗 관련 문서
- [[Android_DataStore_Patterns]]
- [[Android_Flow_StateFlow_SharedFlow]]