refactor(arch): extract persistence codec and domain types to proper layers#47
Merged
Conversation
2f5a99d to
c75e67f
Compare
…layers - `CHANGELOG.md`: Document hexagonal architecture refactoring in unreleased section - `CLAUDE.md`: Expand architecture, performance, memory, concurrency, and Zig 0.15.2 idiom sections - `functional_tests`: Add compiled functional test binary - `src/application.zig`: Export persistence_codec and instruments modules - `src/application/execution_client.zig`: Dupe job_identifier at boundary, propagate resolve errors, use testing.allocator in tests - `src/application/instruments.zig`: Extract OTel instruments from infrastructure into application layer - `src/application/job_storage.zig`: Align with PersistencePort interface - `src/application/persistence_codec.zig`: Extract binary encode/decode from infrastructure/persistence/encoder.zig - `src/application/persistence_port.zig`: Introduce vtable-based PersistencePort to decouple scheduler from backends - `src/application/query_handler.zig`: Adapt to generic SchedulerWith backend type - `src/application/rule_storage.zig`: Align with PersistencePort interface - `src/application/scheduler.zig`: Make Scheduler generic via SchedulerWith(comptime Backend: type) - `src/application/token_store.zig`: Minor cleanup and layer alignment - `src/domain.zig`: Export shell_config, telemetry_config, timestamp modules - `src/domain/auth.zig`: Minor cleanup - `src/domain/job.zig`: Minor cleanup - `src/domain/query.zig`: Update query types for generic scheduler - `src/domain/runner.zig`: Minor cleanup - `src/domain/server_stats.zig`: Simplify stats domain type - `src/domain/shell_config.zig`: Promote shell config from infrastructure to domain - `src/domain/telemetry_config.zig`: Promote telemetry config from infrastructure to domain - `src/domain/timestamp.zig`: Extract timestamp parsing into standalone domain module - `src/functional_tests.zig`: Expand functional test coverage - `src/infrastructure/clock.zig`: Adapt to domain config types - `src/infrastructure/http.zig`: Adapt to domain config types and generic scheduler - `src/infrastructure/http/json.zig`: Adapt JSON codec to updated domain types - `src/infrastructure/persistence/backend.zig`: Delegate encode/decode to persistence_codec - `src/infrastructure/persistence/background.zig`: Delegate encode/decode to persistence_codec - `src/infrastructure/persistence/encoder.zig`: Reduce to thin adapter delegating to application/persistence_codec - `src/infrastructure/persistence/logfile.zig`: Minor cleanup - `src/infrastructure/protocol/parser.zig`: Minor cleanup - `src/infrastructure/runner.zig`: Update runner barrel export - `src/infrastructure/runner/awf.zig`: Minor cleanup - `src/infrastructure/runner/direct.zig`: Adapt to subprocess abstraction - `src/infrastructure/runner/shell.zig`: Adapt to subprocess abstraction - `src/infrastructure/runner/subprocess.zig`: Extract shared subprocess execution logic - `src/infrastructure/shell_runner.zig`: Add shell runner adapter using domain shell_config - `src/infrastructure/tcp_server.zig`: Adapt to generic scheduler and domain types - `src/infrastructure/telemetry.zig`: Use application/instruments instead of inline OTel setup - `src/infrastructure/tls_context.zig`: Adapt to domain telemetry_config type - `src/interfaces/cli.zig`: Adapt CLI to domain config types - `src/interfaces/config.zig`: Adapt config parser to emit domain config types - `src/interfaces/dump.zig`: Adapt dump to use application/persistence_codec - `src/main.zig`: Wire SchedulerWith generic and updated thread architecture
c75e67f to
378b727
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
infrastructure/persistence/encoder.zigintoapplication/persistence_codec.zig, enforcing strict hexagonal layer separation by keeping encode/decode logic out of I/O adaptersPersistencePortvtable interface and makeSchedulergeneric viaSchedulerWith(comptime Backend: type)to decouple the application layer from concrete persistence backendstimestamp.zig,shell_config.zig,telemetry_config.zig) and OTel instruments (instruments.zig) to their correct layers; extract shared subprocess spawn logic intorunner/subprocess.zigExecutionClientmemory ownership: dupe job identifier strings at trigger time, propagateresolve()errors instead of silently discarding them, and switch all unit tests tostd.testing.allocatorfor leak detectionChanges
Application Layer
src/application.zig: Export newpersistence_codecandinstrumentsmodulessrc/application/persistence_codec.zig: New — full encode/decode for all entry types (job, rule, removals, all 6 runner variants) with errdefer-safe allocation and comprehensive unit testssrc/application/persistence_port.zig: New — vtable-basedPersistencePortinterface decouplingSchedulerfrom concrete backendsrc/application/instruments.zig: New — OTelInstrumentsstruct promoted from infrastructure into application layersrc/application/execution_client.zig: Dupejob_identifierattrigger(), makeresolve()return!void, fixpull_resultsto free owned identifiers, switch tests tostd.testing.allocatorsrc/application/job_storage.zig: Replace linear scan + sort inget_to_executewith priority-queue peek/remove; addcount()andcount_by_status()accessors; switch tests tostd.testing.allocatorsrc/application/query_handler.zig: Update to use new persistence port and codec interfacessrc/application/rule_storage.zig: Minor updates for layer alignmentsrc/application/scheduler.zig: Make generic viaSchedulerWith(comptime Backend: type); wire through new persistence portsrc/application/token_store.zig: Layer alignment cleanupDomain Layer
src/domain.zig: Export new domain modulessrc/domain/shell_config.zig: New —ShellConfigtype promoted from infrastructuresrc/domain/telemetry_config.zig: New —TelemetryConfigtype promoted from infrastructuresrc/domain/timestamp.zig: New —Timestampparsing/formatting promoted from infrastructuresrc/domain/auth.zig: Layer alignmentsrc/domain/job.zig: Minor fixsrc/domain/query.zig: Update query types for new layer structuresrc/domain/runner.zig: Minor alignmentsrc/domain/server_stats.zig: Reduced — fields delegated to proper domain typesInfrastructure Layer
src/infrastructure/persistence/encoder.zig: Gutted — logic moved toapplication/persistence_codec.zig; now thin adapter delegating to codecsrc/infrastructure/persistence/backend.zig: Updated to usePersistencePortand application-layer codecsrc/infrastructure/persistence/background.zig: Updated for new codec/port interfacessrc/infrastructure/persistence/logfile.zig: Minor updatesrc/infrastructure/runner/subprocess.zig: New — extracted shared subprocess spawn logic used by shell, direct, awf runnerssrc/infrastructure/shell_runner.zig: New — shell runner adapter using new subprocess modulesrc/infrastructure/runner/shell.zig: Delegate tosubprocess.zigsrc/infrastructure/runner/direct.zig: Delegate tosubprocess.zigsrc/infrastructure/runner/awf.zig: Minor updatesrc/infrastructure/runner.zig: Barrel updatesrc/infrastructure/clock.zig: Minor alignmentsrc/infrastructure/http.zig: Layer alignmentsrc/infrastructure/http/json.zig: Layer alignmentsrc/infrastructure/protocol/parser.zig: Minor updatesrc/infrastructure/tcp_server.zig: Update for new scheduler generic typesrc/infrastructure/telemetry.zig: Useapplication/instruments.zigtypessrc/infrastructure/tls_context.zig: Minor updateInterfaces & Entry Point
src/interfaces/cli.zig: Update for new scheduler typesrc/interfaces/config.zig: Use promoted domain config typessrc/interfaces/dump.zig: Update for new codec locationsrc/main.zig: WireSchedulerWithgeneric, thread updates for new layer structureTests & Docs
src/functional_tests.zig: Extended test coverage for refactored pathsfunctional_tests: Compiled functional test binary (should be in.gitignore)CHANGELOG.md: Document hexagonal architecture refactoring under[Unreleased]CLAUDE.md: Expanded with Performance Principles, Memory & Allocators, Zig 0.15.2 Idioms, Hot Paths, Observability, and additional review/pitfall rulesTest plan
make buildcompiles without errors or warningszig build test-allpasses all layer-specific unit tests including newpersistence_codectestszig build test-functionalpasses end-to-end scheduler round-trip (SET job → tick → execute → persist → reload)zig build test-asanandzig build test-tsanreport no heap or data-race errorsGenerated with awf commit workflow