TunnelVision

02 — Coding standards

These are binding for all code in this repo. They exist so that work from different sessions looks like it came from one engineer.

Language and concurrency

Types first, then logic

This is the house rhythm and it is not optional:

  1. Define the data types (struct/enum, Sendable, Codable where needed).
  2. Define the protocol / function signatures, with documented error behaviour.
  3. Only then implement the bodies.

The spec/ documents already give you step 1 and 2 for every module. Follow them; if you must deviate, update the spec in the same commit.

Error handling

Naming and comments

Product copy (M11 onwards)

Every string a user can read or hear goes through String(localized:defaultValue:comment:). There is no L10n helper and there must not be one: Xcode extracts the copy into TunnelVision/Resources/Localizable.xcstrings by reading these calls at build time, and it only sees them when the key, the default value and the comment are literals at the call site. A wrapper function would compile fine and silently extract nothing.

TunnelVision/Models is compiled into the test bundle by source membership, and the test bundle has no catalog: in tests every lookup falls back to defaultValue, so the existing assertions on literal English keep meaning exactly what they meant.

The test bundle runs in English, and that is a setting, not luck. The scheme pins it (project.yml, schemes.TunnelVision.test.language/region → en/US), so Xcode, the terminal and CI all agree. It matters because a lookup falling back to its defaultValue is language-independent but its placeholders are not: an integer is formatted with the process locale, so without the pin every assertion about a number said whatever the machine running it happened to say. Two things follow:

Memory discipline (the extension is the hard part)

The extension runs under a small memory budget and the OS kills it if exceeded. Therefore:

See ../spec/ipc.md and ../ARCHITECTURE.md.

Dependencies

Native Apple frameworks first (SwiftUI, NetworkExtension, Network, Foundation, Swift Charts, CryptoKit, Security). The only third-party dependency is GRDB.swift, justified in ../decisions/0002-grdb-over-swiftdata.md. Adding any other package requires a new ADR.

Testing

Every module with non-trivial logic ships with tests, and tests run green before every push. Details and fixtures in 04-testing-strategy.md.

Git and authorship

Definition of done for a unit of work