Repository navigation
Description
Summary
src/fl/system/file_system.h (146 lines) has drifted from the conventions documented in agents/docs/cpp-standards.md. It is the header every filesystem-using sketch includes, and it currently mixes the public API, the platform extension point, per-format convenience methods, test-only hooks, and an inline implementation. Requesting an audit and a decision on whether to rectify.
Surfaced while adding a LittleFS backend (#3984) — the natural next step was to add beginLittleFs() / littleFs() next to beginSd() / sd(), which would have widened the class again. That was backed out in favor of the existing generic seam, but it made the shape hard to ignore.
Observations
1. The API object contains implementation
cpp-standards.md → API Object Pattern, rule 2: "The API object wraps, it doesn't implement... contains no core logic itself."
file_system.h ends with a fully inline loadJpegFromSD() that constructs a FileSystem, calls beginSd(), builds an error string, and loads a JPEG. That is core logic living in the public header, and it hard-couples SD to JPEG inside the filesystem API.
2. No matching implementation directory
Rule 1: "One header, one directory, same name. foo.h is the public API; foo/ holds everything behind it."
There is no fl/system/file_system/. The implementation is spread across fl/system/file_system.cpp.hpp, fl/system/sd/, and (proposed) fl/system/littlefs/. The directory naming does not follow the documented pairing, so there is no obvious home for a new backend.
3. FileSystem accumulates a method per format
The class currently exposes openVideo, openMpeg1Video, readText, readJson, readScreenMaps, readScreenMap, loadJpeg, openMp3, and loadFled. A filesystem class knows about JPEG, MP3, JSON, ScreenMap, Video, and Fled.
Consequences worth weighing:
- every new asset format widens the class
- the header drags
JpegConfig,Mp3DecoderPtr,json,ScreenMap,Video,Fled, andflat_mapdeclarations into the include graph of anyone who touches a file - the natural place for
readFoo()is here, so the pressure is always toward more
An alternative shape is free functions taking a FileSystem& (or a filebuf_ptr), which keeps the class to open/read/close and lets each format live with its own decoder. Not proposing that as the answer — just naming the axis the audit should decide on.
4. Public API and platform extension point share a header
FsImpl — the interface a platform subclasses — is declared in the same header as the user-facing FileSystem. Sketch authors and platform implementers read the same file for different reasons. make_sdcard_filesystem() / make_littlefs_filesystem() sit in an earlier namespace fl {} block, separated from FsImpl by the entire FileSystem class.
5. Test-only symbols in the public header
setTestFileSystemRoot() / getTestFileSystemRoot() are declared under #ifdef FASTLED_TESTING in the public header, with the comment noting they are implemented in platforms/stub/fs_stub.hpp.
6. Two namespace fl { } blocks
The file opens and closes namespace fl twice with unrelated declarations in each. Probably incremental growth rather than intent.
What this issue is asking for
- Audit
file_system.hagainstagents/docs/cpp-standards.md, especially the API Object Pattern. - Decide which divergences are deliberate (there may be good linker or include-graph reasons — the SD split in
fl/system/sd/is clearly deliberate and well documented) and which are drift. - If rectifying: agree the target shape before more backends land, so LittleFS (feat: add a LittleFS FsImpl backend — on-chip flash storage is unreachable today #3984) and any future filesystem are added to the intended structure rather than bolted onto the current one.
Note on the SD split
fl/system/sd/ and src/fl/build/fl.system.sd+.cpp are a deliberate, well-commented design — the SD chain gets its own translation unit so the linker can dead-strip ~16 KB on ESP32-S3 when beginSd() is never called (FastLED #2773 item 1.2). Any restructuring must preserve that property. It is a constraint on the fix, not part of the problem.
Related
- feat: add a LittleFS FsImpl backend — on-chip flash storage is unreachable today #3984 — LittleFS backend, currently blocked on knowing the intended shape
- meta: remote assets — hosting, build-time resolution, and on-device filesystem deployment #3986 — meta issue for the asset/filesystem work
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Aug 23, 2026
Additional evidence: the header re-exports codec headers
Observation 3 above is stronger than I first described. The top of
file_system.hdoes not merely forward-declare the format types — it re-exports their headers:IWYU pragma: exportmeans a consumer that includesfile_system.his intended to getvideo.handjpeg.htransitively. So every sketch that opens a file also pulls the video and JPEG headers into its translation unit, whether or not it decodes anything.That is the include-graph cost of the god-object shape, and it is the part most likely to show up as compile time and flash on constrained targets.
Note the mixed strategy:
Mp3Decoderis forward-declared (lines 17-20) rather than included, andScreenMap/Fled/Videoare forward-declared again lower down — so the file already demonstrates the lighter approach for some formats while including others outright. Whatever the audit concludes, being consistent here looks like a cheap win.refactor(fs): expose embedded storage generically as fl::getEmbeddedFs()
docs(review): add a CodeRabbit rule on public API expansion (#4005)
refactor(fs): finish the API Object Pattern items from #4003
refactor(fs): consolidate the filesystem subsystem under fl/fs/ (#4010)
refactor(fs): expose embedded storage generically as fl::getEmbeddedF…
zackees commentedon Sep 1, 2026
Resolved by #4010 (merged as a5d65bb). The audit produced and implemented the target shape under
src/fl/fs/:FsImplis isolated inbackend.h, format-oriented free functions live inread.hwith out-of-line bodies, test hooks live intesting.h, the SD backend retains its separate translation unit for dead-stripping, andfl/system/file_system.his now only a compatibility forwarder. The former inlineloadJpegFromSD()implementation moved out of the public header.\n\nThe remaining legacyFileSystemformat members and their codec includes were explicitly reviewed and deliberately retained for source compatibility; new formats use the free-function seam instead, with removal reserved for a future breaking/deprecation cycle. #3984 subsequently landed through the generic backend interface and is closed.