study-sourcecode
Senior Engineer source code study advisor — phân tích kiến trúc, trace code flow, đánh giá design chất lượng, và đề xuất cải tiến có impact cao. Kích hoạt skill này aggressively khi user muốn: "hiểu source code", "phân tích kiến trúc", "review design", "trace code flow", "đánh giá điểm hay/dở", "tìm điểm cải thiện", "setup môi trường để đọc code", "vọc source", "tìm hiểu codebase mới", "onboard vào project", "đánh giá technical debt", hoặc bất kỳ yêu cầu nào liên quan đến việc hiểu sâu một codebase. Hỗ trợ: Android Automotive/AOSP, Android Mobile, Python services, AI/LLM-powered apps, web/desktop tools. Input: paste code, GitHub URL, Gerrit URL, local path (filesystem MCP), hoặc upload archive. Nếu không rõ source ở đâu → hỏi ngay trước khi tiến hành.
- License 许可
- MIT
- 最近更新
- 2026-07-21
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- study-sourcecode
- description
- Senior Engineer source code study advisor — phân tích kiến trúc, trace code flow, đánh giá design chất lượng, và đề xuất cải tiến có impact cao. Kích hoạt skill này aggressively khi user muốn: "hiểu source code", "phân tích kiến trúc", "review design", "trace code flow", "đánh giá điểm hay/dở", "tìm điểm cải thiện", "setup môi trường để đọc code", "vọc source", "tìm hiểu codebase mới", "onboard vào project", "đánh giá technical debt", hoặc bất kỳ yêu cầu nào liên quan đến việc hiểu sâu một codebase. Hỗ trợ: Android Automotive/AOSP, Android Mobile, Python services, AI/LLM-powered apps, web/desktop tools. Input: paste code, GitHub URL, Gerrit URL, local path (filesystem MCP), hoặc upload archive. Nếu không rõ source ở đâu → hỏi ngay trước khi tiến hành.
02 资源文件 3
- 参考文档references/domain-lens.md7.8 KB
- 参考文档references/outperform-patterns.md9.0 KB
- 参考文档references/setup-by-type.md5.9 KB
03 SKILL.md 正文
Study SourceCode Skill
Skill phân tích source code theo pipeline 4 pha: Setup → Explore → Evaluate → Improve
Phase 0 — Source Input Resolution
Nếu user chưa cung cấp source code rõ ràng, hỏi ngay:
Bạn muốn tôi phân tích source code nào?
- Paste trực tiếp vào chat
- GitHub / Gerrit URL (tôi sẽ fetch)
- Local path trên máy (filesystem MCP)
- Upload file / archive (.zip, .tar.gz)
Xác định loại input rồi mới tiến hành.
| Input type | Cách xử lý |
|---|---|
| Paste / code snippet | Đọc trực tiếp từ context |
| GitHub URL | web_fetch → raw files; nếu repo lớn → fetch key files theo file tree |
| Gerrit URL | Fetch patch / file tree qua Gerrit REST API |
| Local path | Dùng view tool để duyệt filesystem |
| Archive upload | Giải nén, scan cấu trúc, đọc key files |
Phase 1 — SETUP (Cài cắm môi trường đọc code)
Mục tiêu: Định hướng nhanh — biết đây là project gì, build bằng gì, chạy được không.
1.1 Project Fingerprinting
Scan các file sau để nhận diện project type:
/ (root)
├── build.gradle / build.gradle.kts → Android / Kotlin
├── Android.mk / Android.bp → AOSP / AAOS
├── CMakeLists.txt → C/C++ native
├── requirements.txt / pyproject.toml → Python
├── package.json → Node.js / web frontend
├── Cargo.toml → Rust
├── MANIFEST / *.podspec → iOS / macOS
└── Makefile / Dockerfile → Generic build / containerized
Output Phase 1.1:
Project Type : [Android Automotive / AOSP / Python / AI App / ...]
Language(s) : [Java, Kotlin, C++, Python, ...]
Build System : [Gradle, Soong/Make, CMake, pip, ...]
Min SDK / API : [nếu Android]
Key Entry Points: [Application.java, MainActivity, Service, main.py, ...]
1.2 Environment Setup Checklist
Tùy project type, đưa ra checklist setup môi trường đọc/chạy code:
→ Xem file references/setup-by-type.md theo domain phù hợp.
1.3 Dependency Map
Liệt kê dependencies quan trọng:
- External libs (version, purpose)
- Internal modules / subprojects
- System services / HAL (nếu AAOS)
- External APIs / LLM endpoints (nếu AI app)
Phase 2 — EXPLORE (Khám phá kiến trúc & code flow)
Mục tiêu: Vẽ được mental model — ai gọi ai, data đi đâu, luồng chính là gì.
2.1 Architecture Overview (HLD-level)
Phân tích theo layers:
[Presentation Layer] → UI, Activity, Fragment, Composable, CLI
[Domain / Business] → ViewModel, UseCase, Manager, Controller
[Data / Service] → Repository, Service, HAL, API Client
[Infrastructure] → DB, Cache, IPC, Network, Hardware
Với AAOS/AOSP thêm:
[App Layer] → CarApp, System App
[Framework Layer] → CarService, SystemServer
[HAL Layer] → Vehicle HAL, AIDL interface
[Kernel / HW] → Kernel drivers, ECU
Với AI/LLM App thêm:
[Orchestration Layer] → Agent, Chain, Router
[Model Layer] → LLM API client, prompt templates
[Tool Layer] → MCP servers, function calls, plugins
[Memory Layer] → Vector DB, conversation history, cache
Output: Text diagram (ASCII) + mô tả từng layer 2-3 dòng.
2.2 Critical Path Trace
Trace luồng chính end-to-end (ví dụ: user action → response):
Format:
[Trigger] → ClassA.methodX()
→ ClassB.methodY() // note: async via Handler / coroutine
→ ServiceC.call() // Binder IPC / REST / gRPC
→ [Result / Side Effect]
Ưu tiên trace:
- Happy path (luồng thành công)
- Error path (exception, timeout, fallback)
- Lifecycle hooks (onCreate, onBind, onDestroy, onResume…)
2.3 Data Flow Analysis
Input source → Transform → Storage → Output sink
Với mỗi data entity quan trọng:
- Ai tạo ra? Ai consume?
- Được serialize/deserialize thế nào?
- Thread nào xử lý? (UI, IO, Binder, Worker)
- Lifecycle của data? (in-memory, persisted, cached)
2.4 Key Patterns Identified
Liệt kê design patterns thực sự thấy trong code:
- Architecture pattern: MVVM, MVI, Clean Arch, Layered...
- Concurrency: Coroutines, RxJava, Handler/Looper, ThreadPool...
- IPC: Binder, AIDL, Messenger, ContentProvider, gRPC...
- DI: Hilt, Dagger, Koin, manual injection...
- Reactive: Flow, LiveData, EventBus...
Phase 3 — EVALUATE (Đánh giá chất lượng)
Mục tiêu: Điểm mạnh, điểm yếu, technical debt — có dẫn chứng code cụ thể.
3.1 Score Card
Đánh giá theo thang 1–5 với nhận xét ngắn + ví dụ code:
| Dimension | Score | Evidence | Note |
|---|---|---|---|
| Architecture clarity | /5 | file:line | |
| Separation of concerns | /5 | ||
| Thread safety | /5 | ||
| Error handling | /5 | ||
| Testability | /5 | ||
| Performance awareness | /5 | ||
| Readability / naming | /5 | ||
| API design (nếu có) | /5 | ||
| Security basics | /5 | ||
| TOTAL | /45 |
3.2 Điểm HAY — đáng học
Format:
✅ [Tên pattern / kỹ thuật]
Code: [snippet hoặc file:line reference]
Tại sao hay: [1-2 câu]
Học được gì: [áp dụng vào project khác thế nào]
3.3 Điểm DỞ — cần biết
Format:
⚠️ [Vấn đề] Severity: [HIGH/MED/LOW]
Code: [snippet hoặc file:line]
Tại sao dở: [root cause]
Rủi ro: [bug, crash, perf, security, maintainability]
Severity guide:
- HIGH: Có thể crash, data loss, race condition, security hole
- MED: Technical debt nặng, khó test, khó scale
- LOW: Code smell, naming issue, missing comments
3.4 Technical Debt Summary
Debt Category | Count | Estimated Fix Effort
-----------------|-------|---------------------
Missing tests | |
Hardcoded values | |
God classes | |
Missing null check| |
Blocking IO on UI| |
Deprecated API | |
Phase 4 — IMPROVE (Đề xuất cải tiến có impact)
Mục tiêu: Không chỉ nói "cần cải thiện" — mà đưa ra cụ thể: làm gì, tại sao, impact bao nhiêu.
4.1 Quick Wins (< 1 ngày)
Những thứ fix ngay, low-risk, high-value:
- Thêm null check, close resource
- Rename confusing variable
- Extract magic number thành constant
- Add missing
@GuardedBy/@MainThreadannotation
4.2 Improvement Roadmap
Format từng item:
🚀 [Tên cải tiến]
Category : [Architecture / Performance / Safety / Testability / Feature]
Effort : [S=<1d / M=1-3d / L=3-7d / XL=>1w]
Impact : [HIGH / MED / LOW]
What to do : [mô tả kỹ thuật cụ thể]
Code sketch : [pseudocode hoặc diff snippet nếu hữu ích]
Risk : [rủi ro nếu làm, rủi ro nếu không làm]
4.3 HIGHLIGHT — Nếu làm sẽ OUTPERFORM
Phần này quan trọng nhất. Chỉ những cải tiến thực sự tạo ra competitive advantage hoặc wow factor:
⭐ OUTPERFORM: [Tên cải tiến]
Tại sao sẽ nổi bật:
- [So với codebase hiện tại: X → Y]
- [So với industry standard / competitors]
Về MẶT TÍNH NĂNG:
[Tính năng mới hoặc UX improvement cụ thể]
Về MẶT KIẾN TRÚC:
[Pattern nào nên áp dụng, tại sao scalable hơn]
Về MẶT SOURCE CODE:
[Code quality gap và cách bridge]
Implementation sketch:
[Key interfaces, classes, data flow cần thay đổi]
Expected outcome:
- Performance: [X ms → Y ms / X MB → Y MB]
- Maintainability: [team velocity impact]
- Reliability: [error rate, crash rate]
- Testability: [coverage estimate]
4.4 Prioritized Backlog
| Priority | Item | Effort | Impact | Owner hint |
|---|---|---|---|---|
| P0 | ||||
| P1 | ||||
| P2 | ||||
| P3 (nice-to-have) |
Output Defaults
- Luôn trả lời tiếng Việt, English chỉ cho code/API/terms
- Mỗi phase kết thúc bằng 1 câu tóm tắt + hỏi "Đào sâu hơn vào phần nào không?"
- Nếu codebase lớn: ưu tiên phân tích entry points + critical paths trước
- Nếu user chỉ muốn 1 phase: thực hiện phase đó, không cần chạy full pipeline
- Dùng
view/bash_toolđể đọc file khi có filesystem access - Dùng
web_fetchđể lấy GitHub/Gerrit raw content
Domain-Specific Lens
Khi phân tích, apply lens phù hợp theo domain:
→ Chi tiết trong references/domain-lens.md
Quick reference:
- AAOS/AOSP: Thread safety + Binder + CarService lifecycle + CarUxRestrictions
- Android Mobile: Lifecycle leaks + coroutine scope + config changes
- Python service: Blocking I/O + async correctness + dependency injection
- AI/LLM App: Token cost + latency + prompt injection + fallback strategy + context management
Reference Files
| File | Khi nào đọc |
|---|---|
references/setup-by-type.md |
Phase 1.2 — setup môi trường theo domain |
references/domain-lens.md |
Phase 2-4 — áp dụng lens phù hợp domain |
references/outperform-patterns.md |
Phase 4.3 — patterns tạo competitive advantage |
04 同仓库更多 Skills
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
writing-shape
Writing, exploit — shape raw material into an article, paragraph by paragraph.
writing-plans
Use when you have a spec or requirements for a multi-step task, before touching code
writing-great-skills
Reference for writing and editing skills well — the vocabulary and principles that make a skill predictable.
writing-fragments
Writing, explore — mine raw fragments, no structure yet.
writing-beats
Writing, exploit — assemble raw material into a journey of beats, grounding each term before a beat leans on it.