# szuhaydv/mrchili-v2 architecture

> Architecture diagram of the GitHub repository szuhaydv/mrchili-v2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/szuhaydv/mrchili-v2
- Repository: https://github.com/szuhaydv/mrchili-v2

## Overview

##### Project Type and Purpose
- This is a full-stack SvelteKit web application.
- The frontend is built with Svelte components (under src/routes and src/lib).
- The backend is lightweight, using SvelteKit’s filesystem-based server routes for API endpoints (e.g. send-email).
- Purpose: a content-driven site (product catalog, cart, order pages) with email notifications.

##### High-Level Architecture Components
a. Frontend Layer
- Svelte components under src/routes (+layout, +page files, UI components like HeaderComponent, CardComponent, etc.)
- Styling: Tailwind CSS (tailwind.config.ts) + global input.css
- Static assets under static/ (PDFs, images, etc.)
b. Backend/API Layer
- Server endpoints in src/routes/api/send-email/+server.js – processes form submissions
- Utility module src/lib/utils/send-email.server.js – encapsulates email-sending logic
- Data services in src/routes/dataService.ts and src/routes/cartService.ts – business logic for products, cart
- Email templates in src/routes/order/emailTemplates.js
c. Build & Deployment
- Vite as build tool (vite.config.ts)
- SvelteKit config (svelte.config.js) – defines adapter, SSR options
d. External Services
- Email provider (e.g. SendGrid/Mailgun) invoked by send-email.server.js
- Potential payment gateway (not shown but cart/order services could integrate)

##### Relationships & Data Flows
- User’s browser sends HTTP requests for pages; SvelteKit renders SSR or serves static JS/CSS.
- Interaction with site (contact form, placing order) triggers fetch() calls to /api/send-email or other endpoints.
- API layer calls into dataService/cartService for business logic, then into utils/send-email.server.js for outbound emails.
- Email provider responds; API returns status to the frontend.
- Cart state may live client-side (using sessionStorage) or server-session via cookies/hooks.server.js.

##### Architectural Patterns & Principles
- Filesystem-based routing: src/routes directory maps URL paths to endpoints and pages.
- Separation of concerns:
- UI components in routes and lib/components
- Business logic in service modules (dataService, cartService)
- Infrastructure logic (email transport) in server utilities
- SSR + SPA: SvelteKit handles SSR for faster loads, then hydrates to SPA.
- Convention over configuration: minimal routing config; uses SvelteKit defaults.

##### Elements
- Clear labels: e.g. “Contact Page (+page.svelte)”, “Email API (/api/send-email)”

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef server fill:#d4edda,stroke:#333,stroke-width:1px
    classDef external fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef infra fill:#f0f0f0,stroke:#333,stroke-width:1px

    subgraph "Browser / Client" 
        direction TB
        Browser["User Browser"]:::frontend
        subgraph "Pages & Components"
            direction TB
            Layout["+layout.svelte"]:::frontend
            Loader["+layout.js"]:::frontend
            RootPage["+page.svelte"]:::frontend
            About["+page.svelte (about)"]:::frontend
            Contact["+page.svelte (contact)"]:::frontend
            Chilies["+page.svelte (chilies)"]:::frontend
            Products["+page.svelte (products)"]:::frontend
            ProductDetail["+page.svelte (products/[slug])"]:::frontend
            OrderPage["+page.svelte (order)"]:::frontend
            Header["HeaderComponent.svelte"]:::frontend
            Footer["FooterComponent.svelte"]:::frontend
            Card["CardComponent.svelte"]:::frontend
            Accordion["AccordionComponent.svelte"]:::frontend
            CTA["CallToAction.svelte"]:::frontend
            Review["ReviewComponent.svelte"]:::frontend
            Hamburger["Hamburger.svelte"]:::frontend
            ChiliCard["ChiliCard.svelte"]:::frontend
            OrderSummary["OrderSummary.svelte"]:::frontend
        end
        subgraph "Styling & Assets"
            direction TB
            Styles["input.css"]:::frontend
            Tailwind["tailwind.config.ts"]:::frontend
            Static["Static Assets"]:::frontend
        end
    end

    subgraph "SvelteKit Server" 
        direction TB
        Server["Routing & Rendering Engine"]:::server
        subgraph "API Handlers"
            direction TB
            SendEmail["/api/send-email +server.js"]:::server
        end
        subgraph "Service Modules"
            direction TB
            DataService["dataService.ts"]:::server
            CartService["cartService.ts"]:::server
            EmailTemplates["emailTemplates.js"]:::server
        end
        subgraph "Utilities"
            direction TB
            EmailUtil["send-email.server.js"]:::server
            Hooks["hooks.server.js"]:::server
        end
        subgraph "Build & Config"
            direction TB
            Vite["vite.config.ts"]:::infra
            SvelteConfig["svelte.config.js"]:::infra
        end
    end

    subgraph "External Services"
        direction TB
        EmailProvider["Email Provider"]:::external
        PaymentGateway["Payment Gateway"]:::external
    end

    %% Relationships
    Browser -->|"HTTP GET Pages"| Server
    Server -->|"render SSR / serve static"| Browser
    Contact -->|"form POST"| SendEmail
    SendEmail -->|"call sendEmail()"| EmailUtil
    SendEmail -->|"use templates"| EmailTemplates
    SendEmail -->|"business logic"| CartService
    SendEmail --> EmailProvider
    Browser -->|"fetch cart/products"| Server
    Server --> CartService
    Server --> DataService
    CartService --> PaymentGateway
    Browser --> Static
    Server --> Static
    Browser --> Styles
    Browser --> Tailwind

    %% Click Events
    click Layout "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/+layout.svelte"
    click Loader "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/+layout.js"
    click RootPage "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/+page.svelte"
    click Static "https://github.com/szuhaydv/mrchili-v2/tree/main/static/"
    click Styles "https://github.com/szuhaydv/mrchili-v2/blob/main/src/input.css"
    click Tailwind "https://github.com/szuhaydv/mrchili-v2/blob/main/tailwind.config.ts"
    click Vite "https://github.com/szuhaydv/mrchili-v2/blob/main/vite.config.ts"
    click SvelteConfig "https://github.com/szuhaydv/mrchili-v2/blob/main/svelte.config.js"
    click Header "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/HeaderComponent.svelte"
    click Footer "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/FooterComponent.svelte"
    click Card "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/CardComponent.svelte"
    click Accordion "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/AccordionComponent.svelte"
    click CTA "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/CallToAction.svelte"
    click Review "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/ReviewComponent.svelte"
    click Hamburger "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/Hamburger.svelte"
    click ChiliCard "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/ChiliCard.svelte"
    click About "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/about/+page.svelte"
    click Contact "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/contact/+page.svelte"
    click Chilies "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/chilies/+page.svelte"
    click Products "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/products/+page.svelte"
    click ProductDetail "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/products/[slug]/+page.svelte"
    click OrderPage "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/order/+page.svelte"
    click OrderSummary "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/order/OrderSummary.svelte"
    click EmailTemplates "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/order/emailTemplates.js"
    click SendEmail "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/api/send-email/+server.js"
    click EmailUtil "https://github.com/szuhaydv/mrchili-v2/blob/main/src/lib/utils/send-email.server.js"
    click DataService "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/dataService.ts"
    click CartService "https://github.com/szuhaydv/mrchili-v2/blob/main/src/routes/cartService.ts"
    click Hooks "https://github.com/szuhaydv/mrchili-v2/blob/main/src/hooks.server.js"
```
