Overview
Taskflow uses the browser’s localStorage API to persist tasks between sessions. All data is stored client-side as JSON-stringified arrays with no backend server required.Storage Architecture
Key-Value Structure
Taskflow stores two pieces of data in localStorage:| Key | Value Type | Purpose |
|---|---|---|
tareas | JSON string (array) | All task objects |
tema | String ('dark' or 'light') | User’s theme preference |
Task Data Format
Each task is stored as a JavaScript object within thetareas array:
Task Object Structure
localStorage['tareas'] Example
Core Storage Functions
guardarEnStorage()
Saves the currenttareas array to localStorage:
app.js:12-14
How it works
How it works
- Serialization:
JSON.stringify()converts the JavaScript array to a JSON string - Storage:
localStorage.setItem()saves the string with the key'tareas' - Persistence: Data survives browser restarts and page refreshes
When is it called?
Every time tasks are modified:- ✅ Adding a task (app.js:65)
- ✅ Completing/uncompleting a task (app.js:44)
- ✅ Deleting a task (app.js:49)
- ✅ First load with default data (app.js:127)
cargarTareas()
Loads tasks from localStorage or seeds default data on first run:app.js:117-136
Parse or use defaults
- If data exists:
JSON.parse(guardadas)deserializes the string back to an array - If no data: Use the hardcoded default tasks array
Save defaults if needed
If this is the first load (
!guardadas), save the default tasks to localStorageTheme Persistence
The user’s theme preference is also stored in localStorage:app.js:104-114
Initialization: On page load (line 110), the app checks
localStorage.getItem('tema') and applies the saved preference immediately before tasks render.Default Data Seeding
When a user visits the app for the first time (notareas key in localStorage), four default tasks are created:
Default Tasks
- Demonstrate the app’s functionality immediately
- Show examples of different priorities and categories
- Are saved to localStorage on first load (app.js:127)
Storage Workflow
ID Generation
New tasks use timestamps for unique IDs:app.js:63
Storage Limits & Considerations
Storage Capacity
Storage Capacity
- Typical limit: 5-10 MB per origin across all localStorage keys
- Taskflow usage: Even 1,000 tasks would be ~100KB (well within limits)
- No warning: Browser silently fails if quota exceeded
Performance
Performance
- Synchronous API:
localStorage.getItem()andsetItem()block the main thread - Impact: Negligible for small datasets like task lists
- Alternative: IndexedDB for larger datasets (not needed here)
Security
Security
- No encryption: Data stored as plain text
- Same-origin policy: Only accessible by the same domain/protocol/port
- Not for sensitive data: Avoid storing passwords, tokens, or PII
Data Integrity
Data Integrity
- No validation: App doesn’t validate JSON structure on load
- Manual corruption: Users can edit localStorage via DevTools
- Potential improvement: Add try-catch around
JSON.parse()
Debugging Storage
View localStorage in DevTools
Console Commands
View all tasks in console
Clear all tasks
Reset to defaults
localStorage vs Alternatives
✅ localStorage (Current)
Pros:
- Simple API
- Synchronous (no async complexity)
- Persistent across sessions
- Perfect for small datasets
- Not synced across devices
- String-only storage
- Size limits (5-10MB)
sessionStorage
Pros:
- Same API as localStorage
- Per-tab isolation
- Data lost on tab close ❌
- Not suitable for Taskflow
IndexedDB
Pros:
- Much larger storage
- Structured data (objects, indexes)
- Async (non-blocking)
- More complex API ❌
- Overkill for simple task lists
Backend Database
Pros:
- Cross-device sync
- Backup/restore capabilities
- User authentication
- Requires server infrastructure ❌
- Network dependency
- More complex architecture
Verdict: localStorage is the ideal choice for Taskflow’s requirements - simple, persistent, and sufficient for local task management.