# hawaii66/enskilda-killer architecture

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

- Interactive diagram: https://gitdiagram.com/hawaii66/enskilda-killer
- Repository: https://github.com/hawaii66/enskilda-killer

## Overview

##### High-Level Architecture Components

a) Client Layer:
- Next.js Frontend (React components)
- Admin Dashboard
- Public Pages
- Authentication UI

b) Server Layer:
- Next.js API Routes
- Middleware
- Server-Side Components

c) External Services:
- Clerk (Authentication)
- Supabase (Database)
- Vercel (Hosting/Deployment)
- Axiom (Monitoring/Analytics)

##### Detailed Component Breakdown

a) Frontend Structure:
- Component hierarchy
- Shared UI components
- Context providers (GameState, AllUsers, etc.)

b) API Layer:
- API routes by function:
- Admin APIs (/api/admin/*)
- Game APIs (/api/game/*)
- User APIs (/api/user/*)

c) Data Flow:
- Authentication flow with Clerk
- Database interactions with Supabase
- State management through contexts

##### Key Relationships to Highlight

Critical interactions:

a) Authentication Flow:
- Microsoft Integration → Clerk → Application
- Middleware verification
- Admin access control

b) Game Logic Flow:
- Player management
- Kill reporting
- Litigation system
- Circle management

c) Data Management:
- Supabase database interactions
- Backup system
- State management
- Player tracking

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        FE[Frontend]
        MainPage["Main Page"]
        ProfilePage["Profile Page"]
        StatsPage["Statistics Page"]
        RulesPage["Rules Page"]
        AdminDash["Admin Dashboard"]
        AdminSettings["Admin Settings"]
    end

    subgraph API
        direction TB
        AdminAPI["/api/admin"]
        GameAPI["/api/game"]
        UserAPI["/api/user"]
        BackupAPI["/api/backup"]
    end

    subgraph Contexts
        direction TB
        GameState["Game State Context"]
        UsersContext["Users Context"]
        CirclesContext["Circles Context"]
        GroupsContext["Groups Context"]
        StatsContext["Stats Context"]
    end

    subgraph GameLogic
        direction TB
        KillReport["Kill Reporting"]
        PlayerMgmt["Player Management"]
        TargetSystem["Target System"]
        CircleMgmt["Circle Management"]
    end

    subgraph Auth
        direction TB
        AuthMiddleware["Middleware"]
        AdminVerify["Admin Verification"]
        EmailVerify["Email Verification"]
    end

    subgraph DataManagement
        direction TB
        DBConn["Database Connection"]
        Backup["Backup System"]
        UserMgmt["User Management"]
        GameStateTypes["Game State Types"]
    end

    subgraph External
        direction TB
        Clerk["Clerk Auth"]
        Supabase["Supabase DB"]
        Vercel["Vercel"]
        Axiom["Axiom"]
    end

    subgraph LitigationSystem
        direction TB
        LitAdmin["Litigation Admin"]
        LitAPI["Litigation API"]
        LitComponents["Litigation Components"]
    end

    %% Relationships
    FE --> |Uses| Contexts
    FE --> |Calls| API
    API --> |Uses| GameLogic
    API --> |Uses| DataManagement
    Auth --> |Protects| API
    GameLogic --> |Uses| DataManagement
    DataManagement --> |Connects| External

    %% Click Events
    click MainPage "https://github.com/Hawaii66/enskilda-killer/blob/master/src/app/page.tsx"
    click ProfilePage "https://github.com/Hawaii66/enskilda-killer/blob/master/src/app/profil/page.tsx"
    click StatsPage "https://github.com/Hawaii66/enskilda-killer/blob/master/src/app/statistik/page.tsx"
    click RulesPage "https://github.com/Hawaii66/enskilda-killer/blob/master/src/app/regler/page.tsx"
    click AdminDash "https://github.com/Hawaii66/enskilda-killer/blob/master/src/app/admin/page.tsx"
    click AdminSettings "https://github.com/Hawaii66/enskilda-killer/blob/master/src/app/admin/installningar/page.tsx"
    click AdminAPI "https://github.com/Hawaii66/enskilda-killer/tree/master/src/app/api/admin"
    click GameAPI "https://github.com/Hawaii66/enskilda-killer/tree/master/src/app/api/game"
    click UserAPI "https://github.com/Hawaii66/enskilda-killer/tree/master/src/app/api/user"
    click GameState "https://github.com/Hawaii66/enskilda-killer/blob/master/src/components/Contexts/GameStateWrapper.tsx"
    click UsersContext "https://github.com/Hawaii66/enskilda-killer/blob/master/src/components/Contexts/AllUsersWrapper.tsx"
    click CirclesContext "https://github.com/Hawaii66/enskilda-killer/blob/master/src/components/Contexts/AllCirclesWrapper.tsx"
    click GroupsContext "https://github.com/Hawaii66/enskilda-killer/blob/master/src/components/Contexts/AllGroupsWrapper.tsx"
    click KillReport "https://github.com/Hawaii66/enskilda-killer/blob/master/src/app/api/game/report/route.ts"
    click PlayerMgmt "https://github.com/Hawaii66/enskilda-killer/blob/master/src/functions/admin/getPlayers.ts"
    click TargetSystem "https://github.com/Hawaii66/enskilda-killer/blob/master/src/functions/getTargetUser.ts"
    click CircleMgmt "https://github.com/Hawaii66/enskilda-killer/blob/master/src/functions/getUserCircles.ts"
    click AuthMiddleware "https://github.com/Hawaii66/enskilda-killer/blob/master/src/middleware.ts"
    click AdminVerify "https://github.com/Hawaii66/enskilda-killer/blob/master/src/functions/admin/checkIsAdmin.ts"
    click EmailVerify "https://github.com/Hawaii66/enskilda-killer/blob/master/src/functions/isSchoolEmail.ts"
    click DBConn "https://github.com/Hawaii66/enskilda-killer/blob/master/src/functions/supabase.ts"
    click BackupAPI "https://github.com/Hawaii66/enskilda-killer/blob/master/src/app/api/backup/route.ts"
    click UserMgmt "https://github.com/Hawaii66/enskilda-killer/blob/master/src/interfaces/User.ts"
    click GameStateTypes "https://github.com/Hawaii66/enskilda-killer/blob/master/src/interfaces/database.ts"
    click StatsContext "https://github.com/Hawaii66/enskilda-killer/blob/master/src/components/Contexts/StatsWrapper.tsx"
    click LitAdmin "https://github.com/Hawaii66/enskilda-killer/blob/master/src/app/admin/tvistemal/page.tsx"
    click LitAPI "https://github.com/Hawaii66/enskilda-killer/blob/master/src/app/api/user/litigations/route.ts"
    click LitComponents "https://github.com/Hawaii66/enskilda-killer/blob/master/src/components/Profile/Default/Litigations.tsx"

    %% Styling
    classDef frontend fill:#a8d1ff
    classDef api fill:#90EE90
    classDef context fill:#FFE5CC
    classDef auth fill:#FFB6C1
    classDef external fill:#DDA0DD
    classDef data fill:#F0E68C

    class MainPage,ProfilePage,StatsPage,RulesPage,AdminDash,AdminSettings frontend
    class AdminAPI,GameAPI,UserAPI,BackupAPI api
    class GameState,UsersContext,CirclesContext,GroupsContext,StatsContext context
    class AuthMiddleware,AdminVerify,EmailVerify auth
    class Clerk,Supabase,Vercel,Axiom external
    class DBConn,Backup,UserMgmt,GameStateTypes data
```
