Skip to content

Conversation

@kzndotsh
Copy link
Contributor

@kzndotsh kzndotsh commented Jul 11, 2025

Description

This PR implements a major architectural refactor of the Tux project, addressing the goals outlined in Issue #924. The primary motivation is to enhance clarity, extensibility, scalability, and contributor-friendliness by establishing a clear separation of concerns within the codebase.

The refactor introduces a new, modular directory structure:

  • core/: Contains essential bot functionality, startup, shared UI, and core utilities.
  • infra/: Houses infrastructure components like the database, logging, external API wrappers, and infrastructure-specific handlers.
  • modules/: Dedicated to official, loadable feature modules (cogs/extensions).
  • custom_modules/: Provides a .gitignored location for self-hosters to add private or server-specific extensions without modifying the main codebase.
  • cli/: For command-line interface tools.
  • assets/: For static files.
  • main.py: The application entry point, now at the root.

All internal import statements have been updated to reflect this new structure, and the core/cog_loader.py has been enhanced to dynamically load cogs from infra/handlers/, modules/, and custom_modules/ in a defined order.

This change fixes #924.

Guidelines

  • My code follows the style guidelines of this project (formatted with Ruff)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation if needed
  • My changes generate no new warnings
  • I have tested this change
  • Any dependent changes have been merged and published in downstream modules
  • I have added all appropriate labels to this PR

How Has This Been Tested?

The refactoring primarily involved moving files and updating import paths. Testing focused on ensuring all modules and components could be imported correctly:

  • Verified successful import of core components: python -c "import core.bot; import core.app; import core.cog_loader"
  • Verified successful import of infrastructure components: python -c "import infra.database.client; import infra.handlers.error; import infra.wrappers.github"
  • Verified that the main.py entry point can correctly initialize the application with the new import structure.
  • Manual inspection of numerous files to confirm import paths were updated accurately.

Screenshots (if applicable)

N/A

Additional Information

  • A detailed explanation of the new architecture can be found in ARCHITECTURE.md.
  • A summary of the changes made during this refactor is available in REFACTOR_SUMMARY.md.
  • The custom_modules/ directory has been added to .gitignore to prevent accidental commits of user-specific extensions.
  • The tux/extensions/README.md has been removed as its content is now covered by custom_modules/README.md and ARCHITECTURE.md.

Summary by Sourcery

Implement a major architectural refactor to improve modularity by reorganizing the codebase into dedicated core, infrastructure, feature, and custom directories, updating imports and cog loading logic, and adding comprehensive documentation.

New Features:

  • Restructure codebase into core, infra, modules, custom_modules, cli, and assets directories
  • Enhance cog loader to dynamically load infrastructure handlers, official modules, and custom modules in defined priority order
  • Introduce custom_modules directory (gitignored) for self-hosters to add private extensions

Enhancements:

  • Update all import paths to align with the new directory structure
  • Move main application entrypoint to root-level main.py and adjust CLI imports accordingly
  • Add custom_modules to .gitignore and remove the obsolete extensions README

Documentation:

  • Add ARCHITECTURE.md and REFACTOR_SUMMARY.md detailing the new modular architecture and migration guidance

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 11, 2025

Deploying tux with  Cloudflare Pages  Cloudflare Pages

Latest commit: b036e09
Status:🚫  Build failed.

View logs

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jul 11, 2025

Reviewer's Guide

This PR refactors the Tux codebase into a clear, modular architecture by reorganizing all sources into six top-level directories (core, infra, modules, custom_modules, cli, assets), consolidating documentation, updating the cog loader to handle the new layout, and mass-updating import paths to match.

File-Level Changes

Change Details Files
Modular directory structure and documentation
  • Introduce core/, infra/, modules/, custom_modules/, cli/, assets/, tests/ directories
  • Add ARCHITECTURE.md and REFACTOR_SUMMARY.md with new architecture and refactor details
  • Update .gitignore to exclude custom_modules/
  • Remove legacy tux/extensions/README.md and trim root README.md
.gitignore
ARCHITECTURE.md
REFACTOR_SUMMARY.md
README.md
Refactored CogLoader to support new modules layout
  • Compute paths relative to project root and format module names dynamically
  • Adjust cog_path resolution and span tags to point at infra/handlers, modules, custom_modules
  • Update loading order with new span names for infrastructure handlers, official modules, and custom modules
core/cog_loader.py
Mass import path overhaul
  • Replace all from tux.* imports with from core.*, infra.*, modules.*, or cli.*
  • Update imports in Bot, App, config, utils, UI components, cogs, handlers, and wrappers to reflect new directories
core/app.py
core/bot.py
core/config.py
core/ui/embeds.py
modules/admin/git.py
modules/levels/level.py
infra/handlers/event.py
cli/core.py
Database controllers relocation
  • Move database controller files under infra/database/controllers/
  • Update imports from database.client and database.controllers.base across services and bot setup
infra/database/controllers/afk.py
infra/database/controllers/case.py
infra/database/controllers/levels.py
infra/database/controllers/note.py
infra/database/controllers/reminder.py
infra/database/controllers/snippet.py
infra/database/controllers/starboard.py
CLI tools moved and updated
  • Relocate all CLI modules from tux/cli to top-level cli/ directory
  • Update command registration imports and main entrypoint to use cli.core
cli/core.py
cli/database.py
cli/docker.py
cli/dev.py
cli/docs.py
cli/test.py

Assessment against linked issues

Issue Objective Addressed Explanation

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@kzndotsh kzndotsh merged commit c190d7f into refactor/architecture Jul 12, 2025
0 of 2 checks passed
@kzndotsh kzndotsh deleted the cursor/refactor-project-structure-for-modularity-ac27 branch July 12, 2025 06:36
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.

3 participants