Newbie needs advice on planning for structure

Hi all -

I’m looking for some advice on how to set up an interface for my single-page application. Basically, my app will load an object with a whole lot of structure. I’m building an auction-style store application that has categories, groups and products where people can choose one product from each group. Something like this:

  {
  "title": "this is totes awesome", 
  "categories": [{
          [{
          "id": "37897we98r",
          "title": "totes awesome tshirts"
          "groups": [
            [
              { 
                "id":               "123",
                "title":            "Everything is Awesome!"
                "available":        12
              },
              { 
                "id":               "345",
                "title":            "When you're part of a Team"
                "available":        10
              }
            ],
            [
              { 
                "id":               "123",
                "title":            "Lorem Ipsum dolor"
                "available":        10
              },
              { 
                "id":               "345",
                "title":            "Fake latin rulz"
                "available":        10
              }
            ]
          ]
      }] [and another group with categories and products...]
  }]
}

There will only ever be one top level store object, but the number of categories, groupings and products are variable.

Also, to muddy the waters, there will be live updates from the server (via sockets) so that product-level data is updated as people purchase products (i.e. the inventory decreases).

I believe I need api points at the tournament, category and product end-point, so I’m not sure how to structure my models. I’m cautious about having a large number of API requests as well, so any advice would be greatly appreciated.

Right now, the backend API is being designed so we have flexibility there. I’m 99% sure we’ll be rolling a Rails solution…

Thanks for any guidance.

So, when you say ‘an object’, you mean there is only one object? Do you have multiple stores inside your app? Fetching the whole model every time you refresh may cause serious lag, especially if you’re refreshing constantly. Remember that the router stops for promises.

I’m thinking Store is actually your apps namespace.

var Store = Ember.Application.create({});

If you’re going to use Rails, then make sure you use this: https://github.com/rails-api/active_model_serializers

@ulisesrmzroche - Thanks so much for taking a look. Nope, there’s just the one store inside the app, so I think I’ll likely load the model with the first category every page fresh. Then, as we navigate to other categories, I will load that data with that end-point.

I guess I’m wondering about the Ember models. Do I need a model for every Store / Category / Group and Product? I wonder, for example, if the Group (e.g. t-shirts) needs an associated Model (e.g. for every t-shirt) or if the group itself has a simply array of tshirts. Know what I mean. Can a Model with an array of “t-shirts” get live updates for attributes for each of those “t-shirts”?

I suppose I’m trying to say that I’m not sure if making more models is actually simplifying things or making things more complicated. I wonder if there’s a resource on “when to use a has_many relationship to a model rather than simply an array of objects”. Thanks!