Package Structure

Technical documentation of GGUF Loader's package structure and organization

Advanced 10 minutes

This page documents how the GGUF Loader codebase is organized. The app is a PySide6 desktop application; a single main.py bootstraps everything, and logic is split into core/ (pure logic), services/ (Qt threading bridges), and ui/ + widgets/ (presentation).

πŸ—‚οΈ Top-Level Layout

gguf-loader/
β”œβ”€β”€ main.py                 # Entry point: logging, DLL paths, QApplication, MainWindow
β”œβ”€β”€ config.py               # Central configuration constants
β”œβ”€β”€ resource_manager.py     # Resource/path discovery (dev, package, or frozen)
β”œβ”€β”€ addon_manager.py        # Loads and manages addons
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ build_exe.spec          # PyInstaller spec used for Windows & Linux builds
β”‚
β”œβ”€β”€ core/                   # Pure, testable logic (no Qt)
β”‚   β”œβ”€β”€ llm/
β”‚   β”‚   β”œβ”€β”€ model_backend.py    # Thread-safe llama-cpp-python wrapper
β”‚   β”‚   └── prompt_builder.py   # System-prompt & conversation assembly
β”‚   └── agent/
β”‚       β”œβ”€β”€ agent_engine.py     # Tool-use agent loop (no Qt, no llama_cpp)
β”‚       └── tool_registry.py    # Sandboxed workspace tools
β”‚
β”œβ”€β”€ services/               # QObject bridges that run work on threads
β”‚   β”œβ”€β”€ model_service.py        # Load/unload models on a QThread
β”‚   β”œβ”€β”€ chat_service.py         # Streaming generation on a QThread
β”‚   β”œβ”€β”€ agent_service.py        # Runs AgentEngine on a worker thread
β”‚   β”œβ”€β”€ environment_service.py  # venv/dependency checks & pip tasks
β”‚   └── launcher_service.py     # Launches scripts/ utilities
β”‚
β”œβ”€β”€ ui/                     # Main window & panels
β”‚   β”œβ”€β”€ main_window.py          # Composition root + addon-facing API
β”‚   β”œβ”€β”€ chat_panel.py           # Chat display, input, agent controls
β”‚   β”œβ”€β”€ sidebar_panel.py        # Model settings sidebar
β”‚   └── theme.py                # Dark/light QSS token system
β”‚
β”œβ”€β”€ widgets/                # Reusable widgets
β”‚   β”œβ”€β”€ chat_bubble.py          # ChatGPT-style bubble
β”‚   └── feedback_dialog.py      # Feedback form dialog
β”‚
β”œβ”€β”€ addons/                 # Addon packages (each has __init__.py with register())
β”‚   └── floating_chat/          # Built-in floating chat addon
β”‚
β”œβ”€β”€ scripts/                # Utility & release scripts
β”‚   β”œβ”€β”€ capture_screenshots.py  # Regenerates README/site screenshots
β”‚   β”œβ”€β”€ install_linux.sh        # Linux installer/uninstaller
β”‚   β”œβ”€β”€ package_linux.sh        # Builds the Linux .tar.gz release
β”‚   └── ...                     # GPU install/monitor helpers
β”‚
└── build_hooks/            # PyInstaller hook modules

πŸ” Key Design Rules

  • core/ never imports Qt or llama_cpp. It receives plain callables, so it can be unit-tested in isolation.
  • services/ are the only place Qt threads are created. UI never spins up threads directly.
  • ui/ widgets are β€œdumb” β€” they render state and emit signals; MainWindow owns all logic.
  • resource_manager.py makes paths work identically in dev, as an installed package, and in a PyInstaller bundle (sys._MEIPASS).

🧡 Threading Model

UI thread (MainWindow)          Worker thread
        β”‚                             β”‚
        │── ModelService.load() ─────→│  QThread: llama_cpp loads model
        │←────── loaded(ModelBackend) β”‚
        │── ChatService.generate() ──→│  QThread: streams tokens
        │←────── token_received(text) β”‚
        │── AgentService.process() ──→│  QThread: AgentEngine tool loop
        │←────── status/tool/response β”‚

A fresh QThread + worker is created per request (the professional Qt pattern β€” QThread is never subclassed).

πŸš€ Entry Point Flow

main.py β†’ setup_library_path() (finds bundled llama.cpp libs) β†’ QApplication β†’ MainWindow() β†’ builds UI, wires services, checks environment, loads addons β†’ app.exec().

πŸ“¦ Packaging

  • Windows: build_exe.bat / build_exe.spec β†’ GGUFLoader_vX.Y.Z.exe
  • Linux: build the spec inside a Linux environment, then scripts/package_linux.sh wraps the binary + installer + icon into a .tar.gz
  • GitHub Actions publishes both to every release automatically.

See the Architecture Overview for deeper design rationale.

🎯 What's Next?

You've completed this guide! Here are some suggested next steps to continue your GGUF Loader journey:

🏠

Explore Homepage

Discover more features, download options, and community resources on our homepage.

Visit Homepage β†’
πŸ“š

More Documentation

Continue learning with our comprehensive documentation library.

All Documentation β†’
πŸ’¬

Get Support

Have questions? Our community and support team are here to help.

FAQ & Support β†’

🏠 Back to Homepage