-
Notifications
You must be signed in to change notification settings - Fork 113
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 intocreate
andupdate
changesets. - The module should also contain
validation functions
for specificattributes
of 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
QueryHelper
for common functions such ascreate
,update
,get
anddelete
. - All the functions which involve a custom
queries
to 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
Repo
related queries in the domain functions, instead they should be delegated to themodel
for the sameentity
. - Accessing
Schema
inside 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
models
or in rare casesschema
inside domain themodel name
should be prepended withModel.
similarly, for schema it should beSchema.
or appending them withModel
andSchema
respectively.
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
domain
functions anywhere should be done in a manner similar to above e.g.
alias Snitch.Domain
def some_func() do
Domain.Variant.some_call()
end