# muni-town/weird architecture

> Architecture diagram of the GitHub repository muni-town/weird, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/muni-town/weird
- Repository: https://github.com/muni-town/weird

## Overview

##### Main Components

a) Frontend Layer:
- SvelteKit application (src/routes directory structure)
- Theme components (src/lib/themes)
- User interface components (src/lib/components)

b) Backend Services:
- SvelteKit Server (hooks.server.ts)
- Rauthy Authentication Service (OIDC provider)
- Leaf Server (Rust-based distributed protocol)
- Redis for caching (src/lib/redis.ts)

c) Core Protocol Layer:
- Leaf Protocol implementation (leaf/leaf-protocol)
- RPC Server and Client components (leaf/leaf-rpc-*)
- Iroh integration for p2p functionality

d) External Service Integrations:
- DNS Management (src/lib/dns)
- Social Media Connectors (various platforms)
- Email Service (src/lib/email.ts)
- Billing System (src/lib/billing.ts)

##### Relationship Flows

- User authentication flow through Rauthy
- Content distribution through Leaf Protocol
- Data synchronization between peers
- External service interactions
- API endpoints and their connections

##### Architectural Patterns

Following patterns:
- Microservices architecture (separate services for auth, content, etc.)
- Event-driven communication (websocket implementations)
- P2P networking layer
- Federation capabilities

**┌─ Frontend Layer ─────────────┐**
- SvelteKit UI              │
- Theme System              │
- Component Library         │
- ┬──────────────┘

**┌─ Backend Services ───────────┐**
- SvelteKit Server          │
- Rauthy Auth              │
- Redis Cache              │
- Leaf Server              │
- ┬──────────────┘

**┌─ Leaf Protocol Layer ───────┐**
- P2P Communication        │
- Content Distribution     │
- Data Synchronization    │
- ┬──────────────┘

**┌─ External Integrations ─────┐**
- DNS Management           │
- Social Media APIs        │
- Email Service           │
- Billing System          │
- ┘

##### Additional Elements

Include:
- Security boundaries
- Data flow directions
- API endpoints
- Storage systems
- Caching layers
- Load balancers where applicable

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef protocol fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:white
    classDef security fill:#e74c3c,stroke:#c0392b,color:white

    %% Frontend Layer
    subgraph Frontend
        UI["UI Components"]
        Theme["Theme System"]
        AuthRoutes["Auth Routes"]
        Profile["Profile Management"]
        Account["Account Management"]
        Admin["Admin Interface"]
        Social["Social Media Components"]
    end

    %% Backend Services
    subgraph Services
        Server["SvelteKit Server"]
        Auth["Rauthy Auth"]
        Cache["Redis Cache"]
        LeafS["Leaf Server"]
    end

    %% Protocol Layer
    subgraph Protocol
        LeafP["Leaf Protocol"]
        RPC["Leaf RPC Server"]
        P2P["Iroh P2P"]
    end

    %% External Services
    subgraph External
        DNS["DNS Management"]
        Email["Email Service"]
        Billing["Billing System"]
    end

    %% Relationships
    UI --> Server
    Theme --> UI
    AuthRoutes --> Auth
    Profile --> Server
    Account --> Server
    Admin --> Server
    Social --> Server

    Server --> Auth
    Server --> Cache
    Server --> LeafS
    
    LeafS --> LeafP
    LeafP --> RPC
    LeafP --> P2P
    
    Server --> DNS
    Server --> Email
    Server --> Billing

    %% Component Classes
    class UI,Theme,AuthRoutes,Profile,Account,Admin,Social frontend
    class Server,Auth,Cache,LeafS backend
    class LeafP,RPC,P2P protocol
    class DNS,Email,Billing external

    %% Click Events
    click UI "https://github.com/muni-town/weird/tree/main/src/lib/components"
    click Theme "https://github.com/muni-town/weird/tree/main/src/lib/themes"
    click Server "https://github.com/muni-town/weird/blob/main/src/hooks.server.ts"
    click Auth "https://github.com/muni-town/weird/tree/main/src/lib/rauthy"
    click Cache "https://github.com/muni-town/weird/blob/main/src/lib/redis.ts"
    click LeafP "https://github.com/muni-town/weird/tree/main/leaf/leaf-protocol"
    click RPC "https://github.com/muni-town/weird/tree/main/leaf/leaf-rpc-server"
    click P2P "https://github.com/muni-town/weird/blob/main/leaf/leaf-protocol/src/store/iroh.rs"
    click DNS "https://github.com/muni-town/weird/tree/main/src/lib/dns"
    click Email "https://github.com/muni-town/weird/blob/main/src/lib/email.ts"
    click Billing "https://github.com/muni-town/weird/blob/main/src/lib/billing.ts"
    click Social "https://github.com/muni-town/weird/tree/main/src/lib/components/social-media"
    click AuthRoutes "https://github.com/muni-town/weird/tree/main/src/routes/(app)/auth"
    click Profile "https://github.com/muni-town/weird/tree/main/src/routes/(app)/[username]"
    click Account "https://github.com/muni-town/weird/tree/main/src/routes/(app)/account"
    click Admin "https://github.com/muni-town/weird/tree/main/src/routes/(internal)/__internal__/admin"
```
