Skip to content

Refactor: Split large files into one-file-per-declaration structure (#16)#17

Merged
odrobnik merged 4 commits intomainfrom
refactor/issue-16-file-organization
Mar 21, 2026
Merged

Refactor: Split large files into one-file-per-declaration structure (#16)#17
odrobnik merged 4 commits intomainfrom
refactor/issue-16-file-organization

Conversation

@odrobnik
Copy link
Copy Markdown
Contributor

Summary

Systematic refactoring to improve code navigation and maintainability by splitting large monolithic files into focused, single-responsibility files.

Changes

Phase 1: Models (commit 8e24a34)

  • Split Models.swift into 11 individual files in Sources/PostServer/Models/
  • One file per type: MessageHeader, MessageDetail, AttachmentInfo, etc.
  • Zero logic changes

Phase 2: Commands (commit d926a7c)

  • Extracted 22 command structs from PostCLI.swift into Sources/post/Commands/
  • PostCLI.swift: 2,225 → 743 lines (-67% reduction!)
  • Each command now has its own file

Phase 3: IDLE Extension (commit 2cc088d)

  • Extracted ~820 lines of IDLE/Hooks logic into PostServer+IDLE.swift
  • PostServer.swift: 2,126 → 1,326 lines (-38% reduction!)
  • Changed privateinternal for cross-file extension access

Helper Access (commit 73af797)

  • Made helper methods internal for future extension use
  • Preparation for additional extensions (Messages, Folders, Actions, etc.)

Impact

  • 34 new files created (11 models + 22 commands + 1 extension)
  • ~2,500 lines reorganized into focused files
  • Fast navigation via CMD+O to any model, command, or feature
  • Easier maintenance — smaller, focused files
  • Better reviews — changes isolated to specific files
  • Zero behavior changes — pure refactoring
  • All tests pass (8/8)
  • Zero new warnings

Before/After

PostCLI.swift:

  • Before: 2,225 lines (all commands + shared utilities)
  • After: 743 lines (main command + utilities only)

PostServer.swift:

  • Before: 2,126 lines (all server logic)
  • After: 1,326 lines (IDLE extracted, helpers exposed)

Testing

swift build -c release  # ✅ Success
swift test              # ✅ All 8 tests pass

Issue

Closes #16

- Created Sources/PostServer/Models/ directory
- Split 11 model types into separate files:
  - ServerInfo, MessageHeader, MessageDetail
  - AttachmentInfo, AttachmentData
  - MailboxInfo, RawMessage, DraftResult
  - NamespaceEntry, NamespaceInfo, SearchCount
- Deleted original Models.swift
- Zero new warnings, all tests pass

Issue: #16
- Created Sources/post/Commands/ directory
- Extracted 22 command structs into separate files:
  - List, Fetch, Search, Draft, Flag, Junk, Trash, Archive
  - Move, Copy, Servers, Folders, Create, Status, Quota
  - Attachment, PDF, Idle, EML, Expunge
  - Credential (+ nested Set/Delete/List)
  - APIKey (+ nested Create/List/Delete)
- Reduced PostCLI.swift from 2,225 to 743 lines (-1,504 lines)
- Kept all shared utilities in main file
- Zero new warnings, all tests pass

Issue: #16
…Phase 3 partial)

- Created PostServer+IDLE.swift extension (~820 lines)
- Extracted all IDLE watch, hook, and message payload logic
- Removed ~800 lines from main PostServer.swift
- Changed private → internal for cross-file extension access:
  - connectionManager, logger, idleWatchTasks
  - withServer, formatDate, logDiagnostic
  - Helper structs: HookPayload, HookMessagePayload, HookAttachmentPayload
- Zero new warnings, all tests pass

Issue: #16
#16)

- Changed private → internal for helper methods:
  - allowedServerIDsForCurrentSession
  - fetchAdditionalHeaders, collectHeaders
  - messageHeader, messageDetail
  - parseISO8601Date, parseFlags
  - specialUseDescription

Preparation for extracting more methods into extensions.

Issue: #16
@odrobnik odrobnik merged commit fe6f989 into main Mar 21, 2026
2 checks passed
@odrobnik odrobnik deleted the refactor/issue-16-file-organization branch March 21, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Split large files into one-file-per-declaration structure

1 participant