-
Notifications
You must be signed in to change notification settings - Fork 53
en Project Structure
This document explains the organization and architecture of the WordZero codebase, helping developers understand the project layout and contribute effectively.
wordZero/
├── pkg/ # Core library packages
│ ├── document/ # Document manipulation core
│ ├── style/ # Style system
│ └── markdown/ # Markdown conversion utilities
├── examples/ # Example applications and demos
│ ├── basic/ # Basic usage examples
│ ├── advanced_features/ # Advanced feature demonstrations
│ ├── table/ # Table manipulation examples
│ ├── style_demo/ # Style system showcase
│ ├── formatting/ # Text formatting examples
│ ├── template_demo/ # Template system usage
│ ├── markdown_demo/ # Markdown conversion examples
│ └── page_settings/ # Page configuration examples
├── test/ # Test files and test data
│ ├── output/ # Test output files
│ └── fixtures/ # Test fixtures and sample data
├── benchmark/ # Performance benchmarks
│ ├── golang/ # Go benchmarks
│ ├── javascript/ # JavaScript comparison benchmarks
│ ├── python/ # Python comparison benchmarks
│ └── results/ # Benchmark results and charts
├── docs/ # Additional documentation
├── wordZero.wiki/ # Wiki documentation (this documentation)
├── go.mod # Go module definition
├── go.sum # Go module checksums
├── README.md # Project overview
├── README_zh.md # Chinese README
├── CHANGELOG.md # Version history
├── LICENSE # Project license
└── debug.go # Debug utilities
The document package is the core of WordZero, providing the main document manipulation functionality.
-
document.go- Main document structure and operations -
paragraph.go- Paragraph handling and text operations -
table.go- Table creation and manipulation -
styles.go- Style application and management -
page.go- Page settings and layout -
properties.go- Document properties and metadata -
advanced.go- Advanced features (TOC, footnotes, etc.) -
iterator.go- Table cell iterator implementation -
format.go- Text formatting structures and methods
- Document creation, loading, and saving
- Paragraph and text manipulation
- Table operations and cell management
- Style application and formatting
- Page layout and settings
- Advanced features implementation
The style package defines the style system and predefined styles.
-
styles.go- Style definitions and constants -
manager.go- Style management and application -
custom.go- Custom style creation and modification
- Predefined style definitions (18 built-in styles)
- Style inheritance and management
- Custom style creation
- Style validation and application
The markdown package provides bidirectional conversion between Markdown and Word formats.
-
parser.go- Markdown parsing and conversion -
converter.go- Word to Markdown conversion -
formatter.go- Format preservation and mapping
- Markdown to Word document conversion
- Word document to Markdown conversion
- Format mapping and preservation
- Content structure translation
WordZero uses the builder pattern for document construction:
// Document builder pattern
doc := document.New()
.SetTitle("My Document")
.SetPageSize(document.PageSizeA4)
.AddParagraph("Content")
.Save("document.docx")Many operations support method chaining for better readability:
para := doc.AddParagraph("Text")
.SetStyle(style.StyleHeading1)
.SetAlignment(document.AlignmentCenter)Table operations use iterators for efficient cell traversal:
iterator := table.GetCellIterator()
for iterator.HasNext() {
cell := iterator.Next()
// Process cell
}Document and component creation uses factory methods:
doc := document.New() // Document factory
table := doc.AddTable(3, 3) // Table factory
para := doc.AddParagraph("text") // Paragraph factorytest/
├── unit/ # Unit tests
│ ├── document_test.go # Document operations tests
│ ├── table_test.go # Table functionality tests
│ ├── style_test.go # Style system tests
│ └── format_test.go # Formatting tests
├── integration/ # Integration tests
│ ├── complete_test.go # End-to-end workflows
│ └── performance_test.go # Performance tests
├── fixtures/ # Test data and samples
│ ├── sample.docx # Sample Word documents
│ ├── test_data.json # Test data sets
│ └── expected/ # Expected output files
└── output/ # Test output directory
-
File Naming: Tests follow
*_test.goconvention -
Function Naming: Test functions start with
Test -
Benchmark Naming: Benchmark functions start with
Benchmark -
Test Data: Stored in
fixtures/directory - Output Isolation: Each test uses unique output files
The examples are organized by complexity and feature focus:
- Simple document creation
- Basic text and paragraph operations
- Fundamental style application
- Complex document structures
- Advanced features usage
- Multiple feature integration
-
table/- Table operations and styling -
style_demo/- Style system showcase -
formatting/- Text formatting options -
template_demo/- Template-based generation -
markdown_demo/- Format conversion -
page_settings/- Page configuration
- Self-contained: Each example is a complete, runnable program
-
Output Directory: All examples save to
examples/output/ - Error Handling: Comprehensive error checking and logging
- Documentation: Inline comments explaining key concepts
- Progressive Complexity: Examples build on previous concepts
- Package Selection: Determine the appropriate package
- Interface Design: Design public APIs first
- Implementation: Implement core functionality
- Testing: Write comprehensive tests
- Examples: Create usage examples
- Documentation: Update relevant documentation
- Single Responsibility: Each package has a clear, focused purpose
- Minimal Dependencies: Avoid unnecessary external dependencies
- Consistent APIs: Follow established patterns across packages
- Error Handling: Use standard Go error handling patterns
- Documentation: Comprehensive godoc comments
The documentation is organized in a logical learning progression:
- Getting Started (01-05): Basic concepts and operations
- Core Features (06-08): Main functionality areas
- Advanced Topics (09-12): Complex features and best practices
- Reference (13-16): Detailed specifications and analysis
- Tutorials: Step-by-step learning guides
- How-to Guides: Problem-solving focused
- Reference: Comprehensive API documentation
- Explanation: Conceptual background and design decisions
- Go 1.19 or higher
- Git for version control
- Make (optional, for build automation)
# Run tests
go test ./...
# Run specific package tests
go test ./pkg/document
# Run benchmarks
go test -bench=. ./...
# Generate documentation
go doc -all ./pkg/document
# Build examples
go build ./examples/basic
# Run linting (if configured)
golangci-lint run-
Formatting: Use
gofmtfor consistent formatting -
Linting: Follow
golangci-lintrecommendations - Testing: Maintain >80% test coverage
- Documentation: Write comprehensive godoc comments
- Performance: Regular benchmark testing
- Fork and Branch: Create feature branches from main
- Tests Required: All new code must include tests
- Documentation: Update relevant documentation
- Examples: Provide usage examples for new features
- Backwards Compatibility: Maintain API compatibility
- Accuracy: Ensure technical accuracy
- Clarity: Write clear, beginner-friendly explanations
- Examples: Include practical code examples
- Completeness: Cover all aspects of features
- Maintenance: Keep documentation current with code changes
- Standard Library Only: WordZero uses only Go standard library
- No External Dependencies: Minimizes dependency management issues
- Self-contained: Complete functionality without external packages
pkg/document ← pkg/style # Document uses style definitions
pkg/document ← pkg/markdown # Markdown conversion uses document
examples/* ← pkg/* # Examples use all packages
-
Files:
snake_case.go -
Packages:
lowercase -
Types:
PascalCase -
Functions:
PascalCase(exported),camelCase(unexported) -
Constants:
PascalCaseorUPPER_CASE -
Variables:
camelCase
-
Main functionality:
package_name.go -
Types and structures:
types.go -
Constants and enums:
constants.go -
Utilities:
utils.go -
Tests:
*_test.go
This structure provides a solid foundation for understanding, using, and contributing to the WordZero project. The modular design ensures maintainability while the comprehensive examples and documentation support both learning and production use.