Cursor rule
.cursor/rules/makefile-scripting.mdcMakefile and shell scripting patterns for POS System development workflow
Cursor rules
Quality
81/100
Scores the file, not the repository.Length
1,151 words
72 headings · 24 code blocksRepository
118
— · pushed 339 days agoLast changed
3 days ago
First indexed 3 days ago.123456# Makefile & Shell Scripting Guidelines78## Makefile Structure910### Main Makefile Organization11Follow the patterns established in [Makefile](mdc:Makefile):1213### Standard Makefile Headers14```makefile15# POS System - Development Makefile16# Usage: make <command>1718.PHONY: help dev prod up down build logs clean backup restore create-admin remove-data db-shell test lint format1920# Default target21.DEFAULT_GOAL := help2223# Colors for output24GREEN := \033[0;32m25YELLOW := \033[0;33m26RED := \033[0;31m27BLUE := \033[0;34m28NC := \033[0m # No Color29```3031### Command Categories32Organize commands into logical groups:331. **Development Commands** - dev, prod, up, down, restart, build342. **Database Commands** - create-admin, remove-data, backup, restore, db-shell, db-reset353. **Utility Commands** - logs, status, clean, test, lint, format364. **Quick Shortcuts** - start, stop, install3738### Help System Pattern39```makefile40## Help - Display available commands41help:42 @echo "$(BLUE)POS System - Available Make Commands$(NC)"43 @echo ""44 @echo "$(GREEN)Development Commands:$(NC)"45 @echo " make dev - Start development environment with hot reloading"46 # ... more help text47```4849## Docker Integration5051### Docker Compose File Selection52```makefile53# Docker compose files54COMPOSE_DEV := docker-compose.dev.yml55COMPOSE_PROD := docker-compose.yml5657# Development environment58dev:59 @docker compose -f $(COMPOSE_DEV) up --build6061# Production environment62prod:63 @docker compose -f $(COMPOSE_PROD) up -d --build64```6566### Container Management67```makefile68# Check container status before operations69up:70 @echo "$(GREEN)⬆️ Starting Docker containers...$(NC)"71 @docker compose -f $(COMPOSE_DEV) up -d72 @echo "$(GREEN)✅ Containers started in background$(NC)"7374down:75 @echo "$(YELLOW)⬇️ Stopping Docker containers...$(NC)"76 @docker compose -f $(COMPOSE_DEV) down77 @docker compose -f $(COMPOSE_PROD) down 2>/dev/null || true78 @echo "$(GREEN)✅ Containers stopped$(NC)"79```8081## Shell Script Patterns8283### Script Structure84Follow the patterns from [scripts/](mdc:scripts/) directory:8586### Standard Script Headers87```bash88#!/bin/bash8990# Script Description91# Brief description of what this script does9293set -e # Exit on any error9495# Colors96GREEN='\033[0;32m'97YELLOW='\033[0;33m'98RED='\033[0;31m'99BLUE='\033[0;34m'100NC='\033[0m' # No Color101```102103### Container Detection Pattern104```bash105# Check if database container is running106CONTAINER_NAME="pos-postgres-dev"107if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then108 CONTAINER_NAME="pos-postgres"109 if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then110 echo -e "${RED}❌ Database container is not running!${NC}"111 echo -e "${YELLOW}Please run 'make up' or 'make dev' first.${NC}"112 exit 1113 fi114fi115```116117### User Input Validation118```bash119# Safe user input with validation120read -p "Username: " USERNAME121while [[ -z "$USERNAME" ]]; do122 echo -e "${RED}Username cannot be empty!${NC}"123 read -p "Username: " USERNAME124done125126# Hidden password input127echo -n "Password: "128read -s PASSWORD129echo ""130```131132### Confirmation Patterns133```bash134# Multiple confirmation levels for destructive operations135echo -e "${RED}⚠️ WARNING: This will DELETE ALL DATA!${NC}"136echo -e "${YELLOW}Type 'DELETE ALL DATA' to confirm (case sensitive):${NC}"137read -p "> " FINAL_CONFIRMATION138139if [[ "$FINAL_CONFIRMATION" != "DELETE ALL DATA" ]]; then140 echo -e "${BLUE}❌ Operation cancelled. Data is safe.${NC}"141 exit 0142fi143```144145### Database Operations146```bash147# Database backup with error handling148echo -e "${YELLOW}💾 Creating backup...${NC}"149DB_BACKUP_FILE="${BACKUP_DIR}/${BACKUP_NAME}_database.sql"150151docker exec $CONTAINER_NAME pg_dump \152 -U postgres \153 -d pos_system \154 --clean \155 --if-exists \156 --create \157 --verbose \158 --format=plain > $DB_BACKUP_FILE159160if [[ $? -eq 0 ]]; then161 DB_SIZE=$(du -h $DB_BACKUP_FILE | cut -f1)162 echo -e "${GREEN}✅ Database backup created: $DB_BACKUP_FILE ($DB_SIZE)${NC}"163else164 echo -e "${RED}❌ Database backup failed!${NC}"165 exit 1166fi167```168169## Error Handling170171### Comprehensive Error Checking172```bash173# Always check command success174if [[ $? -eq 0 ]]; then175 echo -e "${GREEN}✅ Operation completed successfully!${NC}"176else177 echo -e "${RED}❌ Operation failed!${NC}"178 exit 1179fi180```181182### Emergency Backup Pattern183```bash184# Create emergency backup before destructive operations185EMERGENCY_BACKUP="$BACKUP_DIR/emergency_backup_$(date +%Y%m%d_%H%M%S).sql"186echo -e "${BLUE}Creating emergency backup: $EMERGENCY_BACKUP${NC}"187docker exec $CONTAINER_NAME pg_dump -U postgres pos_system > $EMERGENCY_BACKUP188```189190## File and Directory Management191192### Backup Directory Structure193```bash194# Create backup directory if it doesn't exist195BACKUP_DIR="backups"196mkdir -p $BACKUP_DIR197198# Generate timestamp for backup files199TIMESTAMP=$(date +"%Y%m%d_%H%M%S")200BACKUP_NAME="pos_backup_${TIMESTAMP}"201```202203### File Size and Statistics204```bash205# Show file sizes and statistics206if [[ -f "$DB_BACKUP_FILE" ]]; then207 DB_SIZE=$(du -h $DB_BACKUP_FILE | cut -f1)208 echo -e "${GREEN}✅ Database backup: $DB_BACKUP_FILE ($DB_SIZE)${NC}"209fi210211# Count records in database212USER_COUNT=$(docker exec $CONTAINER_NAME psql -U postgres -d pos_system -tAc "SELECT COUNT(*) FROM users;")213echo " Users: $USER_COUNT"214```215216## Interactive Menus217218### Backup Selection Menu219```bash220# List available backups with numbered selection221BACKUP_FILES=()222INDEX=1223224for file in $BACKUP_DIR/pos_backup_*_complete.tar.gz; do225 if [[ -f "$file" ]]; then226 echo "$INDEX) $(basename "$file" .tar.gz)"227 echo " Date: $READABLE_DATE"228 echo " Size: $FILE_SIZE"229 BACKUP_FILES+=("$file")230 ((INDEX++))231 fi232done233234# Get user selection with validation235read -p "> " SELECTION236if ! [[ "$SELECTION" =~ ^[0-9]+$ ]] || [[ $SELECTION -lt 1 ]] || [[ $SELECTION -gt ${#BACKUP_FILES[@]} ]]; then237 echo -e "${RED}❌ Invalid selection!${NC}"238 exit 1239fi240```241242## Security Best Practices243244### Safe SQL Operations245```bash246# Use proper SQL escaping and parameterization247docker exec $CONTAINER_NAME psql -U postgres -d pos_system -c "248INSERT INTO users (username, email, password_hash, first_name, last_name, role, is_active)249VALUES ('$USERNAME', '$EMAIL', '$TEMP_HASH', '$FIRST_NAME', '$LAST_NAME', 'admin', true);250"251```252253### Temporary File Handling254```bash255# Clean up temporary files256TEMP_DIR=$(mktemp -d)257# ... operations ...258rm -rf "$TEMP_DIR"259```260261## Output Formatting262263### Colored Output System264- 🔴 `${RED}` - Errors, warnings, destructive operations265- 🟡 `${YELLOW}` - Important information, confirmations266- 🔵 `${BLUE}` - Informational messages, file paths267- 🟢 `${GREEN}` - Success messages, completed operations268269### Status Indicators270```bash271echo -e "${GREEN}✅ Success${NC}"272echo -e "${RED}❌ Error${NC}"273echo -e "${YELLOW}⚠️ Warning${NC}"274echo -e "${BLUE}ℹ️ Information${NC}"275```276277### Progress Indicators278```bash279echo -e "${YELLOW}🔄 Processing...${NC}"280echo -e "${YELLOW}💾 Creating backup...${NC}"281echo -e "${YELLOW}📥 Restoring data...${NC}"282echo -e "${YELLOW}🗑️ Cleaning up...${NC}"283```284285## Integration with Docker286287### Container Health Checks288```bash289# Check if container is healthy290if [ -z "$(docker ps -q -f name=pos-postgres)" ]; then291 echo -e "${RED}❌ Database container is not running!${NC}"292 exit 1293fi294```295296### Docker Volume Operations297```bash298# Backup Docker volumes299VOLUMES=$(docker volume ls --filter name=pos --format "{{.Name}}")300if [[ -n "$VOLUMES" ]]; then301 docker run --rm -v pos-postgres-data:/data -v $(pwd)/${BACKUP_DIR}:/backup alpine sh -c "cd /data && tar czf /backup/${BACKUP_NAME}_volumes.tar.gz ."302fi303```304305## Development Workflow Integration306307### Environment File Creation308```makefile309dev:310 @if [ ! -f .env ]; then \311 echo "$(YELLOW)📝 Creating .env file...$(NC)"; \312 cp .env.example .env 2>/dev/null || \313 echo "DB_HOST=postgres\nDB_PORT=5432\nDB_USER=postgres\nDB_PASSWORD=postgres123\nDB_NAME=pos_system\nDB_SSLMODE=disable\nPORT=8080\nGIN_MODE=debug\nVITE_API_URL=http://localhost:8080" > .env; \314 fi315```316317### Multi-Service Log Viewing318```makefile319logs-backend:320 @echo "$(GREEN)📋 Viewing backend logs...$(NC)"321 @docker compose -f $(COMPOSE_DEV) logs -f backend322```323324## Testing and Validation325326### Script Testing327```bash328# Test database connectivity329docker exec $CONTAINER_NAME psql -U postgres -c "SELECT 1;" > /dev/null330if [[ $? -eq 0 ]]; then331 echo -e "${GREEN}✅ Database connection successful${NC}"332else333 echo -e "${RED}❌ Cannot connect to database${NC}"334 exit 1335fi336```337338### Makefile Target Testing339```makefile340# Test all services are running341status:342 @echo "$(GREEN)📊 Service Status:$(NC)"343 @if [ -n "$$(docker ps -q -f name=pos-backend)" ]; then \344 echo "✅ Backend: Available"; \345 else \346 echo "❌ Backend: Not running"; \347 fi348```
Also in madebyaris/poinf-of-sales
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| madebyaris/poinf-of-sales.cursor/rules/admin-interface-patterns.mdc · 118 | Cursor rules | stylearchsecurityapi+2 | 62/100 | 3 days ago | |
| madebyaris/poinf-of-sales.cursor/rules/api-patterns.mdc · 118 | Cursor rules | lint-formatstylesecuritydatabase+3 | 62/100 | 3 days ago | |
| madebyaris/poinf-of-sales.cursor/rules/authentication-and-security-patterns.mdc · 118 | Cursor rules | setupteststylesecurity+4 | 81/100 | 3 days ago | |
| madebyaris/poinf-of-sales.cursor/rules/backend-golang.mdc · 118 | Cursor rules | testlint-formatstylearch+5 | 69/100 | 3 days ago | |
| madebyaris/poinf-of-sales.cursor/rules/business-logic-patterns.mdc · 118 | Cursor rules | teststyledatabaseperformance+1 | 50/100 | 3 days ago | |
| madebyaris/poinf-of-sales.cursor/rules/database-patterns.mdc · 118 | Cursor rules | stylearchtypessecurity+2 | 62/100 | 3 days ago | |
| madebyaris/poinf-of-sales.cursor/rules/development-workflow.mdc · 118 | Cursor rules | setupbuildteststyle+3 | 86/100 | 3 days ago | |
| madebyaris/poinf-of-sales.cursor/rules/docker-deployment.mdc · 118 | Cursor rules | setupbuildteststyle+8 | 77/100 | 3 days ago | |
| madebyaris/poinf-of-sales.cursor/rules/frontend-react.mdc · 118 | Cursor rules | buildtestlint-formatstyle+4 | 69/100 | 3 days ago | |
| madebyaris/poinf-of-sales.cursor/rules/performance-optimization-patterns.mdc · 118 | Cursor rules | buildteststyledatabase+3 | 66/100 | 3 days ago | |
| madebyaris/poinf-of-sales.cursor/rules/project-architecture.mdc · 118 | Cursor rules | setupteststylearch+6 | 78/100 | 3 days ago | |
| madebyaris/poinf-of-sales.cursor/rules/react-native-mobile-patterns.mdc · 118 | Cursor rules | buildstylearchui+2 | 74/100 | 3 days ago | |
| madebyaris/poinf-of-sales.cursor/rules/role-based-access-patterns.mdc · 118 | Cursor rules | styletypessecuritydatabase+2 | 58/100 | 3 days ago | |
| madebyaris/poinf-of-sales.cursor/rules/tech-debt-prevention.mdc · 118 | Cursor rules | styletesting-strategyui | 50/100 | 3 days ago | |
| madebyaris/poinf-of-sales.cursor/rules/testing-patterns.mdc · 118 | Cursor rules | setupteststylearch+4 | 74/100 | 3 days ago | |
| madebyaris/poinf-of-sales.cursor/rules/user-journey-optimization.mdc · 118 | Cursor rules | styleperformanceagent-behaviour | 50/100 | 3 days ago |
Diff against .cursor/rules/admin-interface-patterns.mdc Diff against .cursor/rules/api-patterns.mdc Diff against .cursor/rules/authentication-and-security-patterns.mdc Diff against .cursor/rules/backend-golang.mdc Diff against .cursor/rules/business-logic-patterns.mdc Diff against .cursor/rules/database-patterns.mdc Diff against .cursor/rules/development-workflow.mdc Diff against .cursor/rules/docker-deployment.mdc Diff against .cursor/rules/frontend-react.mdc Diff against .cursor/rules/performance-optimization-patterns.mdc Diff against .cursor/rules/project-architecture.mdc Diff against .cursor/rules/react-native-mobile-patterns.mdc Diff against .cursor/rules/role-based-access-patterns.mdc Diff against .cursor/rules/tech-debt-prevention.mdc Diff against .cursor/rules/testing-patterns.mdc Diff against .cursor/rules/user-journey-optimization.mdc
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
