# belazy167/k0-club architecture

> Architecture diagram of the GitHub repository belazy167/k0-club, 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/belazy167/k0-club
- Repository: https://github.com/belazy167/k0-club

## Overview

##### Main Components

a) Client-Side (Frontend):
- Next.js Application Layer
- Pages/Routes (dashboard, fights, myfights)
- Components (UI elements, forms, cards)
- Client-side state management
- Authentication Layer (NextAuth.js)

b) Server-Side:
- API Routes Layer
- Database Layer
- PostgreSQL (Neon DB) for structured data
- MongoDB for real-time chat
- WebSocket Server (Socket.IO)

**[Client Layer]**
- ↕️
**[API/Server Layer]**
- ↕️
**[Database Layer]**

##### Detailed Component Breakdown

Client Layer:
- Main Next.js pages structure
- Components (FightCard, Chat Section, Vote Section)
- Authentication flow with NextAuth
- Real-time WebSocket connections

API Layer:
- API endpoints by functionality:
- Fight Management (/api/fight/*)
- User Management (/api/username/*)
- Authentication (/api/auth/*)
- Voting System (/api/fight/vote/*)

Database Layer:
- PostgreSQL Tables:
- Users
- Fights
- Votes
- MongoDB Collections:
- Messages
- Conversations

##### Data Flow Representation

- Client-server communication (REST API calls)
- Real-time WebSocket connections
- Database queries and updates
- Authentication flows

##### Elements

- Component labels with clear naming
- Database schema relationships
- WebSocket event flow
- API endpoint groupings
- Authentication flow paths

##### Additional Notes

- Integration between Next.js API routes and external services
- Separation between client and server components
- Where Drizzle ORM interfaces with PostgreSQL
- How Socket.IO integrates with the Express server
- Demonstrate the relationship between fight rooms and chat functionality

This system design should effectively communicate the architecture of K0 Club as a modern, real-time enabled full-stack application with robust authentication, database management, and WebSocket integration.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        direction TB
        NextPages["Pages/Routes"]:::frontend
        UIComp["UI Components"]:::frontend
        MainComp["Main Components"]:::frontend
        FightCard["Fight Card"]:::frontend
        ChatComp["Chat Section"]:::frontend
        VoteComp["Vote Section"]:::frontend
        SocketContext["Socket Context"]:::frontend
        MessageHook["Message Hook"]:::frontend
    end

    subgraph Auth
        direction TB
        AuthConfig["Auth Configuration"]:::auth
        NextAuth["NextAuth.js"]:::auth
    end

    subgraph API
        direction TB
        APIRoutes["API Routes"]:::api
        FightAPI["Fight Management"]:::api
        UserAPI["User Management"]:::api
        VoteAPI["Vote Management"]:::api
    end

    subgraph Server
        direction TB
        WSServer["WebSocket Server"]:::server
        DBSchema["Database Schema"]:::server
        DBMigrations["DB Migrations"]:::server
    end

    subgraph Database
        direction TB
        PostgreSQL[(PostgreSQL)]:::database
        MongoDB[(MongoDB)]:::database
    end

    %% Connections
    NextPages --> APIRoutes
    UIComp --> MainComp
    MainComp --> FightCard
    MainComp --> ChatComp
    MainComp --> VoteComp
    SocketContext --> WSServer
    MessageHook --> SocketContext
    ChatComp --> MessageHook
    
    NextAuth --> AuthConfig
    APIRoutes --> AuthConfig
    
    APIRoutes --> FightAPI
    APIRoutes --> UserAPI
    APIRoutes --> VoteAPI
    
    FightAPI --> DBSchema
    UserAPI --> DBSchema
    VoteAPI --> DBSchema
    
    DBSchema --> PostgreSQL
    WSServer --> MongoDB
    DBMigrations --> PostgreSQL

    %% Click Events
    click NextPages "https://github.com/BeLazy167/K0-Club/tree/main/client/src/app/"
    click UIComp "https://github.com/BeLazy167/K0-Club/tree/main/client/src/components/ui/"
    click MainComp "https://github.com/BeLazy167/K0-Club/tree/main/client/src/components/"
    click NextAuth "https://github.com/BeLazy167/K0-Club/tree/main/client/src/app/api/auth/[...nextauth]/"
    click DBSchema "https://github.com/BeLazy167/K0-Club/blob/main/client/src/server/db/schema.ts"
    click APIRoutes "https://github.com/BeLazy167/K0-Club/tree/main/client/src/app/api/"
    click WSServer "https://github.com/BeLazy167/K0-Club/blob/main/server/server.js"
    click SocketContext "https://github.com/BeLazy167/K0-Club/blob/main/client/src/utils/SocketContext.tsx"
    click ChatComp "https://github.com/BeLazy167/K0-Club/blob/main/client/src/components/chat-section.tsx"
    click FightAPI "https://github.com/BeLazy167/K0-Club/tree/main/client/src/app/api/fight/"
    click UserAPI "https://github.com/BeLazy167/K0-Club/tree/main/client/src/app/api/username/"
    click VoteComp "https://github.com/BeLazy167/K0-Club/blob/main/client/src/components/vote-section.tsx"
    click DBMigrations "https://github.com/BeLazy167/K0-Club/tree/main/client/src/server/db/"
    click AuthConfig "https://github.com/BeLazy167/K0-Club/blob/main/client/src/server/auth.ts"
    click MessageHook "https://github.com/BeLazy167/K0-Club/blob/main/client/src/hooks/useFightMessages.ts"
    click FightCard "https://github.com/BeLazy167/K0-Club/blob/main/client/src/components/main-fight-card.tsx"

    %% Styles
    classDef frontend fill:#2196F3,color:white
    classDef auth fill:#FFC107,color:black
    classDef api fill:#4CAF50,color:white
    classDef server fill:#9C27B0,color:white
    classDef database fill:#FF5722,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Auth["Auth Component"]:::auth
        APIComp["API Component"]:::api
        ServerComp["Server Component"]:::server
        DB["Database"]:::database
    end
```
