Git Product home page Git Product logo

fastapi-todo-ddd's Introduction

FastAPI Example - Domain driven design & Clean architecture

Tech Stack

Environment's variables

.env file

  • POSTGRES_USER - database root name
  • POSTGRES_PASSWORD - database root password
  • DB_HOST - database's hostname
  • DB_PORT - database's port
  • DB_NAME - database's name
  • DB_USER - database's username
  • DB_PASS - database user's password
  • PORT - port which will be listening for incoming connections

Code Architecture

Directory structure based on Clean Architecture

├── core
├── app
│   ├── main.py
│   ├── dependencies.py
│   ├── config.py
│   └── features
│       └── users
│           ├── data
│           │   ├── repositories
│           │   │   ├── user_unit_of_work_impl.py
│           │   │   └── user_repository_impl.py
│           │   ├── services
│           │   │   └── user_query_service_impl.py
│           │   └── models
│           │       ├── user.py
│           │       └── database.py
│           ├── domain
│           │   ├── entities
│           │   │   ├── user_command_model.py
│           │   │   ├── user_common_model.py
│           │   │   ├── user_entity.py
│           │   │   └── user_query_model.py
│           │   ├── repositories
│           │   │   ├── user_repository.py
│           │   │   └── user_unit_of_work.py
│           │   ├── services
│           │   │   └── user_query_service.py
│           │   └── usecases
│           │       ├── create_user.py
│           │       ├── delete_user.py
│           │       ├── get_user.py
│           │       ├── get_users.py
│           │       └── update_user.py
│           ├── presentation
│           │   ├── routes
│           │   │   ├── __init__.py
│           │   │   ├── create_user_route.py
│           │   │   ├── delete_user_route.py
│           │   │   ├── get_user_route.py
│           │   │   ├── get_users_route.py
│           │   │   └── update_user_route.py
│           │   └── schema
│           │       └── routes
│           └── dependencies.py
└── tests

Domain-driven design Glossary

There is a number of high-level concepts that are used in conjunction with one another to create and modify domain models:

  • Model: A system of abstractions that describes aspects of a domain and can be used to solve problems related to that domain.
  • Value Object: An immutable object that has attributes and validation logic, but no distinct identity.
  • Entity: An object that is identified by its consistent thread of continuity, as opposed to traditional objects, which are defined by their attributes.
  • Aggregate: A cluster of entities and value objects with defined boundaries around the group. Rather than allowing every single entity entity or value object to perform all actions on its own, the collective aggregate of items is assigned a singular aggregate root item. External objects no longer have direct access to every individual entity or value object within the aggregate, and use that to pass along instructions to the group as a whole.
  • Service: Service is an operation or form of business logic that doesn't naturally fit within real of objects. That means if functionality must exist, but doesn't relate to an entity or value object.
  • Repository: the DDD meaning of a repository is a service that uses a global interface to provide access to all entities. and value objects that are withing a particular aggregate collection. Methods should be defined to allow for creation, modification, and deletion of objects within the aggregate.
  • Factory: Factory is a creational design pattern that provides an interface for creating objects. DDD highly suggests use such pattern. Factory pattern encapsulates the logic of creating complex objects and aggregates, ensuring that the client has no knowledge of the inner-workings of object manipulation (creation).

Setup

  1. Clone repository
  2. Create .env file and setup env variables
  3. Run docker-compose up
  4. Access the API document http://localhost:<specified_opened_port>

fastapi-todo-ddd's People

Contributors

adamhavlicek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.