# mitskiyu/medalzai architecture

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

- Interactive diagram: https://gitdiagram.com/mitskiyu/medalzai
- Repository: https://github.com/mitskiyu/medalzai

## Overview

##### Project Type and Purpose
- This is a containerized, full-stack web application named “Medalzai.”
- Frontend: a SvelteKit-based single-page app under `client/`.
- Backend: a Rust web service (using Cargo, likely with warp or actix) under `server/`.
- Purpose (inferred): present video-related functionality (VideoPanel, LinkArea, medal services) via a browser UI and interact with metadata/proxy/medal endpoints.

##### File Structure Analysis
- Top level
- `docker-compose.yml` orchestrates client and server containers.
- `.dockerignore`, `.gitignore` for builds and VCS.
- client/
- Standard SvelteKit layout: `src/routes` (page components), `src/lib` (reusable UI components, state, types, video client).
- Dockerfile, package.json, pnpm lock, tsconfig, lint/prettier configs.
- server/
- Rust project managed by Cargo (`Cargo.toml`, `Cargo.lock`).
- `src/main.rs` and `src/app.rs` bootstrap the HTTP server.
- `src/routes/` defines endpoint handlers (`metadata.rs`, `proxy.rs`, `mod.rs`).
- `src/services/` contains business logic (`medal.rs`, `metadata`, etc.).

##### README Insights
- Minimal, but project name implies a “medal” feature around videos, likely awarding or extracting highlights.
- Absence of a database directory suggests no persistent store; service modules handle ephemeral or proxied data.

