Skip to content

Hurtak/clean-architecture

Repository files navigation

Clean architecture example

  • Example web server application implementing the Clean architecture concept as an example web server.
  • API spec is based on https://www.todobackend.com/
  • Technology
    • Language: TypeScript
    • Database: SQLite (in memory)
    • Web server: Koa
  • Fell free to comment and suggest improvements either by creating issue or PR :).

My current understanding of the Clean architecture

Clean architecture diagram

Implementation notes

  • The project is trying to implement the Clean architecture on small example app.
  • The folder structure mirrors the Clean architecture as closely as possible. The folders that directly relate to the Clean architecture concepts (and the diagram above) have number prefixes, so they are sorted from the most outer layer to the most inner layer.
    • Folders:
      • /src/0-config
      • /src/1-external-services
      • /src/2-entrypoints
      • /src/3-use-cases
      • /src/4-entities
    • There are eslint rules preventing importing from inner layer to the outer layers (see nested .eslintrc files).
  • The project tries to purposely use a small number of dependencies and other architectural concepts to keep it simple, so not every part of the code is probably how you would write it in a real production app (for example error handling is done with a simple union of Data | Error, in real-world project you would probably use Either type from some library).
  • After the project is started, there is example data put in the database (see storage-migrations.ts).

API

Run

  • Install dependencies with npm install.
  • Start the project with npm run dev.
  • See all the scripts you can run in package.json.

TODOs

  • add user domain with login/register etc
  • Maybe add more than one thing in the use-case? So we have more than one of each in the use case?
    • something like dummy email service?
  • is --unhandled-rejections=strict still needed?
  • fix all TODO in the code
  • run everything through Grammarly

Related links

About

Example implementation of Clean Architecture patterns

Resources

License

Stars

Watchers

Forks