From 750 Lines to 60: Component Extraction
How reorganizing my Astro page into components made the codebase maintainable.
April 28, 2025 1 min read
195 words
#refactoring
#astro
#architecture
The Problem
My index.astro had grown to 750 lines. Hero, About, Work, Contact, Logs—all inline in one file.
Changing one section meant scrolling through hundreds of lines. Finding bugs was a treasure hunt.
The Solution
Extract everything into composable components. No barrel files, no unnecessary abstractions—just logical grouping.
src/components/
├── header/
├── footer/
├── sections/
│ ├── hero/
│ ├── work/
│ ├── About.astro
│ ├── Contact.astro
│ └── Logs.astro
└── terminal/
Results
| Metric | Before | After |
|---|---|---|
| index.astro lines | 750 | 60 |
| Component files | 0 | 12 |
| Average file size | 750 lines | ~40 lines |
Key Principles
- No barrel files (
index.ts)—just import directly - Flat over nested—
sections/work/, notsections/work/components/ - Co-locate by usage—components live where they’re used
- Delete dead code—if it’s not used, it’s gone
The codebase now feels lightweight. Each component has one responsibility, one file, one purpose.