# telemarkfylke/hugin-svelte-web architecture

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

- Interactive diagram: https://gitdiagram.com/telemarkfylke/hugin-svelte-web
- Repository: https://github.com/telemarkfylke/hugin-svelte-web

## Overview

##### Main System Components

a) Frontend Layer (Svelte Application)
- Client-side routing structure
- Authentication system (MSAL)
- UI Components
- Service integrations

b) External Services Integration
- OpenAI integration
- Mistral integration
- Kildekall integration
- Backend API communication

##### Architectural Structure

a) Core Layers (Top to Bottom):
**User Interface Layer**

**Authentication Layer (MSAL)**

**Service Integration Layer**

**External Services/APIs**

b) Component Organization:

Frontend Components (Left side):
- Home
- Chat
- Document Query
- Labs
- Transcription
- About

Service Layer (Middle):
- useApi.js (API communication handler)
- Authentication services
- Model information services

External Services (Right side):
- OpenAI
- Mistral
- Kildekall
- Backend API

##### Specific Elements

- Blue: Core frontend components
- Green: Authentication components
- Yellow: Service integrations
- Gray: External services
- Purple: Routing components

b) Connection Types:

##### Key Relationships to Highlight

- How the authentication flow integrates with the MSAL system
- How the service layer connects to external APIs
- Demonstrate the relationship between routes and their corresponding service integrations
- How the component library is utilized across different routes

##### Important Architectural Patterns

- The SPA (Single Page Application) nature of the Svelte framework
- The service-oriented architecture for external API integration
- The component-based structure of the UI
- The centralized authentication system

##### Technical Stack Indicators

- Svelte/SvelteKit
- MSAL Authentication
- Vite build system
- Vercel hosting
- External API integrations

##### Data Flow Patterns

Illustrate:
- User authentication flow
- API request/response patterns
- Document upload/processing flow
- Chat interaction flow
- Transcription processing

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "User Interface Layer"
        UI[User Interface]
        Layout["Main Layout"]:::layout
        click Layout "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/routes/+layout.svelte"
    end

    subgraph "Routes"
        Home["Home"]:::route
        Chat["Chat"]:::route
        DocQuery["Document Query"]:::route
        Labs["Labs"]:::route
        Transcript["Transcription"]:::route
        About["About"]:::route

        click Home "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/routes/+page.svelte"
        click DocQuery "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/routes/docQuery/+page.svelte"
        click Labs "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/routes/labs/+page.svelte"
        click Transcript "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/routes/transcript/+page.svelte"
        click About "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/routes/about/+page.svelte"
    end

    subgraph "Authentication Layer"
        MSAL["MSAL Authentication"]:::auth
        click MSAL "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/lib/auth/msal-auth.js"
    end

    subgraph "Component Layer"
        BaseComp["Base Components"]:::component
        ChatBlobs["Chat Interface"]:::component
        ModelInfo["Model Information Display"]:::component

        click BaseComp "https://github.com/telemarkfylke/hugin-svelte-web/tree/main/src/lib/components/"
        click ChatBlobs "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/lib/components/ChatBlobs.svelte"
        click ModelInfo "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/lib/components/ModelInfo.svelte"
    end

    subgraph "Service Integration Layer"
        ApiHandler["API Communication Handler"]:::service
        OpenAIService["OpenAI Integration"]:::service
        MistralService["Mistral Integration"]:::service
        KildekallService["Kildekall Integration"]:::service
        LabsTools["OpenAI Labs Tools"]:::service

        click ApiHandler "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/lib/useApi.js"
        click OpenAIService "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/lib/services/openAiTools.js"
        click MistralService "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/lib/services/mistralTools.js"
        click KildekallService "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/lib/services/kildekallTools.js"
        click LabsTools "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/lib/services/openaiToolsLabs.js"
    end

    subgraph "Model Information Services"
        ModelInfoService["Model Information"]:::modelinfo
        ModelParams["Model Parameters"]:::modelinfo

        click ModelInfoService "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/lib/data/modelinfo.js"
        click ModelParams "https://github.com/telemarkfylke/hugin-svelte-web/blob/main/src/lib/data/modelparams.js"
    end

    subgraph "External Services"
        OpenAI["OpenAI API"]:::external
        Mistral["Mistral API"]:::external
        Kildekall["Kildekall API"]:::external
        Backend["Backend API"]:::external
    end

    UI --> Layout
    Layout --> Home & Chat & DocQuery & Labs & Transcript & About
    UI --> MSAL
    
    MSAL --> ApiHandler
    
    ApiHandler --> OpenAIService & MistralService & KildekallService
    Labs --> LabsTools
    
    OpenAIService --> OpenAI
    MistralService --> Mistral
    KildekallService --> Kildekall
    ApiHandler --> Backend
    
    ModelInfoService --> ModelInfo
    ModelParams --> ModelInfo
    
    Chat & DocQuery & Labs & Transcript --> BaseComp
    Chat --> ChatBlobs
    Chat & DocQuery & Labs --> ModelInfo

    classDef route fill:#9370DB,stroke:#333,stroke-width:2px
    classDef auth fill:#90EE90,stroke:#333,stroke-width:2px
    classDef component fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef service fill:#FFD700,stroke:#333,stroke-width:2px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef modelinfo fill:#FFA07A,stroke:#333,stroke-width:2px
    classDef layout fill:#20B2AA,stroke:#333,stroke-width:2px
```
