#!/bin/bash # Purpose: Generate ASCII architecture diagrams from system descriptions # Version: 1.0.0 # Usage: ./diagram-generator.sh [options] # Types: layered, microservices, database, network, component # Returns: ASCII diagram # Exit codes: 0=success, 1=error, 2=invalid input set -euo pipefail # Configuration readonly SCRIPT_NAME="$(basename "$0")" readonly DIAGRAM_TYPE="${1:-}" # Box drawing characters readonly TL="┌" # Top-left readonly TR="┐" # Top-right readonly BL="└" # Bottom-left readonly BR="┘" # Bottom-right readonly H="─" # Horizontal readonly V="│" # Vertical readonly VR="├" # Vertical-right readonly VL="┤" # Vertical-left readonly HU="┴" # Horizontal-up readonly HD="┬" # Horizontal-down readonly X="┼" # Cross # Arrow characters readonly ARROW_DOWN="▼" readonly ARROW_UP="▲" readonly ARROW_LEFT="◄" readonly ARROW_RIGHT="►" readonly ARROW_BIDIRECT="◄►" # Color codes readonly BLUE='\033[0;34m' readonly GREEN='\033[0;32m' readonly YELLOW='\033[1;33m' readonly RED='\033[0;31m' readonly NC='\033[0m' # Usage information usage() { cat < [options] Diagram Types: layered Generate layered architecture diagram microservices Generate microservices architecture diagram database Generate database architecture diagram network Generate network topology diagram component Generate component interaction diagram dataflow Generate data flow diagram Options: --title TEXT Set diagram title (default: architecture type) --color Enable colored output --help Show this help message Examples: $SCRIPT_NAME layered --title "Web Application Architecture" $SCRIPT_NAME microservices --color $SCRIPT_NAME database --title "E-commerce Database" Exit Codes: 0 - Success 1 - Error during execution 2 - Invalid input EOF } # Parse options parse_options() { DIAGRAM_TITLE="" USE_COLOR=false while [[ $# -gt 0 ]]; do case "$1" in --title) DIAGRAM_TITLE="$2" shift 2 ;; --color) USE_COLOR=true shift ;; --help) usage exit 0 ;; *) shift ;; esac done } # Draw a box draw_box() { local width="$1" local height="$2" local text="$3" local color="${4:-$NC}" # Top border echo -n "$color$TL" printf '%*s' "$((width-2))" '' | tr ' ' "$H" echo "$TR$NC" # Calculate padding for centered text local text_len=${#text} local padding=$(( (width - text_len - 2) / 2 )) local padding_right=$(( width - text_len - padding - 2 )) # Middle rows with text for ((i=1; i&2 echo "Run '$SCRIPT_NAME --help' for usage information" >&2 exit 2 ;; esac exit 0 } # Run main function main "$@"