How muktihari/fit works
Project Type and Purpose
• This is a Go‐based SDK for the Garmin FIT protocol plus a suite of command-line tools (fitactivity, fitconv, fitprint, fitdump).
• Its main responsibilities are:
• Decoding binary FIT files into messages or CSV/text formats
• Encoding messages or CSV back into FIT
• Offering a library API for Go programs to read/write FIT protocol messages with full semantics (message order, unknown/developer fields)
• Providing code-generation and runtime-registration mechanisms for custom/manufacturer‐specific messages
A. CLI Layer (cmd/)
• fitactivity (combine, conceal, reduce/remove messages)
• fitconv (FIT ⇄ CSV)
• fitprint (human-readable TXT dump)
• fitdump (hex/segmented dump)
B. Core FIT SDK
1. decoder/
– ReadBuffer → bits → raw frames → Listener → protocol messages
2. encoder/
– Validator → LRU caching → WriteBuffer → binary FIT stream
3. proto/
– Message/value marshal/unmarshal, versioning, validation
4. profile/ (generated code)
– basetype, filedef, mesgdef, typedef, untyped → Go structs & constants representing every FIT message/field
5. kit/ & internal/
– Utilities (datetime, hash, semicírculos, sliceutil) & internal command helpers (benchfit, csvdiff, fitgen, testgen)
C. Code-Generation Subsystem (internal/cmd/fitgen + docs/)
• Parser reads Profile.xlsx, generator templates produce profile/mesgdef and profile/typedef
• Provides: custom‐SDK generation, runtime registration API (factory package)
D. Data Sources & Sinks
• Input: .fit files, .csv files, Profile.xlsx (for codegen)
• Output: new .fit files, .csv dumps, .txt reports, benchmarks
Relationships & Data Flow
• CLI Tool → invokes Core SDK API
• Core SDK Decode: FIT file → decoder → proto → profile messages → CLI prints or converts to CSV/TXT
• Core SDK Encode: CSV (or Go structs) → profile messages → proto marshal → encoder → FIT file
• Codegen tool (fitgen) → reads Profile.xlsx → outputs Go code (profile/) → included in Core SDK build
• internal/cmd/benchfit → uses Core SDK to benchmark against third-party library
Architectural Patterns & Principles
• Layered design: CLI → Core Library → lower-level wire/frame processing
• Separation of concerns: decoder vs. proto vs. encoder vs. profile data
• Code generation for protocol definitions (DRY & maintainability)
• Pluggable/customizable profiles via runtime registration or codegen
Final Advice
• Both the static structure (packages/modules) and dynamic data flow (FIT → CSV → FIT; codegen → profile)
• Use layering (top = CLI, mid = core, bottom = low-level frame processing) to make the architecture immediately clear
• Review README and docs/usage.md to ensure all features (developer fields, compressed timestamps, benchmarks) are represented