Design Document Generator
Automatically generate HarmonyOS/OpenHarmony design documents including architecture design documents and functional design documents based on PRD documents.
Quick Start
Provide PRD document path:
Generate design documents based on {PRD Document}
Specify output type:
Generate architecture design document and functional design document based on {PRD Document Path}
OpenHarmony Code Analysis
Before generating design documents, it is necessary to analyze the existing code structure of OpenHarmony to ensure that the new design is compatible with the current architecture.
Analysis Steps
1. Discover Code Structure
Use Glob tool to quickly discover directory structure and key files:
| File Type | Search Pattern | Description |
|---|
| Configuration Files | , , | Component definition, build configuration |
| Document Files | , | Module description, usage guide |
| Interface Files | , | IDL interfaces, C++ header files |
| Metadata Files | , | GN build scripts |
| SA Configuration | , | SA configuration files |
2. Search for Key Information
Use Grep tool to search keywords and extract component information:
| Search Target | Search Keywords | Extracted Information |
|---|
| SA ID | | Assigned SA IDs |
| Subsystem | | Subsystem organization |
| Dependencies | | Component dependencies |
| Interface Definition | | IDL interfaces |
| Service Class | | Service implementation classes |
| Provider | | SA Provider classes |
3. Read Key Configurations
Use Read tool to read key configuration files:
- : Component definition and subsystem affiliation
- : Build dependencies and compilation options
- : SA configuration and startup parameters
- : Module description and usage guide
- : Interface definitions and data structures
4. Intelligent Exploration
Use Task tool to start Explore agent for multi-round exploration:
- Discover directory structure of related modules
- Find implementation references for similar functions
- Extract interface design and data structures
Naming Pattern Inference
Infer functions through file and directory naming:
| Naming Pattern | Inferred Function | Example |
|---|
| Service implementation | |
| SA Provider implementation | disk_manager_provider.cpp
|
| Event listening interface | |
| Data type definition | |
| External API layer | , |
| Internal API layer | |
| SA configuration files | |
| Test code | |
| Test Mock | |
Analysis Output
After code analysis, generate:
- Existing SA List: Assigned SA IDs and service names
- Subsystem Organization: Hierarchy of subsystems and components
- Dependency Graph: Dependencies between components
- Interface Reference: Interface design references for similar functions
- Code Style Reference: Naming conventions, directory structure, etc.
Competitor Solution Analysis Chapter Requirements
Chapter 2 of the architecture design document must be Competitor Solution Analysis, which should be placed after Requirement Background and before HarmonyOS Architecture Analysis.
Chapter Structure
2. Competitor Solution Analysis
2.1 Competitor Identification
- List main competitors (at least 2-3)
- Explain reasons for competitor selection
- Competitor types: similar products, technical solutions, industry standards
2.2 Competitor Technical Solution Analysis
For each competitor, analyze:
- Core technical architecture
- Key technical components
- Communication mechanism
- Data flow
- Key flowcharts, sequence diagrams
2.3 Technical Comparison Table
| Comparison Item | Our Solution | Competitor A | Competitor B |
|---|
| Architecture Pattern | | | |
| Core Technology | | | |
| Communication Mechanism | | | |
| Process Model | | | |
| Security Mechanism | | | |
| Cross-language Support | | | |
2.4 Differentiated Design
- Innovations of our solution compared to competitors
- Pain points of competitors solved by our solution
- Technical advantage explanation
- Reference and improvement
Output Requirements
- Present competitor technical solutions using 4+1 view, flowcharts, sequence diagrams
- Include detailed analysis of at least 2 competitors
- Must have a technical comparison table
- Must clarify differentiated design points
Chapter Order Verification
Verify chapter order when generating architecture design documents:
Standard order: Requirement Background → Competitor Solution Analysis → HarmonyOS Architecture Analysis → Architecture Design...
Verification Rules:
- ✅ Chapter 1 must be "Requirement Background"
- ✅ Chapter 2 must be "Competitor Solution Analysis" (Required)
- ✅ Competitor Solution Analysis must be after Requirement Background
- ✅ Competitor Solution Analysis must be before Architecture Design
- ❌ If the order is wrong, prompt the user to adjust
Verification Logic:
- Extract all level 1 headings (starting with #)
- Verify if Chapter 1 is "Requirement Background"
- Verify if Chapter 2 is "Competitor Solution Analysis" or "Competitor Analysis"
- If Chapter 2 is missing or the order is wrong, return an error prompt
Generated Content
Architecture Design Document (architecture_vX.md)
Includes the following standard chapters (in order):
| Chapter | Content |
|---|
| 1. Requirement Background | Project background, business requirements, technical challenges |
| 2. Competitor Solution Analysis | Competitor identification, technical solution comparison, differentiated design (Required) |
| 3. HarmonyOS Architecture Analysis | Current architecture, reusable components |
| 4. Architecture Design | Overall architecture, technology selection, module division |
| 5. Data Model | Core data structures, database design |
| 6. Interface Design | IDL interfaces, NAPI interfaces |
| 7. Deployment Architecture | Process model, startup dependencies |
| 8. Security, Resilience, Privacy and Reliability Analysis | Security design, resilience design, privacy protection, reliability |
| 9. Requirement Decomposition and Code Volume Evaluation | Requirement splitting, code volume estimation |
| 10. Appendix | Error codes, performance indicators |
Functional Design Document (functiondesign_vX.md)
Includes the following standard chapters:
| Chapter | Content |
|---|
| 1. Overview | Document purpose, module list |
| 2. Module Definition | Responsibilities of each module, input/output, dependencies |
| 3. Interface Definition | IDL interfaces, callback interfaces |
| 4. State Machine Design | State enumeration, transition table, transition diagram |
| 5. Process Design | Main flowcharts, sequence diagrams, exception handling |
| 6. Error Handling | Error code definition, handling strategies |
Architecture Layers
┌─────────────────────────────────────────┐
│ Application Layer │
│ Settings App | File Manager | Disk Tool │
└─────────────────────────────────────────┘
↓ NAPI/IPC
┌─────────────────────────────────────────┐
│ Service Layer │
│ DiskManagement SA (5001) │
│ DiskInfo | Format | Repair | Status │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ Tools Layer │
│ FormatTool | FsckTool | PartedTool │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ System Layer │
│ Storage SA | OsAccount SA | HiSysEvent │
└─────────────────────────────────────────┘
SA Division Rules
| SA Name | SA ID Range | Example |
|---|
| Basic Services | 1000-1999 | OsAccount (4101) |
| Data Storage | 4000-4999 | |
| File Management | 5000-5999 | DiskManagement (5001), StorageManager (5003) |
State Machine Design
Use V11.0 state machine specification:
mermaid
stateDiagram-v2
[*] --> UNKNOWN
UNKNOWN --> NORMAL: Detection successful
UNKNOWN --> ABNORMAL: Detection failed
NORMAL --> CHECKING: Start detection
CHECKING --> NORMAL: Detection completed
CHECKING --> REPAIRING: Need repair
CHECKING --> ABNORMAL: Detection failed
REPAIRING --> NORMAL: Repair successful
REPAIRING --> ABNORMAL: Repair failed
ABNORMAL --> CHECKING: Retest
Sequence Diagram Example
mermaid
sequenceDiagram
participant App as Application
participant Kit as DiskManagementKit
participant SA as DiskManagement SA
participant Tool as FormatTool
App->>Kit: formatDisk(diskId, fsType)
Kit->>SA: format(diskId, fsType)
SA->>SA: Permission verification
SA->>SA: State verification
SA->>Tool: executeFormat()
Tool-->>SA: onProgress(percent)
SA-->>Kit: onFormatProgress()
Kit-->>App: progress callback
Tool-->>SA: result
SA-->>Kit: result
Kit-->>App: format result
Reference Documents
- Architecture Design Template: references/architecture_template.md
- Functional Design Template: references/functional_template.md
- State Machine Specification: references/state_machine_spec.md
- Interface Design Guide: references/interface_guide.md
Mapping with PRD
| PRD Chapter | Design Document Chapter | Mapping Rules |
|---|
| Chapter 4: Competitor Analysis | Chapter 2: Competitor Solution Analysis | Expand PRD's competitor analysis into technical solution comparison |
| Chapter 2: Requirement Background | Chapter 1: Requirement Background | Direct mapping |
| Chapter 5: Requirement Description | Chapter 4: Architecture Design | Convert requirements into architecture design |
| KEP Definition | Module Architecture + Interface Design | Each KEP corresponds to at least one service module |
| User Story | Functional Specification | Convert user scenarios into functional processes |
| Acceptance Criteria | Interface Return Value Definition | Convert acceptance conditions into interface contracts |
| Non-functional Requirements | Technology Selection + Performance Indicators | Technical constraints are reflected in architecture design |
Dependent Service Mapping
| Service in Design Document | Corresponding OpenHarmony SA | Description |
|---|
| Permission Verification Service | OsAccount SA (4101) | Reuse account system capabilities |
| Storage Service | StorageManager SA (5003) | External storage management |
| Encryption Service | Crypto SA | Disk encryption capabilities |
Output Directory Structure
output/
├── architecture_v1.md # Architecture design document
├── functiondesign_v1.md # Functional design document
├── code_paths_v1.md # Code path document
└── diagrams/ # Generated diagram files
├── architecture.png
├── state_machine.png
└── sequence.png
Usage Examples
Generate complete design documents:
Generate architecture and functional design documents based on {PRD Document}
Generate only architecture design:
Generate only architecture design document based on {PRD Document}
Specify SA ID:
Generate design documents using {SA_ID} as SA ID, based on {PRD Document}
Specify product name and version:
Generate design documents for {Product Name} {Version}, document version {Document Version}, based on {PRD Document}
Specify output directory:
Generate design documents to ./design_docs directory, based on {PRD Document}
Naming Conventions
| Document Type | Naming Format | Example |
|---|
| Architecture Design | | architecture_v1.md |
| Functional Design | functiondesign_v{major}.md
| functiondesign_v1.md |
| Code Path | | code_paths_v1.md |
| PRD Reference | | prd_v17.md |
Version Management Rules
| Version Change | Update Content |
|---|
| PRD version change | Increment design document version synchronously |
| Architecture adjustment | Add .1 sub-version (V1.0 → V1.1) |
| New function added | Increment minor version number (V1.0 → V2.0) |
Chart Format
Use Mermaid syntax to draw charts. Supported chart types:
- Flowchart: or
- State Diagram:
- Sequence Diagram:
- Class Diagram:
- Component Diagram:
Error Handling
| Error Type | Handling Method |
|---|
| PRD file does not exist | Prompt for wrong file path |
| PRD lacks competitor analysis | Prompt to supplement Chapter 4 of PRD with competitor analysis, or generate based on existing information |
| Architecture document lacks Chapter 2: Competitor Solution Analysis | Return error: Chapter 2 must be Competitor Solution Analysis |
| Chapter order is wrong | Prompt: Chapter 2 must be Competitor Solution Analysis, placed after Requirement Background |
| KEP parsing failed | List missing KEP definitions |
| Format does not meet specifications | Generate according to default template |
| Output directory is not writable | Prompt for permission issues |