How dno8/ecommerce-demo works
Project Type and Purpose
• This is a full-stack e-commerce web application (“Tienda online”) built as a technical exercise.
• Frontend is a Lit-powered SPA (single-page app) using page.js for in-browser routing.
• Backend is a Node.js HTTP server exposing MVC-style REST endpoints for payment (Flow) and shipping (Shipit).
• Static assets (HTML, CSS, fonts, images, JSON data) live under the public folder.
File-Structure Analysis
• “src/index.mjs” and “index.html” bootstrap the SPA.
• “src/routes/…-routes.mjs”: client-side router setup (page.js) and API route definitions.
• “src/API/Flow” + “src/API/Shipit”: server-side controllers & models handling integration with external services.
• “src/server/server.mjs”: Node.js express-style server that wires up controllers to HTTP endpoints.
• “src/Views”: Lit view components and layouts per page (Landing, Shop, About, Purchase).
• “src/utils”: reusable UI components (navbar, cart button, dropdown) and config (GSAP).
• “src/schemas”: Zod schemas for request validation (e.g., shipit payloads).
README Insights
• MVC architecture emphasis, separation of concerns.
• Integrations: Flow payment gateway and Shipit shipping calculator.
• Responsive design, data from JSON, environment variables for API keys.
• Build & run: npm start for frontend dev server, node --watch for backend.
a. Main Components
• Frontend SPA (Lit + page.js)
• Backend API Server (Node.js + controllers/models)
• Static Asset Server (serving public/*) – often the same Node server or separate CDN
• Data Layer (JSON files + Zod validation)
• External Services: Flow API, Shipit API
b. Relationships & Interactions
1. User’s browser loads index.html → boots Lit SPA.
2. SPA routes (Landing, Shop, About, Purchase) fetch product data (public/data/*.json) client-side or via API.
3. Upon checkout: SPA calls backend endpoint (/api/flow/process, /api/shipit/calculate).
4. Backend controller uses model to call Flow or Shipit over HTTPS.
5. Backend returns status/confirmation to SPA → SPA updates UI.
c. Architectural Patterns & Principles
• MVC on server: controllers delegate to models, models encapsulate business/external-API logic.
• Client-side component-based UI (Lit) with utility components for reuse.
• JSON-based data store for products/regions.
• Environment-based configuration (.env) for secrets.
d. Technologies & Frameworks
• Frontend: Lit, page.js
• Backend: Node.js (ESM .mjs), express-style routing (custom or imported), Zod for validation
• External: Flow API, Shipit API
• Build/tools: npm scripts, node --watch