← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Table Module Pattern

Code Quality Intermediate
debt(d7/e7/b7/t5)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints indicate automated detection is 'no' and the code_pattern is a large Eloquent model with 50+ methods or mixed business/persistence logic. Tools listed (phpstan, deptrac) can flag structural issues but won't directly identify a Table Module misuse or its degeneration into a God Class — that requires careful code review to spot the pattern applied wrongly or growing unbounded.

e7 Effort Remediation debt — work required to fix once spotted

Closest to 'cross-cutting refactor across the codebase' (e7). The quick_fix describes a structural pattern choice, not a single-line patch. When a Table Module has grown into a God Class or mixed persistence with presentation, correcting it means redistributing methods across domain objects or introducing a proper Domain Model — a cross-cutting refactor touching many callers and potentially multiple files across the codebase.

b7 Burden Structural debt — long-term weight of choosing wrong

Closest to 'strong gravitational pull' (b7). The pattern applies to web and cli contexts broadly and is architectural in nature (tags: patterns, database, architecture). A Table Module, once adopted, shapes how all business logic for a table is organized. When it decays into a God Class, every future feature addition is shaped by the existing accumulation of methods, making it a persistent productivity tax with strong gravitational pull on every subsequent change.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception field explicitly states that developers confuse Table Module with Repository — a documented and common gotcha. Additionally, common_mistakes list growing into a God Class and creating one per every table regardless of need, both well-documented pitfalls. This is a known, learnable trap rather than a catastrophic or systematically contradictory one.

About DEBT scoring →

Also Known As

table module

TL;DR

One class per database table handling all logic — a pragmatic middle ground between Transaction Script and full Domain Model.

Explanation

Table Module (Martin Fowler, PoEAA): all business logic for a table's rows in one class, operating on collections not individual objects. Good for: moderate business logic that outgrows Transaction Script but does not justify full Domain Model.

Common Misconception

Table Module is the same as Repository — Repository returns domain objects one at a time; Table Module works on the table as a unit.

Why It Matters

Table Module fits database-centric applications where the domain logic is thin and SQL is the natural expression of business rules. It avoids the object-relational impedance mismatch of Active Record for read-heavy reporting use cases. The limitation is that it becomes awkward when business logic complexity grows — the module accumulates methods that would be better distributed across domain objects. It works well as an intermediate step when migrating from procedural database code toward a richer domain model.

Common Mistakes

  • Growing into a God Class
  • Mixing data access with presentation
  • One per every table regardless of need

Code Examples

✗ Vulnerable
// Logic scattered across files:
// file1.php: $pdo->query('SELECT * FROM orders WHERE...');
// file2.php: $pdo->query('UPDATE orders SET...');
✓ Fixed
class OrderTable {
    public function findPendingOverdue(): array { return $this->db->query(...)->fetchAll(); }
    public function markAsProcessing(int $id): void { $this->validateTransition($id); $this->db->execute(...); }
}

Added 16 Mar 2026
Edited 23 Mar 2026
Views 32
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping T 1 ping W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 1 ping T 1 ping W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W 1 ping T 0 pings F 1 ping S 1 ping S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 6 Ahrefs 4 Google 3 ChatGPT 3 Bing 3 Perplexity 2 Unknown AI 2 Claude 2 SEMrush 2 Scrapy 2
crawler 24 crawler_json 5
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Medium
⚡ Quick Fix
Use the Table Module pattern for simple domain logic where an Active Record is overkill but a full Domain Model is unnecessary — one class handles all business logic for a database table
📦 Applies To
any web cli
🔗 Prerequisites
🔍 Detection Hints
Large Eloquent model with 50+ methods; Active Record with complex business logic mixed with persistence; needed separation between domain logic and database
Auto-detectable: ✗ No phpstan deptrac
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Medium Context: Class Tests: Update


✓ schema.org compliant