# webdevcody/survive-the-night-sim architecture

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

- Interactive diagram: https://gitdiagram.com/webdevcody/survive-the-night-sim
- Repository: https://github.com/webdevcody/survive-the-night-sim

## Overview

##### Main Components

a) Frontend Layer:
- Next.js Application (app directory structure)
- UI Components (components directory)
- Game Renderer (renderer directory)
- Game Simulator (simulator directory)

b) Backend Layer:
- Convex Backend (convex directory)
- Authentication Services
- AI Model Integration (models directory)

c) External Services:
- Various AI Models (GPT-4, Claude, Gemini, Mistral, Perplexity)
- OAuth Providers (GitHub, Google)
- Analytics (Plausible)

**Client Tier**
- Next.js Frontend
- Game UI Components
- Renderer Engine
- Simulator Engine

**Service Tier**
- Convex Backend
- Authentication
- Game Logic
- Multiplayer Management
- AI Model Integration

**External Services Tier**
- AI Models
- OAuth Providers
- Analytics

##### Key Relationships to Highlight

a) Data Flow:
- User interactions → Frontend → Convex Backend
- Backend → AI Models → Game Logic
- Real-time updates for multiplayer games
- Authentication flow with OAuth providers

b) Component Interactions:
- Renderer ↔ Simulator
- Game State ↔ AI Models
- User Authentication ↔ OAuth Providers

##### Technical Details

- Next.js 13+ App Router architecture
- Convex real-time database and backend
- WebGL/Canvas rendering system
- AI model integration points
- Authentication flow
- Analytics integration

##### Implementation Notes

- Version numbers for major components
- Environment configuration notes

##### Critical Paths to Highlight

- User authentication flow
- Game state management
- AI model selection and execution
- Multiplayer synchronization
- Score and leaderboard updates

Remember to include:
- Rate limiting mechanisms
- Error handling paths
- Scaling considerations
- Security boundaries
- Data persistence flows

This will provide a complete picture of how the system handles both single-player and multiplayer scenarios while managing multiple AI model integrations in a secure and scalable way.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        direction TB
        NextApp["Next.js Frontend"]:::frontend
        UI["UI Components"]:::frontend
        Renderer["Game Renderer"]:::frontend
        Simulator["Game Simulator"]:::frontend
        GameEntities["Game Entities"]:::frontend
        Assets["Game Assets"]:::frontend
        Effects["Game Effects"]:::frontend
    end

    subgraph Service["Service Layer"]
        direction TB
        ConvexBE["Convex Backend"]:::backend
        Auth["Authentication Service"]:::auth
        GameLogic["Game Logic"]:::backend
        MultiplayerMgmt["Multiplayer Management"]:::backend
        UserMgmt["User Management"]:::backend
        Leaderboard["Leaderboard System"]:::backend
        RateLimit["Rate Limiting"]:::backend
    end

    subgraph AI["AI Models Layer"]
        direction TB
        AIIntegration["AI Model Integration"]:::ai
        subgraph Models["Available Models"]
            direction TB
            GPT4["GPT-4"]:::ai
            Claude["Claude"]:::ai
            Gemini["Gemini"]:::ai
            Mistral["Mistral"]:::ai
            Perplexity["Perplexity"]:::ai
        end
        MultiAI["Multiplayer AI Models"]:::ai
    end

    subgraph External["External Services"]
        direction TB
        OAuth["OAuth Providers"]:::external
        Analytics["Analytics (Plausible)"]:::external
    end

    %% Relationships
    NextApp --> UI
    NextApp --> Renderer
    NextApp --> Simulator
    Simulator --> GameEntities
    Renderer --> Assets
    Renderer --> Effects
    
    UI --> ConvexBE
    Simulator --> ConvexBE
    
    ConvexBE --> Auth
    ConvexBE --> GameLogic
    ConvexBE --> MultiplayerMgmt
    ConvexBE --> UserMgmt
    ConvexBE --> Leaderboard
    ConvexBE --> RateLimit
    
    Auth --> OAuth
    ConvexBE --> Analytics
    
    GameLogic --> AIIntegration
    MultiplayerMgmt --> MultiAI
    AIIntegration --> Models
    
    %% Click Events
    click NextApp "https://github.com/webdevcody/survive-the-night-sim/tree/main/app"
    click UI "https://github.com/webdevcody/survive-the-night-sim/tree/main/components"
    click Renderer "https://github.com/webdevcody/survive-the-night-sim/tree/main/renderer"
    click Simulator "https://github.com/webdevcody/survive-the-night-sim/tree/main/simulator"
    click ConvexBE "https://github.com/webdevcody/survive-the-night-sim/tree/main/convex"
    click Auth "https://github.com/webdevcody/survive-the-night-sim/blob/main/convex/auth.ts"
    click AIIntegration "https://github.com/webdevcody/survive-the-night-sim/tree/main/models"
    click MultiplayerMgmt "https://github.com/webdevcody/survive-the-night-sim/blob/main/convex/multiplayerGames.ts"
    click GameLogic "https://github.com/webdevcody/survive-the-night-sim/blob/main/simulator/ZombieSurvival.ts"
    click UserMgmt "https://github.com/webdevcody/survive-the-night-sim/blob/main/convex/users.ts"
    click Leaderboard "https://github.com/webdevcody/survive-the-night-sim/blob/main/convex/leaderboard.ts"
    click RateLimit "https://github.com/webdevcody/survive-the-night-sim/blob/main/convex/rateLimits.ts"
    click GameEntities "https://github.com/webdevcody/survive-the-night-sim/tree/main/simulator/entities"
    click GPT4 "https://github.com/webdevcody/survive-the-night-sim/blob/main/models/gpt-4o.ts"
    click Claude "https://github.com/webdevcody/survive-the-night-sim/blob/main/models/claude-3-5-sonnet.ts"
    click Gemini "https://github.com/webdevcody/survive-the-night-sim/blob/main/models/gemini-1.5-pro.ts"
    click Mistral "https://github.com/webdevcody/survive-the-night-sim/blob/main/models/mistral-large-2.ts"
    click Perplexity "https://github.com/webdevcody/survive-the-night-sim/blob/main/models/perplexity-llama-3.1.ts"
    click MultiAI "https://github.com/webdevcody/survive-the-night-sim/tree/main/models/multiplayer"
    click Assets "https://github.com/webdevcody/survive-the-night-sim/blob/main/renderer/Assets.ts"
    click Effects "https://github.com/webdevcody/survive-the-night-sim/blob/main/renderer/Effect.ts"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef ai fill:#9b59b6,stroke:#8e44ad,color:white
    classDef auth fill:#e67e22,stroke:#d35400,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
```
