One File Is Enough: The Art of Monolithic Code Architecture
I’ve been architecting software for 47 years, and I’ve finally cracked the code on code organization: don’t. Every file you create is a context switch. Every import statement is cognitive overhead. Every folder is a crime against productivity.
The optimal number of files in any project is one.
The Mathematics of Files
Let’s do some simple math:
| Number of Files | Import Statements | Things That Can Break |
|---|---|---|
| 1 | 0 | 1 |
| 5 | 12 | 60 |
| 50 | 200 | 5,000 |
| 500 | 3,000 | ∞ |
See the pattern? More files = exponentially more problems. One file = one problem. Simple.
The God Class: Divine Architecture
They call it an “anti-pattern.” I call it efficiency:
# app.py - The only file you'll ever need
# Lines 1-50,000: User management
# Lines 50,001-100,000: Order processing
# Lines 100,001-150,000: Payment handling
# Lines 150,001-200,000: Email templates (as strings)
# Lines 200,001-250,000: CSS (also as strings)
# Lines 250,001-300,000: Documentation (in comments)
# Lines 300,001-500,000: Test data (hardcoded)
class App:
def __init__(self):
self.users = {}
self.orders = {}
self.payments = {}
self.emails = {}
self.config = {}
self.cache = {}
self.database = None
self.http_client = None
self.logger = print
self.everything_else = {}
# ... 15,000 methods follow
As XKCD 1205 shows, time spent automating should be less than time spent doing. By having one file, you spend zero time navigating between files. That’s infinite ROI.
IDE Navigation: A Crutch for the Weak
“But how do you find anything in a 500,000 line file?”
Ctrl+F.
That’s it. That’s the whole system.
# My navigation workflow:
1. Ctrl+F
2. Type something that might be there
3. Press Enter 47 times
4. Hope
5. If not found, it doesn't exist
Modern IDEs with their “Go to Definition” and “Find All References” are just making developers lazy. Back in my day, we scrolled. For HOURS.
Real Project Structure
Here’s my production project:
legendary-ecommerce/
└── app.py (847,293 lines)
Compare this to a “modern” project:
modern-ecommerce/
├── src/
│ ├── controllers/
│ │ ├── user/
│ │ │ ├── __init__.py
│ │ │ ├── create.py
│ │ │ ├── read.py
│ │ │ └── ... (37 more files)
│ │ ├── order/
│ │ └── ... (500 more folders)
│ ├── services/
│ ├── repositories/
│ ├── domain/
│ ├── infrastructure/
│ └── ... (10,000 more files)
You know what the Pointy-Haired Boss from Dilbert would say? “I don’t understand either of these, but the one with fewer files looks simpler, so do that one.”
Version Control Benefits
With one file, merge conflicts are guaranteed, which means:
- All developers must coordinate every commit
- This forces communication
- Communication is a “best practice”
- Therefore, one file = best practice
# Git workflow with one file
git pull # CONFLICT in app.py
git stash
git pull
git stash pop # CONFLICT in app.py
# Repeat until someone rage quits
Performance Optimization
Compilers and interpreters love one file:
# No import overhead
# No file system lookups
# No module caching complexity
# Just 500,000 lines of pure, raw code
# Startup time: 47 minutes
# But only ONCE per deploy
Refactoring Made Simple
Need to refactor? In a multi-file project, you need to:
- Find all usages
- Update multiple files
- Fix imports
- Update tests
- Fix more imports
In a single file:
- Ctrl+H (Replace All)
- Done
The Ultimate One-Liner
Here’s my most elegant production code:
// app.js
eval(require('fs').readFileSync('all_the_code.txt', 'utf8').split('\n').map(line => line.trim()).filter(line => line && !line.startsWith('//')).join(';'))
One file. One line. One dream.
Conclusion
Stop creating files. Stop creating folders. Stop “organizing.” Every abstraction is a lie we tell ourselves to feel professional.
True senior engineers know: all code eventually becomes one giant ball of mud. Why fight the inevitable? Start there.
The author’s IDE crashed 47 times while writing this article. It kept running out of memory trying to syntax-highlight app.py.