Hi everyone! I’m Duc Minh, a 14-year-old developer. I recently finished a project called "Sofa King" – a premium e-commerce solution. Today, I want to share the technical journey and how I managed a complex architecture using Firebase.
Why I built Sofa King
I wanted to create a platform that empowers local artisans to transition to digital stores easily, focusing on high performance and rock-solid security.
The 72-File Architecture
Managing 72+ files as a solo developer was a challenge. I adopted an ES6 Module-based architecture to keep the logic clean and maintainable.
State Management: I used LocalStorage as a single source of truth for the cart logic to ensure zero-lag and offline resilience.
Modular Logic: Separate modules for Auth, Admin, and Security allowed me to scale the project without creating "Spaghetti code".
Security First with Firebase
Security isn't an afterthought. I implemented strict Server-side validation using Firebase Security Rules:
Role-Based Access (RBAC): Only whitelisted emails can access the Admin Dashboard.
Data Isolation: Users can only read their own order history.
Atomic Transactions: I used Firestore Transactions for the admin approval process to prevent "Race Conditions" and data corruption.
Technical Deep Dive: The Engineering
Building a production-ready platform as a solo developer required more than just coding; it required architectural foresight. Here is how I solved the core engineering challenges:
Managing Complexity in a 72-File Modular System
Moving away from a monolithic structure, I adopted an ES6 Module-based architecture. Each functionality (Auth, Cart, Admin, Security) is isolated into its own module. * The Challenge: Keeping the UI (like the Navbar cart count) in sync across 25+ HTML pages. * The Solution: I implemented a Shared State Management pattern using LocalStorage as a single source of truth for client-side data, allowing different modules to react to data changes without redundant database queries.Balancing Real-time Sync vs. Resource Efficiency
While Firestore offers onSnapshot, using it everywhere is expensive and can lead to performance bottlenecks. * The Strategy: I used a Hybrid Data Fetching approach. Critical business flows like Order Tracking utilize real-time listeners for instant feedback. For administrative actions (like Account Locking or Comment Deletion), I chose a Standard Fetch-and-Refresh flow to ensure data integrity and reduce long-lived connection overhead.Data Integrity with Atomic Transactions
In an e-commerce environment, a "Race Condition" (two people modifying the same data) can be fatal.
The Implementation: For the Admin Approval process, I used Firestore Transactions. When an order moves from 'pending' to 'history', the system ensures the entire operation succeeds as a single unit. If any part of the process fails, the database rolls back, preventing "ghost orders" or lost data.
Conclusion
Building this project taught me that even at 14, with the right tools like Firebase and a modular mindset, we can build professional-grade software.
Check out my project on GitHub: https://github.com/Duc-tech-hub/Sofa-King Live Demo: https://sofas-king.web.app
Top comments (0)