# dno8/ecommerce-demo architecture

> Architecture diagram of the GitHub repository dno8/ecommerce-demo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dno8/ecommerce-demo
- Repository: https://github.com/dno8/ecommerce-demo

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side" 
        direction TB
        Browser["User's Browser"]:::external
        indexHTML["index.html"]:::frontend
        SPA["src/index.mjs"]:::frontend
        Browser -->|"loads"| indexHTML
        indexHTML -->|"boots SPA"| SPA

        subgraph "Router (page.js)" 
            direction TB
            Routes["src/routes/routes.js"]:::frontend
            FlowRoutes["src/routes/flow-routes.mjs"]:::frontend
            ShipitRoutes["src/routes/shipit-routes.mjs"]:::frontend
        end
        SPA -->|"uses page.js"| Routes
        SPA --> FlowRoutes
        SPA --> ShipitRoutes

        subgraph "Views (Lit Components)"
            direction TB
            LandingLayout["landing-view.js"]:::frontend
            Carrousel["carrousel-component.js"]:::frontend
            Description["description-component.js"]:::frontend
            ShopLayout["shop-view.js"]:::frontend
            GridShop["grid-shop.js"]:::frontend
            ProductCard["product-card.js"]:::frontend
            ProductDetail["producto-detalle.js"]:::frontend
            AboutLayout["aboutact-view.js"]:::frontend
            CorreoComp["correo-component.js"]:::frontend
            PurchaseLayout["purchase-view.js"]:::frontend
            CourierList["courier-list.js"]:::frontend
            FormEnvio["formulario-envio.js"]:::frontend
        end
        Routes --> LandingLayout
        LandingLayout --> Carrousel
        LandingLayout --> Description
        Routes --> ShopLayout
        ShopLayout --> GridShop
        ShopLayout --> ProductCard
        ShopLayout --> ProductDetail
        Routes --> AboutLayout
        AboutLayout --> CorreoComp
        Routes --> PurchaseLayout
        PurchaseLayout --> CourierList
        PurchaseLayout --> FormEnvio

        subgraph "Utils (UI Components)"
            direction TB
            CartBtn["cart-button.js"]:::frontend
            Dropdown["dropdown-component.js"]:::frontend
            Navbar["navbar-component.js"]:::frontend
            TitleComp["title-component.js"]:::frontend
            LiquidBtn["liquid-button.js"]:::frontend
            GSAPConfig["gsap-config.js"]:::frontend
        end
        LandingLayout --> CartBtn
        ShopLayout --> CartBtn
        PurchaseLayout --> CartBtn
        LandingLayout --> Navbar
        ShopLayout --> Navbar
        AboutLayout --> Navbar
        PurchaseLayout --> Navbar

        subgraph "Static Data" 
            direction TB
            ProdJSON["productos.json"]:::datastore
            ProdJS["productos.js"]:::datastore
            Direcciones["direcciones.mjs"]:::datastore
            Regiones["regionesyciudades.json"]:::datastore
        end
        ShopLayout -->|"fetches"| ProdJSON
        ShopLayout --> ProdJS
        PurchaseLayout --> Direcciones
        PurchaseLayout --> Regiones
    end

    %% Server Side
    subgraph "Server Side" 
        direction TB
        HTTPServer["src/server/server.mjs"]:::server
        HTTPServer -->|"serves static assets"| StaticAssets
        HTTPServer -->|"routes"| ServerRouter
        subgraph "Server Router"
            direction TB
            APIFlowRoute["/api/flow"]:::server
            APIShipitRoute["/api/shipit"]:::server
        end
        ServerRouter --> APIFlowRoute
        ServerRouter --> APIShipitRoute

        APIFlowRoute --> Zod["src/schemas/ShipitSchemas.mjs"]:::datastore
        APIFlowRoute --> FlowController["FlowControllerDemo.mjs"]:::server
        FlowController --> FlowModel["FlowModelDemo.mjs"]:::server
        FlowModel --> FlowAPI["Flow API"]:::external

        APIShipitRoute --> Zod
        APIShipitRoute --> ShipitController["shipitDemo.mjs"]:::server
        ShipitController --> ShipitModel["shipitModelDemo.mjs"]:::server
        ShipitModel --> ShipitAPI["Shipit API"]:::external

        subgraph "Static Asset Server"
            direction TB
            StaticCSS["estilos-belen-arte.css"]:::datastore
            Fonts["public/fonts/"]:::datastore
            Icons["public/icons/"]:::datastore
            Images["public/images/"]:::datastore
            PagoOK["pago-exitoso.html"]:::datastore
        end
        StaticAssets --> StaticCSS
        StaticAssets --> Fonts
        StaticAssets --> Icons
        StaticAssets --> Images
        StaticAssets --> PagoOK
    end

    %% Browser to API calls
    Browser -->|"/api/flow/process"| APIFlowRoute
    Browser -->|"/api/shipit/calculate"| APIShipitRoute
    FlowAPI -->|response| Browser
    ShipitAPI -->|response| Browser

    %% Asset fetch
    Browser -->|"GET static"| StaticCSS
    Browser --> Fonts
    Browser --> Icons
    Browser --> Images

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#006064
    classDef server fill:#E8F5E9,stroke:#1B5E20,color:#1B5E20
    classDef external fill:#FFF3E0,stroke:#E65100,color:#E65100
    classDef datastore fill:#ECEFF1,stroke:#455A64,color:#455A64

    %% Click Events
    click indexHTML "https://github.com/dno8/ecommerce-demo/blob/master/index.html"
    click SPA "https://github.com/dno8/ecommerce-demo/blob/master/src/index.mjs"
    click Routes "https://github.com/dno8/ecommerce-demo/blob/master/src/routes/routes.js"
    click FlowRoutes "https://github.com/dno8/ecommerce-demo/blob/master/src/routes/flow-routes.mjs"
    click ShipitRoutes "https://github.com/dno8/ecommerce-demo/blob/master/src/routes/shipit-routes.mjs"
    click LandingLayout "https://github.com/dno8/ecommerce-demo/blob/master/src/Views/Landing/Layout/landing-view.js"
    click Carrousel "https://github.com/dno8/ecommerce-demo/blob/master/src/Views/Landing/components/carrousel-component.js"
    click Description "https://github.com/dno8/ecommerce-demo/blob/master/src/Views/Landing/components/description-component.js"
    click ShopLayout "https://github.com/dno8/ecommerce-demo/blob/master/src/Views/Shop/Layout/shop-view.js"
    click GridShop "https://github.com/dno8/ecommerce-demo/blob/master/src/Views/Shop/components/grid-shop.js"
    click ProductCard "https://github.com/dno8/ecommerce-demo/blob/master/src/Views/Shop/components/product-card.js"
    click ProductDetail "https://github.com/dno8/ecommerce-demo/blob/master/src/Views/Shop/components/producto-detalle.js"
    click AboutLayout "https://github.com/dno8/ecommerce-demo/blob/master/src/Views/Aboutact/Layout/aboutact-view.js"
    click CorreoComp "https://github.com/dno8/ecommerce-demo/blob/master/src/Views/Aboutact/components/correo-component.js"
    click PurchaseLayout "https://github.com/dno8/ecommerce-demo/blob/master/src/Views/purchase/layout/purchase-view.js"
    click CourierList "https://github.com/dno8/ecommerce-demo/blob/master/src/Views/purchase/components/courier-list.js"
    click FormEnvio "https://github.com/dno8/ecommerce-demo/blob/master/src/Views/purchase/components/formulario-envio.js"
    click CartBtn "https://github.com/dno8/ecommerce-demo/blob/master/src/utils/components/cart-button.js"
    click Dropdown "https://github.com/dno8/ecommerce-demo/blob/master/src/utils/components/dropdown-component.js"
    click Navbar "https://github.com/dno8/ecommerce-demo/blob/master/src/utils/navbar-component.js"
    click TitleComp "https://github.com/dno8/ecommerce-demo/blob/master/src/utils/title-component.js"
    click LiquidBtn "https://github.com/dno8/ecommerce-demo/blob/master/src/utils/liquid-button.js"
    click GSAPConfig "https://github.com/dno8/ecommerce-demo/blob/master/src/utils/gsap-config.js"
    click ProdJSON "https://github.com/dno8/ecommerce-demo/blob/master/public/data/productos.json"
    click ProdJS "https://github.com/dno8/ecommerce-demo/blob/master/public/data/productos.js"
    click Direcciones "https://github.com/dno8/ecommerce-demo/blob/master/public/data/direcciones.mjs"
    click Regiones "https://github.com/dno8/ecommerce-demo/blob/master/public/data/regionesyciudades.json"
    click Zod "https://github.com/dno8/ecommerce-demo/blob/master/src/schemas/ShipitSchemas.mjs"
    click HTTPServer "https://github.com/dno8/ecommerce-demo/blob/master/src/server/server.mjs"
    click FlowController "https://github.com/dno8/ecommerce-demo/blob/master/src/API/Flow/controllers/FlowControllerDemo.mjs"
    click FlowModel "https://github.com/dno8/ecommerce-demo/blob/master/src/API/Flow/model/FlowModelDemo.mjs"
    click ShipitController "https://github.com/dno8/ecommerce-demo/blob/master/src/API/Shipit/controllers/shipitDemo.mjs"
    click ShipitModel "https://github.com/dno8/ecommerce-demo/blob/master/src/API/Shipit/model/shipitModelDemo.mjs"
    click StaticCSS "https://github.com/dno8/ecommerce-demo/blob/master/public/styles/estilos-belen-arte.css"
    click Fonts "https://github.com/dno8/ecommerce-demo/tree/master/public/fonts/"
    click Icons "https://github.com/dno8/ecommerce-demo/tree/master/public/icons/"
    click Images "https://github.com/dno8/ecommerce-demo/tree/master/public/images/"
    click PagoOK "https://github.com/dno8/ecommerce-demo/blob/master/public/pago-exitoso.html"
```
