Development
Architecture, build instructions, and contribution guidelines.
Understanding-oriented guides for developers contributing to ztick.
Contents
Architecture — Hexagonal layer structure and design rationale
- Layer separation (Domain, Application, Infrastructure, Interfaces)
- Dependency inversion and testability
- Testing strategy for each layer
Building — Compiling, testing, and packaging
- Debug and release builds
- Running unit and functional tests
- Performance profiling
- Release checklist
Contributing — Code style and submission guidelines
- Branch and PR workflow
- Zig conventions
- Documentation standards
- Types of contributions
Quick Start for Developers
1. Set Up
git clone https://github.com/pocky/ztick.git
cd ztick
zig build test # Verify environment
2. Understand the Code
Start with Architecture:
- 4-layer hexagonal design
- Domain first (pure types), then outward
- Co-located tests per layer
3. Make Changes
Follow these rules:
- Keep dependencies flowing inward
- Write tests alongside code
- Run
make fmtbefore committing - Use descriptive commit messages
4. Test
zig build test # All tests
zig build test --test-filter domain # Layer-specific
make lint # Format check
5. Submit PR
- Push to a feature branch
- Open PR with clear description
- Address review feedback
- Merge once approved
Architecture Decisions
Key decisions are documented in ADRs:
| Decision | Location | Rationale |
|---|---|---|
| Hexagonal architecture | Architecture | Testability, dependency control |
| Zig language choice | ADR 0002 | Fast compile, explicit memory, no runtime |
| Binary persistence format | Persistence | Performance, durability |
| Thread model | Architecture | 3 threads: Controller, Database, Processor |
Key Files
src/
├── domain/ # Pure types (Job, Rule, Runner, etc.)
├── application/ # Scheduler logic (storage, query handling)
├── infrastructure/ # Adapters (TCP, shell, persistence, protocol)
├── interfaces/ # CLI, config loading, component wiring
└── functional_tests.zig # End-to-end tests
build.zig # Build configuration
build.zig.zon # Version and dependencies
Development Workflow
Daily Work
- Create a feature branch:
git checkout -b feature/my-feature - Edit code in
src/ - Run tests:
zig build test - Format:
make fmt - Commit:
git commit -m "feat: description" - Push and open PR
Testing Locally
# Run all tests
zig build test
# Run specific layer tests
zig build test --test-filter domain
# Functional/integration tests
zig build test-functional
# Format check
make lint
Debugging
# Add debug logging
std.debug.print("value: {}\n", .{value});
# Run with debug build
zig build
./zig-out/bin/ztick --config debug.toml
# Use a debugger
gdb ./zig-out/bin/ztick
Code Quality Standards
- Coverage: 80%+ overall (95%+ domain)
- Formatting: 100%
zig fmtcompliant - Tests: All layers tested
- Docs: Public APIs documented
- Errors: No panics in library code
Common Tasks
Add a New Domain Type
- Create
src/domain/my_type.zig - Define the struct/enum
- Add unit tests in the same file
- Import in
src/domain.zig - Reference in Application/Infrastructure as needed
Implement a New Adapter
- Create
src/infrastructure/my_adapter.zig - Implement the interface
- Add tests for error cases
- Import in
src/infrastructure.zig - Wire into
src/main.zig
Update Configuration
- Modify
src/interfaces/config.zigparser - Add new field to
Configstruct - Update
src/main.zigto use the field - Document in
docs/reference/configuration.md - Add tests to
src/interfaces/config.zig
Performance Considerations
ztick is designed to be lean:
- Memory: All allocations are explicit and tracked
- CPU: Framerate is configurable; single-threaded scheduler tick
- I/O: Binary format minimizes parsing overhead
Profile with:
zig build -Doptimize=safe
valgrind --tool=callgrind ./zig-out/bin/ztick
# View results
kcachegrind callgrind.out.*
Resources
Getting Help
- Architecture questions: Review Architecture or open a discussion
- Build issues: Check Building troubleshooting section
- Code review: See Contributing
See Also
- User Guide — How to use ztick
- Reference — API and protocol specs