Skip to content

Avoid code repetition across tiers in full-stack app #359

@yakir12

Description

@yakir12

When building a full-stack app, I find it frustrating to define basically 3 nearly identical types:

  1. What I consider the main struct: defining the logic of the type disregarding any GUI/DB needs. This is the struct you'd define normally. This struct would contain only the most basic fields needed to define it "in real life" (e.g. a User will have name, email, and password). Methods associated with it would only deal with actions that have to do with what it actually is.
  2. The back-end struct: same as in # 1 but for the database, with the obligatory id and maybe public id for associations with other entities. Methods with this one would be CRUD.
  3. The front-end struct: Again, same as # 1 but for the GUI. User-facing with some additional checks and validations.

As suggested in this Discourse topic, one way forward is to wrap the business struct (type # 1 above) with a wrapper struct that includes all the missing fields needed for the DB or the GUI. Currently, I think the pipeline to make this convenient is missing. For instance, in issue GenieFramework/Stipple.jl#47 a convenience wrapper for custom types is missing on the GUI end of things. On the other end, DB, the same problem exists: I can't SearchLight.findone(MyCustomType, field_name = field_value).

Right now, I need to basically replicate my custom type for each tier and add the missing fields for the two tiers (e.g. id for the DB). Or alternatively, have a business type that includes fields that "pollute" it's actual function (e.g. the id field has nothing to do with a user being a User on its own right).

This feels like a magnificent opportunity for Genie to be the first framework to solve this duplication of code. Imagine a framework where full-stack developers only need to define the business structs and their methods, while the front and back end automagically follow suit! This might be a high order, but if there is a way to make this happen, then the appeal to use the Genie framework should be huge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions