# 2. Layered Code Organization

Date: 2022-10-04

## Status

Accepted

## Context

The code was previously organized as a flat set of files, with every file depending on every other file. This creates the opportunity for many anti-patterns to manifest.

## Decision

The code is now organized according to the following layering hierarchy, starting from the "bottom" up.

- Interfaces
- Support code
- Hardware Platform (BSP, devices)
- Error Handler
- State
- Top-level application logic (Main.cpp, CPFStateProcessing.cpp)

The Hardware Platform layer also has its own internal layered hierarchy:

- STM32H7
- Devices (drivers for non-processor components)
- BSP
- FatFS
- SDLogger

## Consequences

- Each layer can only use the facilities provided by layers lower than it.
- Not all code is usable from all layers.
- Code must be placed into the proper spot in the layer in order to use the proper dependencies
- The build system is designed to support this layering strategy
