2
\$\begingroup\$

I'm trying to create a logical and scalable many to many relationship data structure in Firebase. A user can authenticate with Facebook/Google, upload 3 photos, and a video. Users can also "star" another user's profile.

I've created the following JSON schema, but I'm struggling with keeping flexibility with photos and videos associated with a user's profile. I'm trying not to nest too much. Does the following seem over-coupled?

{
  "users": {
    "fb_id": "{{objectId()}}",
    "name": "{{firstName()}} {{surname()}}",
    "updated_at": "{{date()}}",
    "picture": "http://lorempixel.com/32/32/",

    "car_profiles": {
      "car_profile_1": true
    },

    "car_photos": {
      "car_photos_1": true
    },

    "car_videos": {
      "car_videos": true
    },

    "uid": "user-guid"
  },

  "likes": {
    "car_profile_1": {
      "count": "{{integer(0, 1540)}}",
      "users": {
        "user-guid": "{{date()}}"
      }
    }
  },

  "car_profiles": {
    "car_profile_1": {
      "user": {
        "name": "{{firstName()}} {{surname()}}",
        "picture": "http://lorempixel.com/32/32/",
        "timestamp": "{{date()}}"
      },
      "title": "{{lorem(1, "words")}}",
      "flags": 0,
      "removed": "{{random(true, false)}}",
      "car_specs": {
        year: "1975",
        make: "ford",
        model: "mustang",
        engine: "hemi",
        horsePower: "a lot",
        supercharged: '{{random("yes", "no")}}',
        "description": 'repeat(5)': '{{lorem(1, "paragraphs")}}'
      },
      "tags": []
    }
  },

  "car_photos": {
    "car_photos_1": {
      "user": {
        "name": "{{firstName()}} {{surname()}}",
        "picture": "http://lorempixel.com/32/32/",
        "timestamp": "{{date()}}"
      },
      "photos": [{
        "photo1": "http://lorempixel.com/400/200/",
        "photo2": "http://lorempixel.com/400/200/",
        "photo3": "http://lorempixel.com/400/200/",
      }]
    }
  },

  "car_videos": {
    "car_videos_1": {
      "user": {
        "name": "{{firstName()}} {{surname()}}",
        "picture": "http://lorempixel.com/32/32/",
        "timestamp": "{{date()}}"
      },
      "title": "{{lorem(1, "words")}}}}",
      "videos": ["some-url", "another-url"],
    }
  }

}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.