Repository navigation
Give cross-cutting concepts one owner and enforce architecture rules in tests - #97
Merged
Merged
Conversation
Records the architecture scan findings and the baseline, so each refactoring round can be tracked against them.
UserAuth, LocaleController and FallbackController each validated user-controlled redirect targets with their own rules. The two referer-based ones accepted protocol-relative paths (//host), which made Phoenix raise instead of falling back to /. LocalPath is now the single implementation. test/architecture_test.exs pins it, along with the domain/web and Repo layering rules (ADR 0001).
Supported locales were read from config in three modules, the default was hardcoded in two more, and request-locale resolution lived inside the auth plug while its cookie was written by LocaleController. ElixirReactStarter.Locale now owns the list and the default; Plugs.Locale owns resolution and the cookie. An architecture test keeps the config reads in one place.
…ser shape SettingsController and ConnCase wrote the "user_token" session key themselves; UserAuth.put_user_session/2 now does it for all callers. SharedData's private serialize_user/1 becomes UserJSON.data/1, per the *_json.ex rule, which an architecture test now enforces.
Link-token contexts were free strings, so a typo silently issued a token no verifier would accept. Both UserToken and the Accounts API now guard against a closed list. build_email_change_token/2 folds into build_link_token/3, and the SHA3-256 call lives in one private hash/1. Stored token format is unchanged.
Controllers piped emails into Mailer.deliver/1 and discarded the result, so delivery failures vanished, and the builders logged "Sending" before anything was sent. Email.deliver/1 now sends, logs the outcome with the recipient redacted, and returns :ok. An architecture test keeps it the only caller of the mailer. Also folds the repeated invalid-link redirects in AuthController and SettingsController into one helper each.
Six pages hand-wrote the same label, input and error markup eleven times, and none linked the error to its input. TextField owns that markup plus aria-invalid and aria-describedby, and replaces the shared inputClass string (components/ui.ts, deleted). A node contract test keeps raw inputs out of pages and layouts.
LocaleSelector carried its own chevron SVG next to lucide's, and an English-only aria-label. syncLocale moves to i18n/, beside the setup it drives; components/ holds UI primitives only.
watch-routes.cjs and watch-ssr-pages.cjs were two copies of the same regenerate-on-change loop, each its own dev watcher process. watch-generated.cjs runs both generators from one table.
- Serializer rule now sees guarded definitions; every rule fails if its glob matches no files instead of passing vacuously. - TextField keeps a caller's aria-describedby alongside the error id. - Email.deliver/1 test runs in its own sync module (global log level). - AGENTS.md JSON-view rule matches practice: data/1, index/show with the first JSON endpoint.
The map-literal spec allowed only an :id key, so dialyzer flagged every caller passing a full user struct.
The sender was hardcoded in Email, so every project and environment had to edit code to change it. It is now the :mail_from config value, read at runtime so an environment's config can override it.
runtime.exs and ssr.tsx derive Sentry's environment and release from the same variables in two runtimes. Each now points to the other so an edit to one prompts the matching edit.
Drops the task pool, progress log and ADR (the history lives in the commits) and shortens the architecture map and AGENTS.md additions to the rules and owners agents need.
… import bans to Biome TextField-only form fields move from the node contract test to Biome's noRestrictedElements, and the heroicons / radix-themes bans from AGENTS.md become noRestrictedImports entries. architecture.test.ts now holds the two AGENTS.md rules Biome can't express: no raw try/catch outside result.ts, and no string-literal internal URLs.
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.
Several concepts were each owned by more than one module, and the project's architecture rules were only checked in review. This PR gives each of those concepts one owner and adds tests that fail the build when a rule is broken.
Changes
LocalPathreplaces three separate redirect checks inUserAuth,LocaleControllerandFallbackController. Fix: the two referer-based checks accepted//hostpaths, which made Phoenix raise a 500. They now fall back to/.ElixirReactStarter.Localeowns the supported and default locales.Plugs.Localeresolves the request locale and owns the cookie. Before, config reads and hardcoded"en"values were spread across five modules.UserAuthnow handles authentication only.UserAuth.put_user_session/2is the only code that writes the session token. Before,SettingsControllerandConnCasealso wrote it.UserJSON.data/1replacesSharedData's privateserialize_userhelper.Email.deliver/1. Fix: delivery failures used to be silently discarded, and "Sending" was logged before anything was sent. Failures are now logged at error level. The sender address comes from the new:mail_fromconfig value.TextFieldreplaces 11 hand-written fields on 6 pages. It links each error message to its input witharia-invalidandaria-describedby; no form did this before.components/ui.tsis deleted.syncLocale.tsmoves toi18n/.config/runtime.exsandssr.tsxpoint to each other, because both work out Sentry's environment and release from the same variables.Enforcement
test/architecture_test.exschecks the Elixir source and fails the build when any of these rules break:LocalPathreadsReferer;Localereads the locale config;EmailcallsMailer;*_json.ex.assets/js/architecture.test.tscovers twoAGENTS.mdrules Biome can't express: no rawtry/catchoutsideresult.ts, and no string-literal internal URLs.assets/biome.jsoncnow bans raw<input>/<label>/<textarea>in pages and layouts (useTextField), and bans@heroicons/reactand@radix-ui/themesimports.docs/architecture.mdlists each rule and which module owns each concept.Verification
mix precommitpassed on every commit, with 270 tests.mix dialyzerreports 0 errors.scripts/e2epassed for every flow these changes touch: login, registration, email confirmation, resend confirmation, password reset, change email, change password, delete account and locale.