a. Main Components
- Client UI Service (SvelteKit container)
- API Gateway / Backend Service (Rust container)
- Internal Modules: Route Handlers, Business Services (medal, metadata, proxy)
- External Services: upstream video sources or 3rd-party APIs
- (Optional) Docker-Compose network fabric
b. Relationships & Interactions
- Browser ↔ Client UI (HTTP/WS)
- Client UI → Backend API (REST or JSON over HTTP)
- Backend Routes → Service Modules (in-process calls)
- Service Modules → External Video APIs (HTTP calls)
c. Architectural Patterns & Principles
- Layered architecture: presentation, API gateway, domain services
- Separation of concerns: routing vs business logic
- Containerization for environment parity
- Client–server decoupling via clear API contracts
d. Key Technologies
- Frontend: SvelteKit, TypeScript, pnpm, Vite
- Backend: Rust, Cargo, web framework (warp/actix), modules under `routes/` and `services/`
- DevOps: Docker, Docker-Compose

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    User((User)):::external

    %% Docker Compose Network
    subgraph "Docker-Compose Network" 
        direction TB
        ClientContainer["Client Container\n(SvelteKit SPA)"]:::ui
        ServerContainer["Server Container\n(Rust API)"]:::backend
    end

    User -->|"Interacts via HTTP/WS"| ClientContainer

    %% Frontend Subcomponents
    subgraph "Frontend (SvelteKit SPA)" 
        direction TB
        A1["+layout.svelte"]:::ui
        A2["+page.svelte"]:::ui
        subgraph "UI Components"
            direction TB
            Comp1["Videopanel"]:::ui
            Comp2["Linkarea"]:::ui
            Comp3["Navbar"]:::ui
            Comp4["Settingspanel"]:::ui
            Comp5["Toolbar"]:::ui
        end
        subgraph "Video Library / API Client"
            direction TB
            Lib1["client.ts"]:::ui
            Lib2["save.ts"]:::ui
            Lib3["urls.ts"]:::ui
        end
        subgraph "State & Types"
            direction TB
            ST1["index.svelte.ts"]:::ui
            ST2["video.ts"]:::ui
        end
    end

    ClientContainer -->|"Serves SPA (4200)"| A1
    A1 --> A2
    A2 --> Comp1
    A2 --> Comp2
    A2 --> Comp3
    A2 --> Comp4
    A2 --> Comp5

    Comp1 --> Lib1
    Comp1 --> Lib2
    Comp1 --> Lib3
    Lib1 --> ST1
    Lib3 --> ST2

    %% Backend Subcomponents
    subgraph "Backend (Rust API Gateway)" 
        direction TB
        B1["main.rs"]:::backend
        B2["app.rs"]:::backend
        subgraph "Route Handlers"
            direction TB
            R1["mod.rs"]:::backend
            R2["metadata.rs"]:::backend
            R3["proxy.rs"]:::backend
        end
        subgraph "Service Modules"
            direction TB
            S1["mod.rs"]:::backend
            S2["medal.rs"]:::backend
        end
    end

    ClientContainer -->|"GET /metadata\nPOST /proxy\nGET /medal"| ServerContainer
    ServerContainer --> B1
    B1 --> B2
    B2 --> R1
    R1 --> R2
    R1 --> R3
    R2 --> S1
    R3 --> S1
    S1 --> S2
    S2 -->|"HTTP calls"| ExternalAPI

    %% External Systems
    ExternalAPI[(External Video API)]:::external

    %% Dockerfiles and Compose
    subgraph "DevOps"
        direction TB
        DC["docker-compose.yml"]:::external
        DFC["client/Dockerfile"]:::external
        DFR["server/Dockerfile"]:::external
    end

    DC --> ClientContainer
    DC --> ServerContainer
    ClientContainer --> DFC
    ServerContainer --> DFR

    %% Click Events
    click ClientContainer "https://github.com/mitskiyu/medalzai/tree/main/client/"
    click A1 "https://github.com/mitskiyu/medalzai/blob/main/client/src/routes/+layout.svelte"
    click A2 "https://github.com/mitskiyu/medalzai/blob/main/client/src/routes/+page.svelte"
    click Comp1 "https://github.com/mitskiyu/medalzai/blob/main/client/src/lib/components/Videopanel.svelte"
    click Comp2 "https://github.com/mitskiyu/medalzai/blob/main/client/src/lib/components/Linkarea.svelte"
    click Comp3 "https://github.com/mitskiyu/medalzai/blob/main/client/src/lib/components/Navbar.svelte"
    click Comp4 "https://github.com/mitskiyu/medalzai/blob/main/client/src/lib/components/Settingspanel.svelte"
    click Comp5 "https://github.com/mitskiyu/medalzai/blob/main/client/src/lib/components/Toolbar.svelte"
    click Lib1 "https://github.com/mitskiyu/medalzai/blob/main/client/src/lib/video/client.ts"
    click Lib2 "https://github.com/mitskiyu/medalzai/blob/main/client/src/lib/video/save.ts"
    click Lib3 "https://github.com/mitskiyu/medalzai/blob/main/client/src/lib/video/urls.ts"
    click ST1 "https://github.com/mitskiyu/medalzai/blob/main/client/src/lib/state/index.svelte.ts"
    click ST2 "https://github.com/mitskiyu/medalzai/blob/main/client/src/lib/types/video.ts"
    click ServerContainer "https://github.com/mitskiyu/medalzai/tree/main/server/"
    click B1 "https://github.com/mitskiyu/medalzai/blob/main/server/src/main.rs"
    click B2 "https://github.com/mitskiyu/medalzai/blob/main/server/src/app.rs"
    click R1 "https://github.com/mitskiyu/medalzai/blob/main/server/src/routes/mod.rs"
    click R2 "https://github.com/mitskiyu/medalzai/blob/main/server/src/routes/metadata.rs"
    click R3 "https://github.com/mitskiyu/medalzai/blob/main/server/src/routes/proxy.rs"
    click S1 "https://github.com/mitskiyu/medalzai/blob/main/server/src/services/mod.rs"
    click S2 "https://github.com/mitskiyu/medalzai/blob/main/server/src/services/medal.rs"
    click DC "https://github.com/mitskiyu/medalzai/blob/main/docker-compose.yml"
    click DFC "https://github.com/mitskiyu/medalzai/tree/main/client/Dockerfile"
    click DFR "https://github.com/mitskiyu/medalzai/tree/main/server/Dockerfile"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366d6,color:#000
    classDef backend fill:#D0FFD0,stroke:#22863a,color:#000
    classDef external fill:#F0F0F0,stroke:#6a737d,color:#000
```
