Last active
December 28, 2015 12:19
-
-
Save tastywheat/7500283 to your computer and use it in GitHub Desktop.
ddd example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
High level directory structure | |
root/ | |
application/ (configuration) | |
domain/ (business logic) | |
Entities/ (User, Article, Image, Video) | |
Aggregates/ (UserProfile, UserHistory) | |
ValueObjects/ | |
dataAccess/ (repositories for data retrieval/persistance) | |
services/ (manages of domain and dataAccess) | |
*/ | |
//Application Layer - application/configuration.js | |
configuration.article.databaseImplementation.default = "breeze mongo"; | |
configuration.article.databaseImplementation.search = "elasticsearch"; | |
//Service Layer - services/articleService.js | |
function getArticles(req, res){ | |
var articleRepository = getArticleRepository(req); | |
articleRepository.getArtcles(req, res); | |
} | |
function getArticleRepository(req){ | |
//Need to decide if we should go through elasticsearch or breeze | |
if(req.query.search) // /api/article?search=1 | |
return articleRepositoryFactory.get(configuration.article.databaseImplementation.search); | |
else | |
return articleRepositoryFactory.get(configuration.article.databaseImplementation.default); | |
} | |
//Data Access Layer - dataAccess/articleRepositoryFactory.js | |
function get(implementation){ | |
switch(implementation){ | |
case 'breeze mongo': | |
return articleRepositoryBreeezeMongo; | |
case 'mongoose mongo': | |
return articleRepositoryMongooseMongo; | |
case 'elasticsearch': | |
return articleRepositoryElasticsearch; | |
case 'redis': | |
return articleRepositoryRedis; | |
case 'mysql': | |
return articleRepositoryMysql; | |
case 'memcache': | |
return articleRepositoryMemcache; | |
} | |
} | |
//Data Access Layer | |
//dataAccess/articleRepositoryBreeezeMongo.js | |
function getArticles() { /* perform a breeze query to mongo - return JSON */ } | |
//dataAccess/articleRepositoryMongooseMongo.js | |
function getArticles() { /* perform a mongoose ODM query to mongo - return JSON */ } | |
//dataAccess/articleRepositoryElasticsearch.js | |
function getArticles() { /* perform a query to elasticsearch - return JSON */ } | |
//Domain Layer (business logic) | |
/* | |
Domains: | |
Search (score calculation) | |
Objectives (point/token calculation) | |
Chat (Rooms, Members) | |
Authentication | |
Authorization | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment