-
Notifications
You must be signed in to change notification settings - Fork 111
Project Structure
Ashish Singh edited this page Apr 27, 2018
·
1 revision
- Snitch has a following contextual design to maintain hierarchy
Domain
|-- Model
|-- Schema
It's a general convention being followed that, while designing a schema for a particular entity the following should be kept in mind:
- The module should have entity
Schema - The module should have the
changesets, which can be broken down intocreateandupdatechangesets. - The module should also contain
validation functionsfor specificattributesof the entity. - Some general validations which are common among entities should be placed inside
snitch_core/lib/tools/validations.
- The model should include all the functions which require to touch the database directly.
- The model functions should use
QueryHelperfor common functions such ascreate,update,getanddelete. - All the functions which involve a custom
queriesto the database should also be included in this module. - For accessing schema inside model the convention is to use the schema name prepended with
Schema.or appending schema name withSchema. Please do not use any other convention to maintain consistency across the project.
alias Snitch.Data.Schema
alias Snitch.Data.Schema.Variant, as: VariantSchema
# accessing inside function
def some_func() do
Schema.Variant.changeset()
end
def some_other_func() do
VariantSchema.changeset()
end- The domain module for any entity should utilise the model functions to do any transaction with the database. Please avoid using any
Reporelated queries in the domain functions, instead they should be delegated to themodelfor the sameentity. - Accessing
Schemainside domain module should be avoided at all costs to maintain the abstraction. Only in very rare scenarios this would be acceptable. The access should always be delegated to the concerned model. - Again for accessing
modelsor in rare casesschemainside domain themodel nameshould be prepended withModel.similarly, for schema it should beSchema.or appending them withModelandSchemarespectively.
alias Snitch.Data.Model
alias Snitch.Data.Model.Variant, as: VariantModel
# accessing inside function
def some_func() do
Model.Variant.changeset()
end
def some_other_func() do
VariantModel.changeset()
end- Even the use of a
domainfunctions anywhere should be done in a manner similar to above e.g.
alias Snitch.Domain
def some_func() do
Domain.Variant.some_call()
end