# brunostjohn/perplexideez architecture

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

- Interactive diagram: https://gitdiagram.com/brunostjohn/perplexideez
- Repository: https://github.com/brunostjohn/perplexideez

## Overview

##### Project Type and Purpose
- This is a monolithic full-stack web application built with SvelteKit that provides a self-hosted AI-powered search experience.
- It integrates with a Postgres database for persistence, a SearXNG search microservice for web searches, and an LLM provider (Ollama or OpenAI) for generating responses.
- It supports multi-user authentication (AuthJS/OIDC) and is deployed via Docker Compose or Kubernetes.

##### Top-Level Components
a. Client (Browser)
- Renders the SvelteKit front end (HTML/CSS/JS).
- Initiates API calls (tRPC) for data, search, and AI interactions.
b. SvelteKit Server
- Routes and SSR (src/routes, +layout, +page).
- tRPC API layer (src/lib/trpc/router.ts).
- AuthJS/OIDC middleware (src/lib/auth.ts, hooks.server.ts).
- Metrics endpoint for Prometheus (src/lib/metrics).
- OG image generator (src/lib/og).
c. Database Service
- Postgres (prisma/schema, migrations).
- Used by Prisma client calls in server and by the migrate container.
d. Search Microservice
- SearXNG (deploy/docker/searxng or external URL via SEARXNG_URL).
- Returns JSON search results.
e. LLM Provider
- Ollama or OpenAI endpoints (configurable via LLM_MODE, OLLAMA_URL or OPENAI_BASE_URL + API key).
- Performs embedding, summarization, follow-ups, etc.
f. Authentication Provider
- External OIDC IdP (optional).
g. Deployment & Ops
- Docker Compose stack (deploy/docker/compose.yml).
- Kubernetes Helm chart (deploy/kubernetes/perplexideez).
- Dockerfiles for app and migration.

##### Relationships & Data Flows
- Client → SvelteKit Server: page requests, tRPC calls.
- Server ↔ Postgres: CRUD (users, chats, favorites, sharing links).
- Server → SearXNG: web search requests.
- Server → LLM Provider: prompt completions, embeddings, image/video search.
- Server ↔ Auth/OIDC: user login, sign-up, token exchange.
- Prometheus → Server: scrapes metrics endpoint.
- CI/CD (GitHub Actions) → Builds & pushes Docker images, publishes Helm chart.

##### Architectural Patterns & Principles
- Monolithic application with microservice dependencies (Search, LLM, Auth).
- Layered separation:
- Presentation (SvelteKit UI)
- API layer (tRPC routers)
- Business logic (src/lib/ai, src/lib/utils)
- Persistence (Prisma + Postgres)
- Stateless pods/containers: all state in Postgres or external services.
- Configuration via 12-factor environment variables.
- Metrics-driven observability (Prometheus).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["Client (Browser)"]:::internal

    %% App Service Components
    subgraph "App Service"
        direction TB
        Routes["SvelteKit Routes"]:::internal
        TRPC["tRPC API Layer"]:::internal
        Auth["AuthJS/OIDC Middleware"]:::internal
        OG["Open Graph Image Generator"]:::internal
        Metrics["Metrics Endpoint"]:::internal
        DBClient["Prisma Client Init"]:::internal
    end

    %% Data Stores & External Services
    Postgres[(Postgres DB)]:::datastore
    SearX["SearXNG Search"]:::external
    LLM["LLM Provider"]:::external
    OIDC["External OIDC IdP"]:::external
    Prometheus["Prometheus"]:::external

    %% Build Artifacts & Deployment
    subgraph "Build Artifacts"
        direction TB
        AppImage["app.Dockerfile"]:::ci
        MigrateImage["db-migrate.Dockerfile"]:::ci
    end

    subgraph "Deployment"
        direction TB
        DockerComp["Docker Compose"]:::ci
        K8s["Kubernetes Helm Chart"]:::ci
    end

    CI["CI/CD (GitHub Actions)"]:::ci

    %% Data Flows
    Client -->|HTTP / tRPC| Routes
    Routes -->|invoke| TRPC
    TRPC -->|CRUD| Postgres
    TRPC -->|search requests| SearX
    TRPC -->|LLM calls| LLM
    Routes -->|auth flows| Auth
    Prometheus -->|scrapes /metrics| Metrics
    MigrateImage -->|migrate DB| Postgres

    %% Deployment Flows
    CI -->|build| AppImage
    CI -->|build| MigrateImage
    CI -->|publish| DockerComp
    CI -->|publish| K8s
    DockerComp -->|deploy| Routes
    K8s -->|deploy| Routes

    %% Click Events
    click Client "https://github.com/brunostjohn/perplexideez/tree/main/src/routes/"
    click Routes "https://github.com/brunostjohn/perplexideez/blob/main/src/routes/(app)/+layout.server.ts"
    click TRPC "https://github.com/brunostjohn/perplexideez/blob/main/src/lib/trpc/router.ts"
    click Auth "https://github.com/brunostjohn/perplexideez/blob/main/src/lib/auth.ts"
    click Metrics "https://github.com/brunostjohn/perplexideez/blob/main/src/lib/metrics/index.ts"
    click OG "https://github.com/brunostjohn/perplexideez/blob/main/src/lib/og/index.ts"
    click Postgres "https://github.com/brunostjohn/perplexideez/blob/main/prisma/schema/schema.prisma"
    click DBClient "https://github.com/brunostjohn/perplexideez/blob/main/src/lib/db.ts"
    click SearX "https://github.com/brunostjohn/perplexideez/tree/main/deploy/docker/searxng/"
    click LLM "https://github.com/brunostjohn/perplexideez/blob/main/src/lib/ai/llms.ts"
    click AppImage "https://github.com/brunostjohn/perplexideez/blob/main/deploy/app.Dockerfile"
    click MigrateImage "https://github.com/brunostjohn/perplexideez/blob/main/deploy/db-migrate.Dockerfile"
    click DockerComp "https://github.com/brunostjohn/perplexideez/blob/main/deploy/docker/compose.yml"
    click K8s "https://github.com/brunostjohn/perplexideez/blob/main/deploy/kubernetes/perplexideez/Chart.yaml"
    click CI "https://github.com/brunostjohn/perplexideez/blob/main/.github/workflows/build-push.yaml"

    %% Styles
    classDef internal fill:#e0f7fa,stroke:#006064,color:#006064
    classDef datastore fill:#fff3e0,stroke:#e65100,color:#e65100
    classDef external fill:#e8f5e9,stroke:#2e7d32,color:#2e7d32
    classDef ci fill:#eceff1,stroke:#607d8b,color:#37474f
```
