# Distillery Codebase Style Guide This document outlines the key aspects and coding style used throughout the Distillery codebase. When contributing to or working with this codebase, please adhere to these guidelines to maintain consistency. ## Naming Conventions - **Class names** are in [[PascalCase]], e.g. `DistilleryCheckIn`, `OutputParser`, `RawInputParser` - **Function and method names** are in [[snake_case]], e.g. `is_user_under_throttle_levels`, `parse_input`, `create_routine` - **Variable names** are generally in [[snake_case]], e.g. `parsed_input`, `command_args`, `payload_keymaker` - **Constants** are in `UPPERCASE_WITH_UNDERSCORES`, e.g. `APP_NAME`, `MAX_SEED_INT`, `WORKER_TIMEOUT_FOR_INFERENCE` ## Code Organization - **Imports** are grouped together at the top of each file - **Constants** are often defined after the imports and before the **class/function definitions** - **[[Helper functions]]** are usually defined within the relevant class as `@staticmethod` or `@classmethod` - The **`main` functionality or entry point** is typically at the bottom of the file ## Error Handling and Logging - Most functions use a [[try-except]] block to catch and handle exceptions - Errors are logged using the `AWSConnector.print_log` method, which takes a `request_id`, `instance_identifier`, the error message, and a log level (`'ERROR'`, `'WARNING'`, etc.) - The [[better_exceptions library]] is used to format and print more detailed tracebacks ## Configuration and Environment Variables - **Configuration settings** are loaded from a [[config.json]] file using `json.load` - **Environment variables** are accessed using `os.getenv` ## Async and Await - Many functions and methods are defined as `async def` to enable asynchronous execution [[asyncio]] - The `await` keyword is used extensively to wait for asynchronous operations to complete, such as database queries, API calls, and file I/O ## Database and AWS Integration - The `AWSManager` class handles interactions with AWS services like S3, RDS (MySQL), and CloudWatch [[AWS services]] - **Database queries** are executed using the [[aiomysql library]] for asynchronous database access ## Discord Bot and Slash Commands - The **Discord bot** is built using the `py-cord` library - **Slash commands** are dynamically created based on the `DISTILLERY_COMMANDS` configuration in `config.json` - User input is **parsed and validated** using the `RawInputParser` and `OutputParser` classes ## ComfyUI Integration - The `ComfyConnector` class handles communication with the ComfyUI API - Payloads for ComfyUI are built using the `PayloadBuilder` class based on templates defined in `config.json` By following these guidelines and understanding the key aspects of the codebase, contributors can maintain a consistent style and structure while working with the Distillery project.