Refactoring 12-Year-Old Tsugi Code with AI — UI, Controllers, and Services @ChuckSeverance
Refactoring 12-Year-Old Tsugi Code with AI — UI, Controllers, and Services  @ChuckSeverance
Uploaded October 2026 | Updated November 2026, 2 hours ago
In this episode I take on a very different kind of AI coding task:

refactoring old production code.

Tsugi has accumulated more than a decade of history, and some of that history lives in places like UI/lessons.php — large utility files that mix HTML rendering, reusable logic, legacy compatibility, and application behavior.

It works.

But architecturally, it is time to clean it up.

The goal is conservative:

HTML generation belongs in controllers
reusable business logic belongs in services
UI utilities should actually be reusable UI widgets
legacy APIs should keep working
production behavior should not change

So we begin moving lesson rendering into the Lessons controller, along with similar rendering code for assignments, badges, and discussions.

Then the refactor gets deeper.

The remaining lesson-processing code begins to move out of UI/lessons.php and into a real Lessons service, along with supporting Common Cartridge and legacy lesson-processing classes.

But then comes the dangerous realization:

old LTI tools outside this repository already import UI/lessons.php.

Those tools are not using it for rendering. They are using it to parse lessons.json and look up content by resource-link ID.

If I simply delete the old class, a bunch of legacy tools scattered around the ecosystem could break.

So instead of removing the old API completely, we preserve a backwards-compatible shim that delegates into the new Lessons service.

That gives us the best of both worlds:

cleaner internal architecture without immediately breaking old integrations.

Along the way, I also refactor analytics code, move utility behavior into services, reorganize tests, and repeatedly ask AI to review its own work from a fresh thread before trusting the branch.

The hardest part of refactoring is not moving code.

It is knowing when to move it.

Too early, and you are designing abstractions before you understand the system.

Too late, and every new feature piles more dependencies onto the old architecture.

This felt like the right moment: enough of the new Tsugi architecture exists to know the controller/service patterns, but there is still plenty of development ahead to exercise and test the refactor before it settles into production.

AI makes this kind of large-scale cleanup dramatically faster — but the human still has to decide what belongs where, what compatibility must be preserved, and how much risk is acceptable.
Refactoring 12-Year-Old Tsugi Code with AI — UI, Controllers, and ServicesWeek 0 - Welcome to CA4E Live 2026-03-11AI Designing with Dr. Chuck:  Sakai LTI Direct ResearchShelby dogcation beach supercut #aussie #spoiledpupAI Master Programmer with Dr. Chuck: Preparing Tsugi Sites for Google OAuth Login with Cursor AIAI Coding with Dr. Chuck: Using AI to Add CSRF Security Across 60 FilesAI Coding: Supporting multiple tenants in LTI 1.3 tools in Sakai using deployment_id - SAK-52559Week 4 – HTML and CSS in DjangoDJ 08.03 Django Tutorial 2 on Python Anywhere: File Paths and Database Migrations (29:20)Turning PythonShell Into a PWA — That Was Surprisingly EasyDJ 07.03 SQLite Command Line: Basic Table Creation and Queries (8:39)AI Refactoring Needs Testing – Fixing a Tsugi Admin Bug with Panther QA
Chuck Severance |

Refactoring 12-Year-Old Tsugi Code with AI — UI, Controllers, and Services

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER