Code in junior.guru
Design and style
- Aim for Clean Architecture (textual slides): imperative shell wrapping functional core. See Pure core, I/O shell.
- Use Python type hints everywhere.
- Keep cyclomatic complexity low.
- Order module functions from highest-level entry points to progressively smaller helpers. Exception: functions that must exist earlier because module import uses them.
- Use
httpx2for HTTP requests. Do not add direct use ofrequestsor plainhttpx; those remain transitive dependencies. - Use
clickfor CLI definitions. - Modern Python and walrus operators are welcome. Follow Ruff
UPrules. - Keep Ruff target version compatible with
requires-python. - In
key=callbacks such assorted(),max(), andmin(), preferattrgetteroritemgetterover lambda when applicable. - Do not use
if TYPE_CHECKING:blocks. Prefer direct imports and annotations. - Do not place imports inside functions or methods. Keep them at module level.
- When a comment at the start of a function documents the whole function, write it as a docstring, not a leading
#comment block. Keep#comments for individual steps inside the function. - In SCSS, prefer
$spacerover equivalentmap.get($spacers, 3).
Pure core, I/O shell
A function either computes or does I/O (database, HTTP, files, Discord, CLI output), never both.
- Put data transformation in pure functions that take plain data and return plain data (dicts, dataclasses, primitives). Cover them with unit tests.
- I/O functions only fetch data, pass it to pure functions, and save or send the results.
- Existing code doesn't always follow this. Don't copy a mixed pattern from surrounding code; split it in the code you add or change.
Example: don't write save_referrer(member), which builds a row from API data and calls .create(). Write a pure parse_referrer(member) -> dict | None, test it, and have the sync loop call Model.create(**referrer).
Tests
- Develop using red-green TDD.
- Favor many fast unit tests for functional core and few integration tests for imperative shell.
- Tests must not depend on network, current time, or similar external state. Networked smoke/e2e tests must not run by default.
- For remote HTML, download representative pages as fixtures under tests and test against those fixtures. Add multiple fixtures for meaningful edge cases.
- Aim for one descriptive assertion per test function unless impractical, such as checking several small parts of one complex structure.
- For stub objects, prefer
types.SimpleNamespaceover named tuples. Exception: use a named tuple when the stub must be hashable, e.g. when collected into a set. - Use
@pytest.mark.parametrizewhen applicable. Include spaces after commas in parameter names, for example"secondary_school, university, expected".
Logging
- Set
LOG_LEVEL=debugto show DEBUG logs. Default level is INFO; selected muted loggers default to WARNING. Configuration lives inloggers.py. - Log potentially sensitive diagnostic details only at DEBUG because CI normally logs INFO.
- Never log actual secrets or other data unsafe for CI output. CI may temporarily enable DEBUG while diagnosing failures that cannot be reproduced locally.
Verification
- Before finishing, check every function you added or changed: if it both transforms data and does I/O (
.create(),.save(), HTTP calls, file writes, etc.), split it. - After any code changes, run
uv run jg tidy --codebefore finishing. - Run
uv run jg testonly after substantial Python or JavaScript changes. - After major SCSS or JavaScript changes, consider
uv run jg web build-staticto catch asset build failures. - After template,
context.py, or related rendering changes, consideruv run jg web buildto verify site generation.
Sync safety
Never run uv run jg sync ... without asking user first. When authorized and necessary, use uv run jg sync --no-deps ... to avoid triggering full dependency pipeline.