# hmddevs/chat-guard architecture

> Architecture diagram of the GitHub repository hmddevs/chat-guard, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hmddevs/chat-guard
- Repository: https://github.com/hmddevs/chat-guard

## Overview

Chat Guard is a Discord moderation bot. Server administrators configure protections and logging through slash commands; the bot stores those settings, evaluates incoming and edited messages against enabled guards and exemptions, then deletes violations, warns or escalates to a timed mute, and records moderation actions in the configured log channel. The sampled event and command handlers show those runtime boundaries; README capabilities not visible in the excerpts are represented only where the documented subsystem is supported by the tree.

Main entry points: [`src/db.js`](https://github.com/hmddevs/chat-guard/blob/main/src/db.js) (Guild settings model), [`app.js`](https://github.com/hmddevs/chat-guard/blob/main/app.js) (Bot client), [`src/login.js`](https://github.com/hmddevs/chat-guard/blob/main/src/login.js) (Login and registration), [`src/events.js`](https://github.com/hmddevs/chat-guard/blob/main/src/events.js) (Message events)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot runtime"]
  node_app["Bot client<br/>[app.js]"]
  node_login["Login and registration<br/>[login.js]"]
  node_config["Environment configuration<br/>[config.js]"]
end

subgraph group_moderation["Message moderation"]
  node_events["Message events<br/>[events.js]"]
  node_guards["Guard and exemption checks<br/>[functionz.js]"]
  node_punishment["Warnings and timed mutes<br/>[functionz.js]"]
end

subgraph group_settings["Configuration"]
  node_commands["Slash commands<br/>[commands.js]"]
end

subgraph group_persistence["Persistence"]
  node_dbmodel["Guild settings model<br/>[db.js]"]
  node_mongo[("MongoDB")]
end

node_admins(("Server admins"))
node_members(("Server members"))
node_discord{{"Discord API"}}

node_admins -->|"configure via"| node_discord
node_members -->|"post messages"| node_discord
node_discord -->|"delivers events"| node_app
node_app -->|"loads"| node_login
node_app -->|"loads"| node_events
node_app -->|"loads"| node_commands
node_login -->|"reads"| node_config
node_commands -->|"reads"| node_config
node_login -->|"registers commands"| node_discord
node_commands -->|"replies to interactions"| node_discord
node_events -->|"checks messages"| node_guards
node_events -->|"reads settings"| node_dbmodel
node_commands -->|"updates settings"| node_dbmodel
node_guards -->|"reads exemptions"| node_dbmodel
node_guards -->|"escalates violations"| node_punishment
node_punishment -->|"updates escalation state"| node_dbmodel
node_login -->|"connects"| node_mongo
node_dbmodel -->|"stores guild data"| node_mongo
node_events -->|"deletes or warns"| node_discord
node_punishment -->|"times out and logs"| node_discord

click node_app "https://github.com/hmddevs/chat-guard/blob/main/app.js"
click node_login "https://github.com/hmddevs/chat-guard/blob/main/src/login.js"
click node_commands "https://github.com/hmddevs/chat-guard/blob/main/src/commands.js"
click node_events "https://github.com/hmddevs/chat-guard/blob/main/src/events.js"
click node_guards "https://github.com/hmddevs/chat-guard/blob/main/src/functionz.js"
click node_punishment "https://github.com/hmddevs/chat-guard/blob/main/src/functionz.js"
click node_config "https://github.com/hmddevs/chat-guard/blob/main/src/config.js"
click node_dbmodel "https://github.com/hmddevs/chat-guard/blob/main/src/db.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_login,node_config toneBlue
class node_events,node_guards,node_punishment toneAmber
class node_commands,node_admins,node_members,node_discord toneMint
class node_dbmodel,node_mongo toneRose
```

## Components

### Bot runtime

- [Bot client](https://github.com/hmddevs/chat-guard/blob/main/app.js): `app.js`
- [Login and registration](https://github.com/hmddevs/chat-guard/blob/main/src/login.js): `src/login.js`
- [Environment configuration](https://github.com/hmddevs/chat-guard/blob/main/src/config.js): `src/config.js`

### Message moderation

- [Message events](https://github.com/hmddevs/chat-guard/blob/main/src/events.js): `src/events.js`
- [Guard and exemption checks](https://github.com/hmddevs/chat-guard/blob/main/src/functionz.js): `src/functionz.js`
- [Warnings and timed mutes](https://github.com/hmddevs/chat-guard/blob/main/src/functionz.js): `src/functionz.js`

### Configuration

- [Slash commands](https://github.com/hmddevs/chat-guard/blob/main/src/commands.js): `src/commands.js`

### Persistence

- [Guild settings model](https://github.com/hmddevs/chat-guard/blob/main/src/db.js): `src/db.js`
- **MongoDB**

### Other components

- **Server admins**
- **Server members**
- **Discord API**

## Connections

- Server admins → Discord API: configure via
- Server members → Discord API: post messages
- Discord API → Bot client: delivers events
- Bot client → Login and registration: loads
- Bot client → Message events: loads
- Bot client → Slash commands: loads
- Login and registration → Environment configuration: reads
- Slash commands → Environment configuration: reads
- Login and registration → Discord API: registers commands
- Slash commands → Discord API: replies to interactions
- Message events → Guard and exemption checks: checks messages
- Message events → Guild settings model: reads settings
- Slash commands → Guild settings model: updates settings
- Guard and exemption checks → Guild settings model: reads exemptions
- Guard and exemption checks → Warnings and timed mutes: escalates violations
- Warnings and timed mutes → Guild settings model: updates escalation state
- Login and registration → MongoDB: connects
- Guild settings model → MongoDB: stores guild data
- Message events → Discord API: deletes or warns
- Warnings and timed mutes → Discord API: times out and logs
