BMAD-METHOD/expansion-packs/bmad-c4-architecture/install.sh

315 lines
9.7 KiB
Bash
Executable File

#!/bin/bash
# BMAD C4 Architecture Expansion Pack Installation Script
# This script installs the C4 Architecture expansion pack into a BMAD-METHOD project
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Check for Windows line endings and fix them
if [ -f "install.sh" ] && file install.sh | grep -q "CRLF"; then
echo -e "${BLUE}🔧 Detected Windows line endings - fixing...${NC}"
# Convert Windows line endings to Unix line endings using sed
sed -i 's/\r$//' install.sh
echo -e "${GREEN}✅ Line endings converted successfully${NC}"
fi
# Check if we're running in PowerShell and provide instructions
if [ -n "$PSVersionTable" ] || [ -n "$POWERSHELL_DISTRIBUTION_CHANNEL" ]; then
echo -e "${YELLOW}⚠️ PowerShell detected. If you get line ending errors, run:${NC}"
echo -e "${BLUE} (Get-Content install.sh -Raw) -replace \"\`r\`n\", \"\`n\" | Set-Content install.sh -NoNewline${NC}"
echo
fi
# Configuration
EXPANSION_PACK_NAME="bmad-c4-architecture"
TARGET_DIR=".bmad-c4-architecture"
SOURCE_DIR="$(dirname "$0")"
echo -e "${BLUE}🏛️ BMAD C4 Architecture Expansion Pack Installer${NC}"
echo "=================================================="
# Check if we're in the expansion pack directory and BMAD-METHOD root exists
if [ ! -f "agents/c4-architect.md" ]; then
echo -e "${RED}❌ Error: Please run this script from the bmad-c4-architecture directory${NC}"
echo "Current directory: $(pwd)"
exit 1
fi
# Check if BMAD-METHOD root exists
if [ ! -d "../../bmad-core" ]; then
echo -e "${RED}❌ Error: BMAD-METHOD root directory not found${NC}"
echo "Expected: ../../bmad-core"
echo "Current directory: $(pwd)"
exit 1
fi
# Check if expansion pack already exists
if [ -d "$TARGET_DIR" ]; then
echo -e "${YELLOW}⚠️ Expansion pack already exists at $TARGET_DIR${NC}"
read -p "Do you want to overwrite it? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Installation cancelled."
exit 0
fi
echo -e "${YELLOW}Removing existing expansion pack...${NC}"
rm -rf "$TARGET_DIR"
fi
# Create BMAD-METHOD directories if they don't exist
echo -e "${BLUE}📁 Creating BMAD-METHOD directories...${NC}"
mkdir -p "../../bmad-core/agents"
mkdir -p "../../bmad-core/tasks"
mkdir -p "../../bmad-core/templates"
mkdir -p "../../bmad-core/data"
mkdir -p "../../bmad-core/checklists"
mkdir -p "../../bmad-core/agent-teams"
mkdir -p "../../bmad-core/workflows"
# Copy expansion pack files to BMAD-METHOD
echo -e "${BLUE}📋 Copying expansion pack files to BMAD-METHOD...${NC}"
cp agents/*.md "../../bmad-core/agents/"
cp tasks/*.md "../../bmad-core/tasks/"
cp templates/*.yaml "../../bmad-core/templates/"
cp data/*.md "../../bmad-core/data/"
cp checklists/*.md "../../bmad-core/checklists/"
cp agent-teams/*.yaml "../../bmad-core/agent-teams/"
cp workflows/*.yaml "../../bmad-core/workflows/"
# Update core configuration
echo -e "${BLUE}⚙️ Updating core configuration...${NC}"
if [ -f ".bmad-core/core-config.yaml" ]; then
# Backup existing config
cp ".bmad-core/core-config.yaml" ".bmad-core/core-config.yaml.backup"
echo -e "${YELLOW}📋 Backed up existing core-config.yaml${NC}"
fi
# Create or update core config to include C4 architecture
cat > ".bmad-core/core-config.yaml" << EOF
# BMAD Core Configuration
# This file is automatically generated by the C4 Architecture expansion pack
# Developer context files
devLoadAlwaysFiles:
- docs/architecture/coding-standards.md
- docs/architecture/tech-stack.md
- docs/architecture/project-structure.md
# Expansion pack configurations
expansionPacks:
- name: "c4-architecture"
enabled: true
config: ".bmad-c4-architecture/config.yaml"
# C4 Architecture specific settings
c4Architecture:
structurizrLiteUrl: "http://localhost:8080"
defaultTheme: "default"
exportFormats: ["png", "svg", "pdf", "dsl"]
autoLayout: true
validationStrict: true
EOF
# Create example technical preferences
if [ ! -f ".bmad-c4-architecture/data/technical-preferences.md" ]; then
echo -e "${BLUE}📝 Creating example technical preferences...${NC}"
cat > ".bmad-c4-architecture/data/technical-preferences.md" << EOF
# Technical Preferences for C4 Architecture
## Preferred Technologies
### Frontend
- React, Vue.js, Angular
- TypeScript preferred over JavaScript
- Tailwind CSS for styling
### Backend
- Node.js, Python, Java, Go
- RESTful APIs preferred
- GraphQL for complex data requirements
### Databases
- PostgreSQL for relational data
- MongoDB for document storage
- Redis for caching
### Cloud Platforms
- AWS, Azure, Google Cloud
- Docker for containerization
- Kubernetes for orchestration
## Architecture Patterns
### Microservices
- Domain-driven design
- Event-driven architecture
- API-first approach
### Security
- OAuth 2.0 / OpenID Connect
- JWT tokens
- HTTPS everywhere
## Diagram Preferences
### Styling
- Consistent color scheme
- Clear, readable fonts
- Minimal, clean layouts
### Naming
- Business terminology in context diagrams
- Technical terminology in container/component diagrams
- Consistent naming conventions
EOF
fi
# Check for Structurizr Lite dependencies
echo -e "${BLUE}🔍 Checking for Structurizr Lite dependencies...${NC}"
# Check for Docker (recommended)
if command -v docker &> /dev/null; then
echo -e "${GREEN}✅ Docker found - recommended for Structurizr Lite${NC}"
echo -e "${BLUE}💡 To start Structurizr Lite with Docker:${NC}"
echo " docker pull structurizr/lite"
echo " docker run -it --rm -p 8080:8080 -v ~/structurizr:/usr/local/structurizr structurizr/lite"
else
echo -e "${YELLOW}⚠️ Docker not found. You can install Docker or use Java 17+ instead.${NC}"
fi
# Check for Java (alternative)
if command -v java &> /dev/null; then
JAVA_VERSION=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2 | cut -d'.' -f1)
if [ "$JAVA_VERSION" -lt 17 ]; then
echo -e "${YELLOW}⚠️ Java version $JAVA_VERSION found. Structurizr Lite Spring Boot requires Java 17+.${NC}"
echo "Please upgrade to Java 17 or later, or use Docker instead."
echo "Visit: https://adoptium.net/"
else
echo -e "${GREEN}✅ Java $JAVA_VERSION found - compatible with Structurizr Lite Spring Boot${NC}"
fi
else
echo -e "${YELLOW}⚠️ Java not found. Install Java 17+ or use Docker instead.${NC}"
echo "Visit: https://adoptium.net/"
fi
# Create example workspace
echo -e "${BLUE}📄 Creating example workspace...${NC}"
cat > ".bmad-c4-architecture/examples/example-workspace.dsl" << EOF
workspace "Example E-commerce Platform" "A sample e-commerce platform architecture" {
model {
customer = person "Customer" "A customer of the e-commerce platform"
admin = person "Administrator" "An administrator of the e-commerce platform"
ecommerce = softwareSystem "E-commerce Platform" "Allows customers to browse and purchase products" {
webApp = container "Web Application" "Provides the user interface" "React, TypeScript" {
customer -> this "Uses" "HTTPS"
admin -> this "Uses" "HTTPS"
}
api = container "API" "Provides business logic" "Node.js, Express" {
webApp -> this "Makes API calls" "HTTPS/REST"
}
database = container "Database" "Stores data" "PostgreSQL" {
api -> this "Reads from and writes to" "SQL"
}
paymentGateway = softwareSystem "Payment Gateway" "Processes payments" "External"
api -> paymentGateway "Sends payment requests" "HTTPS/API"
}
}
views {
systemContext ecommerce {
include *
autolayout lr
}
container ecommerce {
include *
autolayout lr
}
theme default
}
}
EOF
# Create quick start guide
echo -e "${BLUE}📚 Creating quick start guide...${NC}"
cat > ".bmad-c4-architecture/QUICKSTART.md" << EOF
# C4 Architecture Quick Start Guide
## 1. Start Structurizr Lite (Optional)
\`\`\`bash
# Download and run Structurizr Lite
git clone https://github.com/structurizr/lite.git
cd lite
./gradlew bootRun
# Access at http://localhost:8080
\`\`\`
## 2. Use the C4 Architect Agent
\`\`\`bash
# In your IDE
@c4-architect
*help
\`\`\`
## 3. Create Your First Diagram
\`\`\`bash
# Create a context diagram
*create-context
# Follow the interactive prompts to define:
# - System name and description
# - Users and their goals
# - External systems
# - Key relationships
\`\`\`
## 4. Generate Complete Workspace
\`\`\`bash
# Generate full Structurizr DSL
*generate-dsl
# Validate your model
*validate-model
# Export diagrams
*export-diagrams
\`\`\`
## 5. Example Files
- \`examples/example-workspace.dsl\` - Sample Structurizr DSL
- \`data/technical-preferences.md\` - Your technical preferences
- \`README.md\` - Complete documentation
## Next Steps
1. Read the full README.md for comprehensive documentation
2. Customize technical-preferences.md for your project
3. Start creating your architecture diagrams!
EOF
# Final success message
echo ""
echo -e "${GREEN}🎉 C4 Architecture Expansion Pack installed successfully!${NC}"
echo ""
echo -e "${BLUE}📁 Installation location: $TARGET_DIR${NC}"
echo -e "${BLUE}📚 Quick start guide: $TARGET_DIR/QUICKSTART.md${NC}"
echo -e "${BLUE}📖 Full documentation: $TARGET_DIR/README.md${NC}"
echo ""
echo -e "${YELLOW}🚀 Next steps:${NC}"
echo "1. Read the quick start guide: $TARGET_DIR/QUICKSTART.md"
echo "2. Start Structurizr Lite (optional): http://localhost:8080"
echo "3. Use the C4 Architect agent in your IDE: @c4-architect"
echo ""
echo -e "${GREEN}Happy architecting! 🏛️${NC}"