-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor Plan
- β 106 lines of CSS inline
- β 829 lines of JavaScript inline
- β Violates separation of concerns
- β Hard to maintain and debug
- β Poor caching strategy (entire file invalidated on any change)
flight_budget/
βββ index.html β App file
βββ libs/ β App dependencies
βββ data/ β App data
βββ nginx/ β Infrastructure
βββ Dockerfile β Infrastructure
βββ docker-compose.yml β Infrastructure
βββ README.md β Documentation
βββ DEPLOYMENT.md β Documentation
βββ QUICK_START.md β Documentation
βββ TODO.md β Documentation
βββ CONTAINER_SETUP.md β Documentation
βββ PROJECT_STRUCTURE.md β Documentation
Problems:
- App files mixed with infrastructure
- Documentation cluttering root
- No clear boundaries
- Hard to navigate
flight_budget/
βββ π app/ β Application files (deployed)
β βββ index.html β HTML only (~350 lines)
β βββ css/
β β βββ styles.css β Extracted CSS (~110 lines)
β βββ js/
β β βββ app.js β Extracted JS (~830 lines)
β βββ libs/ β JavaScript dependencies
β β βββ papaparse.min.js
β β βββ chart.umd.min.js
β β βββ html2pdf.bundle.min.js
β βββ data/ β Persistent data (volume mount)
β βββ .gitkeep
β
βββ π docs/ β Documentation (NOT deployed)
β βββ README.md
β βββ DEPLOYMENT.md
β βββ QUICK_START.md
β βββ CONTAINER_SETUP.md
β βββ PROJECT_STRUCTURE.md
β βββ REFACTOR_PLAN.md
β βββ TODO.md
β
βββ π infrastructure/ β Docker/deployment configs
β βββ nginx/
β β βββ nginx.conf
β βββ Dockerfile
β βββ docker-compose.yml
β
βββ π .github/ β CI/CD
β βββ workflows/
β βββ docker-build.yml
β βββ update-dependencies.yml
β
βββ .dockerignore
βββ .env.example
βββ .gitignore
βββ README.md β Short readme pointing to docs/
β HTML for structure β CSS for styling β JavaScript for behavior β Each file has single responsibility
β CSS changes don't invalidate HTML cache β JS changes don't invalidate CSS cache β Browser caches files independently β Faster load times after first visit
β Easier to find and edit code β Syntax highlighting works better in separate files β Easier for multiple developers to work simultaneously β Easier to debug (browser dev tools work better)
β Clear separation: app vs infrastructure vs docs β Docker builds only what's needed β Documentation doesn't clutter root β Easier to navigate project
β Industry standard structure β Easier for new developers to understand β Better for code reviews β Scalable for future growth
- Create
app/css/styles.css- extract lines 10-116 from index.html - Create
app/js/app.js- extract lines 451-1280 from index.html - Update
app/index.html- link to external files - Move
index.htmlβapp/index.html - Move
libs/βapp/libs/ - Move
data/βapp/data/
- Create
infrastructure/folder - Move
Dockerfileβinfrastructure/Dockerfile - Move
docker-compose.ymlβinfrastructure/docker-compose.yml - Move
nginx/βinfrastructure/nginx/ - Update paths in Dockerfile and compose file
- Create
docs/folder - Move all
.mdfiles (except root README) βdocs/ - Create short root
README.mdpointing to docs - Update internal links in documentation
- Update Dockerfile to copy from
app/directory - Update nginx.conf if needed (should work as-is)
- Update .dockerignore to exclude docs and infrastructure
- Update GitHub Actions paths
- Build Docker image locally
- Test all functionality
- Verify caching headers work
- Check file paths in browser console
- Test CSV upload/download
- Test PDF export
index.html: 72KB (1,281 lines)
Total loaded: 72KB on every page load
index.html: ~15KB (350 lines)
styles.css: ~5KB (110 lines)
app.js: ~25KB (830 lines)
βββββββββββββββββββββββββββββββ
Total: ~45KB (40% smaller!)
After gzip:
index.html: ~5KB
styles.css: ~2KB
app.js: ~8KB
βββββββββββββββββββββββββββββββ
Total: ~15KB (80% smaller!)
Caching Benefits:
- First visit: 45KB download
- Return visits: ~15KB (only HTML if JS/CSS cached)
- After code change: Only changed file re-downloaded
Browser loads:
1. index.html (72KB) - contains everything
Total: 72KB every time
First visit:
1. index.html (15KB)
2. styles.css (5KB) - cached for 1 year
3. app.js (25KB) - cached for 1 year
Total: 45KB first time
Return visits:
1. index.html (15KB) - no cache (always fresh)
2. styles.css - from cache (0KB)
3. app.js - from cache (0KB)
Total: 15KB (70% faster!)
Base: 23MB
App: 72KB (index.html) + 1.1MB (libs)
Total: ~25MB
Base: 23MB
App: 45KB (html+css+js) + 1.1MB (libs)
Total: ~24MB (slightly smaller)
Note: Image size improvement is minimal, but organization is much better.
location / {
# No cache for HTML
add_header Cache-Control "no-cache, no-store, must-revalidate";
}# HTML - always fetch fresh
location ~ \.html$ {
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# CSS/JS - cache for 1 year (immutable)
location ~ \.(css|js)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# JS libraries - cache for 1 year
location ^~ /libs/ {
expires 1y;
add_header Cache-Control "public, immutable";
}| Task | Complexity | Time | Risk |
|---|---|---|---|
| Extract CSS | Low | 15 min | None |
| Extract JS | Low | 15 min | None |
| Reorganize folders | Low | 30 min | Low |
| Update Dockerfile | Medium | 30 min | Medium |
| Update nginx.conf | Low | 15 min | Low |
| Update docs | Low | 30 min | None |
| Test everything | Medium | 1 hour | - |
| Total | Low-Medium | ~3 hours | Low |
The refactoring should be transparent to users:
- Same functionality
- Same URLs
- Same behavior
- Better performance
- Better maintainability
- β All features work identically
- β CSV import/export
- β PDF generation
- β Save/load budgets
- β Docker deployment process
- β Portainer compatibility
- β Faster load times (caching)
- β Easier to maintain
- β Better debugging
- β Professional structure
- β Ready for future features
Reasons:
- Early in project lifecycle - easier now than later
- No users yet - no breaking changes to worry about
- Industry best practice - should have been done initially
- Better for future - easier to add features
- Low risk - straightforward changes
- Quick - only ~3 hours of work
- Professional - looks better to contributors/employers
Only if:
- β Project is throw-away/temporary
- β Only you will ever work on it
- β No plans to add features
- β Performance doesn't matter
But this doesn't apply because:
- β You're deploying to production (Portainer)
- β You're setting up CI/CD (GitHub Actions)
- β You created comprehensive documentation
- β You're asking about best practices
- Review this plan - make sure you agree with approach
- Backup current state - commit to git first
- Implement refactoring - follow phase-by-phase plan
- Test locally - ensure everything works
- Update documentation - reflect new structure
- Deploy - push to GitHub, auto-deploy via CI/CD
Before proceeding, decide:
-
Do you want to refactor now or after initial deployment?
- Recommendation: Now (easier and cleaner)
-
Keep flat structure or use app/ folder?
- Recommendation: Use app/ folder (professional)
-
Move docs to docs/ or keep in root?
- Recommendation: Move to docs/ (cleaner root)
-
Extract CSS/JS or keep inline?
- Recommendation: Extract (best practice)
Decision needed: Should we proceed with the refactor?
If YES, I can implement all changes in ~30-60 minutes with zero breaking changes.
If NO, we can keep current structure and proceed to deployment.
My recommendation: Refactor now. It's the right time and right approach.
π View on GitHub | π³ Docker Hub
π Report Issue | π¬ Discussions
License: MIT License | Copyright (c) 2024-2025 FliteAxis
π Getting Started
π¦ Deployment
π§ Development
π Security
- Security Setup Guide
- Security CI/CD Pipeline
- Code Quality & Linting
- SBOM Management
- Vulnerability Scanning
π Dependencies
π³ Docker
π Reference
π Links