{
    "componentChunkName": "component---src-templates-post-page-js",
    "path": "/2018/cryptomate/groundwork",
    "result": {"data":{"site":{"siteMetadata":{"title":"Solid Abstractions","siteUrl":"https://solidabstractions.com","twitterId":291334023,"author":{"fullName":"Julien Hartmann","profileHtml":"I am an open-source de­vel­op­er, for­mer IT con­sul­tant with a pas­sion for new tech­nol­o­gies. I be­lieve the role of an en­gi­neer is to em­pow­er peo­ple, by as­sem­bling sim­ple, re­fined de­signs.\n","links":[{"url":"https://github.com/spectras/","name":"github","title":"GitHub"},{"url":"https://stackoverflow.com/users/3212865/spectras","name":"stackoverflow","title":"StackOverflow"},{"url":"https://www.linkedin.com/in/julienhartmann/","name":"linkedin","title":"LinkedIn"}],"profilePicNode":{"original":{"src":"/static/profile-pic-301a9cbe7b572c3e7910c9717d2b3bcd.jpg"}},"url":"https://etherdream.org/about"}}},"markdownRemark":{"id":"d12d3996-cc13-5e45-9019-522df437b64f","excerpt":"Initial design is done. It is now time to start laying the basis of the project.\nAt this point, there are a few technical choices we can no longer defer.","html":"<p>Initial design is done. It is now time to start laying the basis of the project.\nAt this point, there are a few technical choices we can no longer defer.</p>\n<p>--- excerpt ---</p>\n<p>Initial design is done. It is now time to start laying the basis of the project.\nAt this point, there are a few technical choices we can no longer defer.</p>\n<h2 id=\"technical-decisions\">Technical decisions</h2>\n<h3 id=\"language-choice\">Language choice</h3>\n<p>As per our architecture constraints, we must choose either C++ or Python, or a mix thereof.\nI personally tend to favor Python, as a more flexible language, which allows building software\nmuch faster than C++, albeit at the cost of performance.</p>\n<p>I will stick to this choice here. The initial design will be full python and then, as we\nidentify bottlenecks, we will convert to C++ piece-wise. Especially, as we will have a lot of\ninput/output, python 3.5 asyncio module will be very convenient and allow us to reach an\ninitial working version much faster than C++.</p>\n<p>Thus, we will build the initial version using python, with support for version 3.5 and 3.6.\nAnd when potential benefit arises, we will use C++14, which has a good balance of modern\nfeatures and compiler support.</p>\n<h3 id=\"toolbox\">Toolbox</h3>\n<p>We have a couple of basic tools we will need to support our project. Without ceremony, here are\nthe essential tools we will use:</p>\n<ul>\n<li>We will use <a href=\"https://github.com\" class=\"external\" rel=\"external noopener noreferrer\">github</a> to host our project. It couples the ubiquitous\n<a href=\"https://git-scm.com/\" class=\"external\" rel=\"external noopener noreferrer\">git</a> versioning system with a neat pull-request workflow that works\ngreat for open-source projects.</li>\n<li>We will use <a href=\"https://www.pylint.org/\" class=\"external\" rel=\"external noopener noreferrer\">Pylint</a> to identify code smells and style mistakes.</li>\n<li>We will use the <a href=\"https://docs.pytest.org\" class=\"external\" rel=\"external noopener noreferrer\">pytest</a> framework for testing.</li>\n<li>We will use <a href=\"https://github.com/nedbat/coveragepy\" class=\"external\" rel=\"external noopener noreferrer\">coverage.py</a> to ensure our tests are thorough.</li>\n<li>We will use <a href=\"https://travis-ci.org/\" class=\"external\" rel=\"external noopener noreferrer\">travis-ci</a> continuous integration service to ensure our\ntests are run for every change we make.</li>\n<li>We will use the <a href=\"http://www.sphinx-doc.org\" class=\"external\" rel=\"external noopener noreferrer\">sphinx</a> documentation generator.</li>\n</ul>\n<p>Those tools come a little from personal preference, and a lot from being industry standards.\nI will not explain the setup here, but the\n“<a href=\"/2018/starting-python-project\" class=\"internal\">starting a python project</a>” post covers the details.</p>\n<p>Our newly created repository is on <a href=\"https://github.com/solid-abstractions/cryptomate/\" class=\"external\" rel=\"external noopener noreferrer\">github</a>, and you can check the <a href=\"https://github.com/solid-abstractions/cryptomate/tree/posts/groundwork/1\" class=\"external\" rel=\"external noopener noreferrer\">initial commit</a>.\nIt is now time to look at our directory hierarchy.</p>\n<h3 id=\"cross-cutting-dependencies\">Cross-cutting dependencies</h3>\n<p>Cryptomate has multiple modules with similar requirements, so to keep its parts consistent,\nwe decide to choose some dependencies at the global level.</p>\n<dl><dt>Event loop</dt><dd><p>We need a single event loop component. Handling tick data from many markets will put a\nlot of stress on our I/O loop. Also, as we plan to move modules from Python to C++ as\nwe go, an event loop readily available in both languages would be great.</p><p>We shall use <a href=\"http://libuv.org/\" class=\"external\" rel=\"external noopener noreferrer\">libuv</a>, with the <a href=\"https://github.com/MagicStack/uvloop\" class=\"external\" rel=\"external noopener noreferrer\">uvloop</a>\npython bindings. It is widely used, and renowned for its performance.</p></dd><dt>Cross-language integration</dt><dd><p>In order not to restrict Python-C++ interactions to integration boundaries, we need a\nstandard way to make them talk.</p><p>We shall initially use <a href=\"http://cython.org/\" class=\"external\" rel=\"external noopener noreferrer\">Cython</a> for this purpose. Though not as featureful\nas <code class=\"language-text\">Boost.Python</code> or the more recent <code class=\"language-text\">pybind11</code>, it integrates better within a Python\nworkflow and produces leaner modules. Should we find ourselves moving large parts of the\ncode over to C++, we might reconsider this choice later on.</p></dd></dl>\n<h2 id=\"mapping-the-model-to-files\">Mapping the model to files</h2>\n<p>As per the traditional python model, we will adopt a package-by-module approach.\nEvery module defined in the\n<a href=\"https://solidabstractions.com/2018/cryptomate/modules#modules-overview\" class=\"external\" rel=\"external noopener noreferrer\">modules overview</a>\nshall have its own, possibly nested, directory structure, reflecting its own\nsubdivisions in sub-modules and internal layers.</p>\n<p>To enforce isolation and encapsulation:</p>\n<ul>\n<li>Modules may only access the root of other modules, and cannot reach into the\nhierarchy of their sub-modules.</li>\n<li>Modules may only access other modules if allowed to in the\n<a href=\"http://127.0.0.1:8000/2018/cryptomate/exploring-patterns#compositing\" class=\"external\" rel=\"external noopener noreferrer\">architecture</a>.\nIn particular, remember that adapters depend on ports and not the other way around.</li>\n</ul>\n<p>One consequence of this approach is that layer boundaries end up within each module.\nFor instance, the real-time market module will contain all objects related to fetching\nmarket data in real-time:</p>\n<ul>\n<li>The description of the port-adapter relationship.</li>\n<li>The various adapters.</li>\n<li>The registry that makes it possible to find and instantiate them.</li>\n<li>The management of their life-cycle.</li>\n<li>The interfaces that abstract out and expose the functionality.</li>\n</ul>\n<p>Another way to view this structure is to see those modules as an outer hexagon, the interfaces\nexposing module functionality being adapters to inner hexagon's ports.</p>\n<p>The resulting hierarchy has been <a href=\"https://github.com/solid-abstractions/cryptomate/tree/posts/groundwork/2\" class=\"external\" rel=\"external noopener noreferrer\">added</a>.</p>\n<h2 id=\"conclusion\">Conclusion</h2>\n<p>Thus, Cryptomate was born. In the <a href=\"market-port\" class=\"internal\">next post</a>, we will start working on the main\ncomponent of the system, that is the business logic and, most importantly, its <em>ports</em>.</p>","fields":{"isPage":false,"slug":"/2018/cryptomate/groundwork"},"frontmatter":{"title":"Laying the Groundwork","classname":null,"date":"2018-09-24T00:00:00.000Z","formattedDate":"September 24, 2018","isoDate":"2018-09-24T00:00:00+00:00"},"headings":[{"value":"Technical decisions","depth":1},{"value":"Language choice","depth":2},{"value":"Toolbox","depth":2},{"value":"Cross-cutting dependencies","depth":2},{"value":"Mapping the model to files","depth":1},{"value":"Conclusion","depth":1}],"image":null,"series":{"name":"cryptomate","fullName":null,"fields":{"slug":"/cryptomate"}},"tags":[{"name":"code","slug":"/tag/code"}]}},"pageContext":{"series":"cryptomate","slug":"/2018/cryptomate/groundwork","previous":{"fields":{"slug":"/2018/starting-python-project"},"frontmatter":{"title":"Starting a Python Project","series":"python"},"tags":[{"name":"code","slug":"/tag/code"}]},"next":{"fields":{"slug":"/2018/cryptomate/market-port"},"frontmatter":{"title":"Market Port","series":"cryptomate"},"tags":[{"name":"architecture","slug":"/tag/architecture"},{"name":"ports","slug":"/tag/ports"}]},"seriesPrevious":{"fields":{"slug":"/2018/cryptomate/the-story-so-far"},"frontmatter":{"title":"The Story So Far","series":"cryptomate"},"tags":[{"name":"architecture","slug":"/tag/architecture"}]},"seriesNext":{"fields":{"slug":"/2018/cryptomate/market-port"},"frontmatter":{"title":"Market Port","series":"cryptomate"},"tags":[{"name":"architecture","slug":"/tag/architecture"},{"name":"ports","slug":"/tag/ports"}]}}},
    "staticQueryHashes": ["1733002695","4006707078"]}