# ibrahimcaj/lumberjack architecture

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

## Overview

##### Main Components

a. Discord Interface Layer
- Discord.js integration point
- Command handling system
- Message utilities and rich embed handlers

b. Command Management System
- Command parser and router
- Individual command implementations
- Command categories (administrative, game mechanics, utility)

c. Game Core
- User management system
- Inventory system
- Item management system
- Economy system

d. Database Layer
- Data persistence
- User data storage
- Item data storage

**[Discord API]**
- ↕
**[Bot Interface Layer]**
- ↕
**[Command Handler]**
- ↕
**[Game Core] ↔ [Database]**

##### Component Details

a. Discord Interface Layer:
- Error handling system (ErrorRichEmbed.js)
- Message utilities (MessageUtilities.js)
- User resolution system (UserResolver.js)

b. Command Handler:
- Command routing system
- Command categories:
- Economy commands (balance, shop)
- Game mechanics (cut, craft)
- Administrative (eval, reload)
- Utility (help, ping)

c. Game Core:
- Item system hierarchy:
- Base Item class
- Specialized items (axes)
- Inventory management
- User system:
- User data management
- Balance tracking
- Inventory tracking

d. Database Layer:
- Data models
- Data validation
- Error handling (InventoryCorruptedError)

##### Relationships to Emphasize

- Command → Game Core interaction
- Game Core → Database operations
- User data validation flow
- Item management system

##### Implementation Details

- Command pattern for Discord commands
- Factory pattern for item creation
- Repository pattern for data access
- Service layer pattern for game logic

##### Key Files to Reference

Core Systems:
- index.js (entry point)
- Database.js (data layer)
- User.js (user management)
- Inventory.js (inventory system)

Game Items:
- Item.js (base item class)
- CommonItems.js (item definitions)
- Axe.js (tool system)

##### Additional Notes

Specific features:
- 5-minute cooldown system for wood cutting
- Item durability tracking
- Economy system with buying/selling
- Leaderboard functionality

Remember to show the separation between the Discord bot framework and the game logic, as this is crucial for maintaining code organization and potential future platform expansion.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Discord API Layer"
        DiscordAPI["Discord.js API"]
        ErrorEmbed["Error Rich Embed"]:::error
        MultiEmbed["Multi Rich Embed"]:::discord
        MsgUtil["Message Utilities"]:::discord
        UserRes["User Resolver"]:::discord
        UserUtil["User Utilities"]:::discord
    end

    subgraph "Command Layer"
        CmdHandler["Command Handler"]:::command
        HelpCmd["Help Command"]:::command
        SyntaxCmd["Syntax Command"]:::command
        
        subgraph "Game Commands"
            CutCmd["Cut Command"]:::gameplay
            CraftCmd["Craft Command"]:::gameplay
            InventoryCmd["Inventory Command"]:::gameplay
            LeaderCmd["Leaderboard Command"]:::gameplay
        end
        
        subgraph "Economy Commands"
            BalanceCmd["Balance Command"]:::economy
            ShopCmd["Shop Command"]:::economy
        end
    end

    subgraph "Game Core"
        User["User System"]:::core
        Inventory["Inventory System"]:::core
        
        subgraph "Item System"
            BaseItem["Base Item"]:::item
            CommonItems["Common Items"]:::item
            StoreItem["Store Items"]:::item
            
            subgraph "Axe System"
                BaseAxe["Base Axe"]:::item
                CommonAxes["Common Axes"]:::item
                CraftableAxe["Craftable Axe"]:::item
                Durability["Durability System"]:::item
            end
        end
    end

    subgraph "Database Layer"
        DB["Database"]:::database
        Config["Configuration"]:::database
        Constants["Constants"]:::database
    end

    subgraph "Error Handling"
        InvError["Inventory Corrupted Error"]:::error
        NotImplError["Not Implemented Error"]:::error
    end

    subgraph "Utility Layer"
        ItemUtil["Item Utilities"]:::utility
        MarkdownUtil["Markdown Utilities"]:::utility
        TypeUtil["Type Utilities"]:::utility
    end

    %% Relationships
    DiscordAPI --> ErrorEmbed
    DiscordAPI --> MultiEmbed
    DiscordAPI --> MsgUtil
    DiscordAPI --> UserRes
    DiscordAPI --> UserUtil

    DiscordAPI --> CmdHandler
    CmdHandler --> HelpCmd
    CmdHandler --> SyntaxCmd
    CmdHandler --> CutCmd
    CmdHandler --> CraftCmd
    CmdHandler --> InventoryCmd
    CmdHandler --> LeaderCmd
    CmdHandler --> BalanceCmd
    CmdHandler --> ShopCmd

    User --> Inventory
    Inventory --> BaseItem
    BaseItem --> CommonItems
    BaseItem --> StoreItem
    BaseItem --> BaseAxe
    BaseAxe --> CommonAxes
    BaseAxe --> CraftableAxe
    BaseAxe --> Durability

    User --> DB
    Inventory --> DB
    DB --> Config
    DB --> Constants

    %% Click events
    click ErrorEmbed "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/discord/ErrorRichEmbed.js"
    click MultiEmbed "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/discord/MultiRichEmbed.js"
    click MsgUtil "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/utility/discord/MessageUtilities.js"
    click UserRes "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/utility/discord/UserResolver.js"
    click UserUtil "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/utility/discord/UserUtilities.js"
    click HelpCmd "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/command/Help.js"
    click SyntaxCmd "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/command/Syntax.js"
    click CmdHandler "https://github.com/ibrahimcaj/lumberjack/tree/reimplementation-release/command/commands"
    click User "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/game/User.js"
    click Inventory "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/game/Inventory.js"
    click BaseItem "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/game/item/Item.js"
    click CommonItems "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/game/item/CommonItems.js"
    click StoreItem "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/game/item/StoreItem.js"
    click DB "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/Database.js"
    click Config "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/Config.js"
    click Constants "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/Constants.js"
    click BaseAxe "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/game/item/axe/Axe.js"
    click CommonAxes "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/game/item/axe/CommonAxes.js"
    click CraftableAxe "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/game/item/axe/CraftableAxe.js"
    click Durability "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/game/item/axe/Durability.js"
    click InvError "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/game/InventoryCorruptedError.js"
    click NotImplError "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/utility/NotImplementedError.js"
    click BalanceCmd "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/command/commands/balance.js"
    click ShopCmd "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/command/commands/shop.js"
    click CutCmd "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/command/commands/cut.js"
    click CraftCmd "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/command/commands/craft.js"
    click InventoryCmd "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/command/commands/inventory.js"
    click LeaderCmd "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/command/commands/leaderboard.js"
    click ItemUtil "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/utility/ItemUtilities.js"
    click MarkdownUtil "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/utility/MarkdownUtilities.js"
    click TypeUtil "https://github.com/ibrahimcaj/lumberjack/blob/reimplementation-release/utility/Type.js"

    %% Styles
    classDef discord fill:#7289DA,color:white
    classDef command fill:#FFB900,color:black
    classDef gameplay fill:#32CD32,color:white
    classDef economy fill:#FFD700,color:black
    classDef core fill:#4169E1,color:white
    classDef item fill:#98FB98,color:black
    classDef database fill:#800080,color:white
    classDef error fill:#FF0000,color:white
    classDef utility fill:#A9A9A9,color:white
```
