Skip to content
nim-code-organization logo

Nim Code Organization

nim-code-organization

Organize Nim code into clear modules and multi-step workflows, with explicit state, top-level helper procs, narrow exports, and easy-to-follow orchestration. Use when refactoring a large Nim file, splitting logic across modules, designing parser-style stateful code, or cleaning up nested helpers ...

planetis-m/skills0installs59stars

SKILL.md

Full skill instructions

Nim Code Organization

Preamble

Use this skill when splitting Nim code into modules, helpers, and orchestration steps. Keep shared state explicit. Keep behavior in top-level procs. Keep exports narrow.

Rules

Orchestration state

  • For multi-step orchestration, use an explicit state object.
  • Prefer a plain object passed by var for orchestration state.
  • Use ref object state only when identity, aliasing, or shared lifetime is part of the design.
  • Pass shared mutable flow through proc parameters. Do not hide it in outer locals.

Helper placement

  • Prefer top-level helper procs for orchestration logic.
  • Keep reusable helpers out of the main driver proc.
  • Use nested procs only for truly local logic or intentional closures.
  • A nested proc may capture outer locals by default. If a nested proc must stay non-capturing, mark it {.nimcall.}.

Module shape

  • Keep exports intentional. Export only the public surface.
  • Keep orchestration internals, helper procs, and state details private unless another module must call them.
  • Keep one module focused on one piece of state and the procs that operate on it.

Control flow

  • Prefer explicit branching in procs over runtime dispatch for ordinary orchestration code.
  • When behavior varies by kind, model the kind in data and branch with case before reaching for method.

Stdlib pattern

  • Follow the stdlib parser-style shape when it fits: one state object, top-level open/next/close-style procs, and private helpers that mutate var State.

Workflow

  1. Identify the shared mutable flow. If several steps touch the same evolving state, name it as an explicit object.
  2. Choose the state representation. Start with a plain object and pass it by var.
  3. Place helpers. Put orchestration helpers at module scope. Use nested procs only when the logic is local and short.
  4. Define the public surface. Export only the entry points and public data types.
  5. Choose the control flow shape. Use a small set of procs and explicit branching. Add runtime dispatch only if the design really needs it.

Minimal Pattern

type
  State = object
    pos: int
    ready: seq[bool]

proc markReady(state: var State; idx: int) =
  state.ready[idx] = true

proc flushReady(state: var State; ids: openArray[string]; out: var seq[string]) =
  while state.pos < ids.len and state.ready[state.pos]:
    out.add ids[state.pos]
    inc state.pos

Common Mistakes

MistakeWhy it's wrong
Hiding shared orchestration flow in outer localsThe data flow becomes implicit instead of visible in proc signatures
Using nested helper captures for a multi-step pipelineIt hides shared mutation and makes the control flow harder to inspect
Spreading one stateful workflow across many runtime-dispatched typesThe state flow becomes harder to follow than a small set of procs and a case split
Exporting internal helpers or internal stateIt leaks implementation details into the public API
Starting with ref object state for a plain local pipelineIt adds aliasing where a plain object would keep ownership clearer

References

  • references/​orchestration_pattern.md — Explicit state object vs nested closure for a small orchestration flow
  • references/​parser_state_pattern.md — Stdlib-style parser/​state object with top-level mutating procs

Changelog

  • 2026-04-09: Initial verified skill.
  • 2026-04-11: Added plain-object state, top-level orchestration, nested proc capture guidance.

More skills from planetis-m

tts-tool logo
planetis-m/tts-tool

tts-tool

Generate a natural-sounding `.opus` audio file from text or markdown. Use when a user wants spoken audio, especially for content with markdown, URLs, formulas, paths, or technical notation that should be rewritten for speech.

3 0
View
nim-api-design logo
planetis-m/skills

nim-api-design

Design clear public Nim APIs for libraries and modules, including exported types, constructors, lookup functions, error contracts, and container-style interfaces. Use when creating or reviewing a Nim library API, designing an exported module surface, or deciding how callers should construct, acce...

59 0
View
ocr-tool logo
planetis-m/ocr-tool

ocr-tool

Extract raw text from PDF files with OCR, including full-document extraction, selected page ranges, and reuse of cached pages. Use when a user asks to OCR a PDF, extract text from a scanned PDF, or read selected PDF pages.

1 0
View
nim-c-wrappers logo
planetis-m/skills

nim-c-wrappers

Turn low-level C FFI bindings into an idiomatic Nim API, with safer types, cleaner module boundaries, resource management, callbacks, enums, bitflags, and exception-based error handling. Use when building a high-level Nim wrapper around a C library or improving the usability of existing raw bindi...

59 0
View
nim-style-guide logo
planetis-m/skills

nim-style-guide

Write clear, consistent Nim code in a simple stdlib-aligned style, covering imports, naming, proc vs func vs template choices, local variables, constructors, formatting, and control flow. Use when writing new Nim code or reviewing a Nim module for readability, consistency, and low-noise style dec...

59 0
View
rag-tool logo
planetis-m/rag-tool

rag-tool

Store and search text or markdown as semantic chunks in a reusable local vector store. Use when a user wants to ingest documents or retrieve relevant passages from previously stored material.

1 0
View
study-assistant logo
planetis-m/study-assistant

study-assistant

Study assistant workflow for turning provided study material into exam-focused deliverables such as verbatim transcriptions, study notes, lecture-style explanations, ELI5 explanations, flashcards, Mermaid mind maps, quizzes, and essay questions.

5 0
View
nim-ownership-hooks logo
planetis-m/skills

nim-ownership-hooks

Implement and review Nim ARC/ORC ownership hooks for types that manually manage resources, including move-only, deep-copy, refcounted, and copy-on-write patterns. Use when a Nim type owns pointers, buffers, file descriptors, or custom heap memory and you need correct `=destroy`, `=copy`, `=dup`, ...

59 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View