{
  "project": "CMS SIMS Swiss",
  "version": "1.0.0",
  "rules": {
    "directory_structure": {
      "data": {
        "description": "Chứa dữ liệu JSON gốc",
        "naming": "<feature>.json",
        "required_fields": ["updatedAt"],
        "file_structure": {
          "sections": "Các section của trang",
          "images": "Đường dẫn bắt đầu bằng /uploads/<feature>/",
          "validation": "Tất cả trường bắt buộc phải có giá trị"
        }
      },
      "models": {
        "description": "Mongoose models",
        "naming": "<Feature>.js (PascalCase)",
        "required_fields": ["updatedAt"],
        "schema_rules": {
          "types": "Định nghĩa rõ type cho mỗi trường",
          "required": "Đánh dấu trường bắt buộc với required: true",
          "timestamps": "Sử dụng updatedAt tự động"
        }
      },
      "scripts": {
        "description": "Migration scripts",
        "naming": "migrate-<feature>.js",
        "required_functions": {
          "validate": "validate<Feature>Data()",
          "migrate": "migrate<Feature>Data()"
        },
        "error_handling": {
          "validation": "Kiểm tra đầy đủ trường và cấu trúc",
          "logging": "Log chi tiết quá trình migrate",
          "cleanup": "Xóa dữ liệu cũ trước khi migrate"
        }
      },
      "controllers": {
        "description": "Logic xử lý",
        "naming": "<feature>Controller.js",
        "required_methods": {
          "index": "GET /admin/<feature>",
          "update": "POST /admin/<feature>/update",
          "delete": "DELETE /admin/<feature>"
        },
        "features": {
          "validation": "Validate input data",
          "flash_messages": "Thông báo kết quả cho user",
          "error_handling": "Try-catch cho async functions"
        }
      },
      "views": {
        "structure": {
          "admin": "views/admin/<feature>/index.ejs",
          "page": "views/page/<feature>/index.ejs"
        },
        "components": {
          "layout": "Sử dụng layout chung",
          "forms": "Form validation và error handling",
          "buttons": "Consistent button styling",
          "messages": "Flash messages display"
        },
        "ui_rules": {
          "responsive": "Responsive design cho mọi màn hình",
          "loading": "Loading states cho async operations",
          "error": "Error states và messages",
          "success": "Success feedback"
        }
      }
    },
    "naming_conventions": {
      "files": "kebab-case (migrate-admissions.js)",
      "models": "PascalCase (Admissions)",
      "functions": "camelCase (validateData)",
      "routes": "kebab-case (/admin/about-us)",
      "variables": "camelCase (userData)"
    },
    "validation_rules": {
      "frontend": {
        "forms": "Client-side validation",
        "file_upload": "Kiểm tra type và size"
      },
      "backend": {
        "model": "Mongoose schema validation",
        "input": "Sanitize và validate input",
        "file": "Validate file types và limits"
      }
    },
    "error_handling": {
      "try_catch": "Bắt lỗi cho async functions",
      "messages": {
        "user": "Flash messages cho user feedback",
        "log": "Console.log cho development",
        "production": "Error logging service cho production"
      }
    },
    "security": {
      "input": "Validate và sanitize tất cả input",
      "file_upload": {
        "types": "Chỉ cho phép định dạng an toàn",
        "size": "Giới hạn kích thước file",
        "storage": "Lưu trữ an toàn với unique names"
      },
      "access": "Phân quyền admin/user"
    },
    "development_workflow": {
      "steps": [
        "1. Tạo JSON data mẫu",
        "2. Tạo Mongoose model",
        "3. Viết migration script",
        "4. Tạo controller",
        "5. Tạo admin view",
        "6. Tạo public view",
        "7. Test toàn bộ flow",
        "8. Review code"
      ],
      "testing": {
        "data": "Verify JSON structure",
        "model": "Test CRUD operations",
        "migration": "Test với dữ liệu mẫu",
        "ui": "Test responsive và interactions"
      }
    },
    "routing_rules": {
      "admin_routes": {
        "file": "routes/admin.js",
        "structure": {
          "base": "/admin/<feature>",
          "required_routes": {
            "index": "GET /<feature>",
            "update": "POST /<feature>/update"
          },
          "middleware": {
            "auth": "ensureAuthenticated",
            "upload": "upload.single('file')"
          }
        },
        "configuration": {
          "controller_import": "const <feature>Controller = require('../controllers/<feature>Controller')",
          "route_definition": "router.<method>('/<path>', middleware, controller.<action>)"
        }
      },
      "api_routes": {
        "file": "routes/index.js",
        "structure": {
          "base": "/api/<feature>",
          "required_routes": {
            "get": "GET /api/<feature>"
          }
        },
        "configuration": {
          "controller_import": "const <feature>Controller = require('../controllers/<feature>Controller')",
          "route_definition": "router.get('/api/<feature>', controller.api)"
        }
      }
    },
    "ui_standards": {
      "admin_views": {
        "layout": {
          "header": {
            "title": "Page title with breadcrumb",
            "actions": "Primary actions (Save, Reset)"
          },
          "tabs": {
            "structure": "Use nav-tabs for section navigation",
            "content": "Each tab contains related content"
          }
        },
        "section_cards": {
          "header": {
            "title": "Section title",
            "actions": "Add/Remove buttons"
          },
          "body": {
            "form_groups": "Grouped form elements",
            "validation": "Client-side validation"
          }
        },
        "item_management": {
          "header": {
            "position": "Action buttons in card header",
            "buttons": {
              "add": "Add new item button",
              "remove": "Remove item button"
            }
          },
          "container": {
            "structure": "Consistent padding and spacing",
            "style": "Border and background for separation"
          }
        },
        "form_elements": {
          "layout": "Bootstrap grid system",
          "spacing": "Consistent margins and padding",
          "validation": "Required field indicators",
          "feedback": "Error and success states"
        }
      }
    },
    "controller_standards": {
      "required_methods": {
        "index": {
          "purpose": "Render admin view with data",
          "response": "Render with layout and data"
        },
        "update": {
          "purpose": "Handle form submission",
          "validation": "Validate input data",
          "response": "Redirect with flash message"
        },
        "api": {
          "purpose": "Serve API data",
          "response": "JSON response with data"
        }
      },
      "error_handling": {
        "try_catch": "Wrap async operations",
        "validation": "Input data validation",
        "messages": "Flash messages for feedback"
      }
    },
    "message_standards": {
      "language": "English",
      "flash_messages": {
        "success": {
          "create": "Successfully created [resource]",
          "update": "Successfully updated [resource]",
          "delete": "Successfully deleted [resource]",
          "upload": "Successfully uploaded [resource]"
        },
        "error": {
          "not_found": "[Resource] not found",
          "invalid_input": "Invalid input data",
          "validation": "Please check your input and try again",
          "upload": "Failed to upload [resource]",
          "server": "An error occurred. Please try again"
        },
        "info": {
          "processing": "Processing your request",
          "no_changes": "No changes detected",
          "confirm_delete": "Are you sure you want to delete this [resource]?"
        }
      },
      "validation_messages": {
        "required": "This field is required",
        "invalid_format": "Invalid format",
        "min_length": "Must be at least [n] characters",
        "max_length": "Must not exceed [n] characters",
        "invalid_type": "Invalid type. Expected [type]",
        "unique": "This [field] already exists"
      },
      "api_responses": {
        "success": {
          "200": "Request successful",
          "201": "Resource created successfully",
          "204": "Resource deleted successfully"
        },
        "error": {
          "400": "Bad request - Invalid input",
          "401": "Unauthorized - Please login",
          "403": "Forbidden - Insufficient permissions",
          "404": "Resource not found",
          "500": "Internal server error"
        }
      },
      "format_rules": {
        "capitalization": "First letter capitalized",
        "punctuation": "End with proper punctuation",
        "placeholders": "Use [placeholder] format",
        "consistency": "Use same message for same actions"
      }
    },
    "data_management_standards": {
      "form_data_handling": {
        "preparation": {
          "hidden_inputs": {
            "purpose": "Store JSON data for complex sections",
            "naming": "<section>Json (e.g. bannerJson, overviewJson)",
            "structure": "Hidden input for each major section"
          },
          "data_collection": {
            "method": "Collect all form data before submission",
            "validation": "Validate required fields and data types",
            "structure": "Group data by logical sections"
          }
        },
        "json_conversion": {
          "sections": {
            "main_data": "Primary section information (title, description)",
            "items_data": "Array of items with consistent structure",
            "media_data": "Image paths and media information"
          },
          "validation": {
            "required_fields": "Check all required fields before conversion",
            "data_types": "Ensure correct data types for each field",
            "structure": "Maintain consistent JSON structure"
          }
        }
      },
      "save_process": {
        "client_side": {
          "data_collection": {
            "form_data": "Collect all form inputs",
            "file_data": "Handle file uploads separately",
            "validation": "Client-side validation before submit"
          },
          "json_preparation": {
            "structure": "Prepare structured JSON data",
            "hidden_fields": "Update hidden JSON inputs",
            "validation": "Validate JSON structure"
          }
        },
        "server_side": {
          "data_processing": {
            "validation": "Server-side validation of all data",
            "sanitization": "Clean and sanitize input data",
            "transformation": "Transform data to required format"
          },
          "file_handling": {
            "upload": "Process and store uploaded files",
            "paths": "Update file paths in data",
            "cleanup": "Remove unused files"
          },
          "database_update": {
            "transaction": "Use transactions for complex updates",
            "validation": "Validate data before saving",
            "backup": "Backup existing data before update"
          }
        }
      },
      "response_handling": {
        "success": {
          "redirect": "Redirect to appropriate page",
          "message": "Display success message via toast",
          "data_refresh": "Refresh displayed data"
        },
        "error": {
          "validation": "Show specific validation errors",
          "server": "Handle and display server errors",
          "recovery": "Maintain form data for recovery"
        }
      },
      "data_structure": {
        "sections": {
          "main": {
            "title": "Section title field",
            "description": "Section description field",
            "image": "Main image path if applicable"
          },
          "items": {
            "structure": "Array of related items",
            "required_fields": ["title", "description"],
            "optional_fields": ["image", "order"]
          }
        },
        "relationships": {
          "parent_child": "Maintain parent-child relationships",
          "ordering": "Maintain item order in lists",
          "references": "Handle references between sections"
        }
      }
    }
  }
} 