flowchart TB
    subgraph External
        USER([User])
        DISCORD([Discord API])
        LLM([OpenRouter])
        NTFY([ntfy.sh])
    end

    subgraph Bot["bot/"]
        CLIENT[bot.py]
        REGISTRY[command_registry.py]
        COMMANDS[commands/]
    end
    
    subgraph API["api/"]
        FLASK[main.py]
        ROUTES[routes/]
    end
    
    subgraph Scheduler["scheduler/"]
        DAEMON[daemon.py]
    end
    
    subgraph Core["core/"]
        AUTH[auth.py]
        USERS[users.py]
        PG[postgres.py]
        NOTIF[notifications.py]
    end
    
    subgraph AI["ai/"]
        PARSER[parser.py]
        CONFIG[ai_config.json]
    end
    
    subgraph DB["db service"]
        POSTGRES[(PostgreSQL)]
    end

    USER <-->|"DM"| DISCORD
    DISCORD <-->|"events"| CLIENT
    CLIENT -->|"parse"| PARSER
    PARSER -->|"completion"| LLM
    LLM -->|"JSON"| PARSER
    PARSER -->|"structured data"| CLIENT
    CLIENT -->|"get_handler"| REGISTRY
    REGISTRY -->|"handler"| COMMANDS
    COMMANDS -->|"logic"| CLIENT
    CLIENT -->|"HTTP"| FLASK
    FLASK --> ROUTES
    FLASK --> AUTH
    FLASK --> USERS
    FLASK --> PG
    AUTH --> USERS
    USERS --> PG
    PG --> POSTGRES
    DAEMON --> PG
    DAEMON --> NOTIF
    NOTIF -->|"webhook"| DISCORD
    NOTIF -->|"push"| NTFY
    PARSER --> CONFIG
