
{
  "entities": {
    "Business": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "title": "Business",
      "type": "object",
      "description": "Represents a business profile in the directory.",
      "properties": {
        "id": {
          "type": "string",
          "description": "Unique identifier for the business entity."
        },
        "name": {
          "type": "string",
          "description": "Name of the business."
        },
        "description": {
          "type": "string",
          "description": "Description of the business."
        },
        "contactDetails": {
          "type": "string",
          "description": "Contact details for the business (e.g., phone number, email, address)."
        },
        "openingHours": {
          "type": "string",
          "description": "Opening hours of the business."
        },
        "categoryIds": {
          "type": "array",
          "description": "References to Categories. (Relationship: Category N:N Business)",
          "items": {
            "type": "string"
          }
        },
        "latitude": {
          "type": "number",
          "description": "Latitude coordinate of the business location."
        },
        "longitude": {
          "type": "number",
          "description": "Longitude coordinate of the business location."
        }
      },
      "required": [
        "id",
        "name",
        "description",
        "contactDetails",
        "openingHours",
        "latitude",
        "longitude"
      ]
    },
    "Category": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "title": "Category",
      "type": "object",
      "description": "Represents a category of services.",
      "properties": {
        "id": {
          "type": "string",
          "description": "Unique identifier for the category entity."
        },
        "name": {
          "type": "string",
          "description": "Name of the category."
        },
        "description": {
          "type": "string",
          "description": "Description of the category."
        }
      },
      "required": [
        "id",
        "name",
        "description"
      ]
    },
    "Review": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "title": "Review",
      "type": "object",
      "description": "Represents a user review for a business.",
      "properties": {
        "id": {
          "type": "string",
          "description": "Unique identifier for the review entity."
        },
        "businessId": {
          "type": "string",
          "description": "Reference to Business. (Relationship: Business 1:N Review)"
        },
        "userId": {
          "type": "string",
          "description": "Reference to User. (Relationship: User 1:N Review). Represents the user who wrote the review."
        },
        "rating": {
          "type": "number",
          "description": "Rating given by the user (e.g., 1-5)."
        },
        "comment": {
          "type": "string",
          "description": "Text of the review comment."
        },
        "createdAt": {
          "type": "string",
          "description": "Timestamp of when the review was created.",
          "format": "date-time"
        }
      },
      "required": [
        "id",
        "businessId",
        "userId",
        "rating",
        "comment",
        "createdAt"
      ]
    },
    "User": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "title": "User",
      "type": "object",
      "description": "Represents a user of the application.",
      "properties": {
        "id": {
          "type": "string",
          "description": "Unique identifier for the user entity."
        },
        "username": {
          "type": "string",
          "description": "Username of the user."
        },
        "email": {
          "type": "string",
          "description": "Email address of the user.",
          "format": "email"
        },
        "isAdmin": {
          "type": "boolean",
          "description": "Indicates if the user has administrative privileges."
        }
      },
      "required": [
        "id",
        "username",
        "email"
      ]
    },
    "BusinessSubscription": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "title": "BusinessSubscription",
      "type": "object",
      "description": "Represents a subscription for a business.",
      "properties": {
        "id": {
          "type": "string",
          "description": "Unique identifier for the subscription entity."
        },
        "businessId": {
          "type": "string",
          "description": "Reference to the Business."
        },
        "planId": {
          "type": "string",
          "description": "Reference to the SubscriptionPlan."
        },
        "status": {
          "type": "string",
          "description": "Status of the subscription.",
          "enum": ["pending", "active", "expired", "rejected"]
        },
        "requestDate": {
          "type": "string",
          "description": "Timestamp of when the subscription was requested.",
          "format": "date-time"
        },
        "startDate": {
          "type": "string",
          "description": "Timestamp of when the subscription started.",
          "format": "date-time"
        },
        "expiryDate": {
          "type": "string",
          "description": "Timestamp of when the subscription expires.",
          "format": "date-time"
        }
      },
      "required": [
        "id",
        "businessId",
        "planId",
        "status",
        "requestDate"
      ]
    },
    "Country": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "title": "Country",
      "type": "object",
      "description": "Represents a country.",
      "properties": {
        "id": {
          "type": "string",
          "description": "Unique identifier for the country entity."
        },
        "name": {
          "type": "string",
          "description": "Name of the country."
        }
      },
      "required": ["id", "name"]
    },
    "City": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "title": "City",
      "type": "object",
      "description": "Represents a city within a country.",
      "properties": {
        "id": {
          "type": "string",
          "description": "Unique identifier for the city entity."
        },
        "name": {
          "type": "string",
          "description": "Name of the city."
        },
        "countryId": {
          "type": "string",
          "description": "Reference to Country."
        }
      },
      "required": ["id", "name", "countryId"]
    },
    "AppSettings": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "title": "AppSettings",
      "type": "object",
      "description": "Stores global application settings.",
      "properties": {
        "appName": { "type": "string", "description": "The name of the application." },
        "appVersion": { "type": "string", "description": "The current version of the application." },
        "contactEmail": { "type": "string", "format": "email", "description": "The primary contact email." },
        "contactPhone": { "type": "string", "description": "The primary contact phone number." },
        "contactAddress": { "type": "string", "description": "The physical contact address." }
      },
      "required": ["appName", "appVersion"]
    },
     "SubscriptionPlan": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "title": "SubscriptionPlan",
      "type": "object",
      "description": "Represents a subscription plan for businesses.",
      "properties": {
        "id": { "type": "string", "description": "Unique identifier for the plan." },
        "name": { "type": "string", "description": "Name of the plan." },
        "durationInDays": { "type": "number", "description": "Duration of the plan in days." },
        "price": { "type": "number", "description": "Price of the plan." }
      },
      "required": ["id", "name", "durationInDays", "price"]
    }
  },
  "auth": {
    "providers": [
      "password",
      "anonymous"
    ]
  },
  "firestore": {
    "structure": [
      {
        "path": "/businesses/{businessId}",
        "definition": {
          "entityName": "Business",
          "schema": {
            "$ref": "#/backend/entities/Business"
          },
          "description": "Stores business profiles. Includes the denormalized `id` as `businessId`.",
          "params": [
            {
              "name": "businessId",
              "description": "The unique identifier for the business."
            }
          ]
        }
      },
      {
        "path": "/categories/{categoryId}",
        "definition": {
          "entityName": "Category",
          "schema": {
            "$ref": "#/backend/entities/Category"
          },
          "description": "Stores service categories.",
          "params": [
            {
              "name": "categoryId",
              "description": "The unique identifier for the category."
            }
          ]
        }
      },
      {
        "path": "/users/{userId}",
        "definition": {
          "entityName": "User",
          "schema": {
            "$ref": "#/backend/entities/User"
          },
          "description": "Stores user profiles. The `userId` is also the Firebase Authentication UID.",
          "params": [
            {
              "name": "userId",
              "description": "The unique identifier for the user, matching the Firebase Auth UID."
            }
          ]
        }
      },
      {
        "path": "/businesses/{businessId}/reviews/{reviewId}",
        "definition": {
          "entityName": "Review",
          "schema": {
            "$ref": "#/backend/entities/Review"
          },
          "description": "Stores user reviews for businesses. Includes the denormalized `businessId` and `userId` from the parent documents to ensure authorization independence. This allows rules to validate that the authenticated user matches the `userId` field and that the review belongs to an existing business.",
          "params": [
            {
              "name": "businessId",
              "description": "The unique identifier for the business being reviewed."
            },
            {
              "name": "reviewId",
              "description": "The unique identifier for the review."
            }
          ]
        }
      },
      {
        "path": "/countries/{countryId}",
        "definition": {
          "entityName": "Country",
          "schema": { "$ref": "#/backend/entities/Country" },
          "description": "Stores a managed list of countries.",
          "params": [{ "name": "countryId", "description": "The unique ID for the country." }]
        }
      },
      {
        "path": "/cities/{cityId}",
        "definition": {
          "entityName": "City",
          "schema": { "$ref": "#/backend/entities/City" },
          "description": "Stores a managed list of cities.",
          "params": [{ "name": "cityId", "description": "The unique ID for the city." }]
        }
      },
       {
        "path": "/settings/{settingId}",
        "definition": {
          "entityName": "AppSettings",
          "schema": { "$ref": "#/backend/entities/AppSettings" },
          "description": "Stores global application settings. Assumes a single document (e.g., 'app') for all settings.",
          "params": [{ "name": "settingId", "description": "The unique identifier for the settings document (e.g., 'app')." }]
        }
      },
      {
        "path": "/subscriptionPlans/{planId}",
        "definition": {
          "entityName": "SubscriptionPlan",
          "schema": { "$ref": "#/backend/entities/SubscriptionPlan" },
          "description": "Stores subscription plans that businesses can purchase.",
          "params": [{ "name": "planId", "description": "The unique identifier for the subscription plan." }]
        }
      }
    ],
    "reasoning": "The Firestore structure is designed to support the BizAround application, focusing on businesses, categories, user reviews, and user profiles. The structure is optimized for efficient data retrieval, scalability, and, most importantly, secure and independent authorization. Authorization independence is achieved through denormalization, specifically within the `reviews` subcollection.  The `reviews` document include the `businessId` and `userId`. This design enables QAPs for listing business reviews and ensures that business reviews can be added atomically without needing to read parent business documents to authorize ownership.\n\n The addition of top-level `countries`, `cities` and `settings` collections allows administrators to maintain a standardized list of locations and manage global application configurations, preventing data entry errors and ensuring consistency across the application. These managed lists will populate dropdown menus in the UI, improving user experience."
  }
}

    