/bake-connect

A bake and connect backend application which helps you to bake and others to connect to you built using Python, Fast API, MySQL.

Primary LanguagePython


Bake & Connect

A bake and connect application which helps you to bake and others to connect to you built using Python, Fast API, MySQL.

Key FeaturesUse CasesHow To UseHow To run testsImplementation roadmapDesign decisions

Key Features

  • New account registration (either as a Member or as a Baker) and authentication
  • Bakers can add new products for selling and then edit or remove them.
  • All users can list available products and filter them by location and type.
  • All users can see a baker's profile (with a rating).
  • Members can see available collection times and place orders.
  • Bakers can see their orders, accept, reject, and fulfill them.
  • Customers can rate their fulfilled orders. Order rates form the overall baker's rating.

Use Cases

  • Alice loves baking and wants to sell her cherry cakes and kidney pies to others. Alice created a baker profile at BakeConnect.
  • Alice listed her two products. A kidney pie takes 3 hours to bake, and a cherry pie needs 2 hours.
  • Assume that at some day, 10:00 in the morning, Bob, Carol and Dan discovered BakeConnect.
  • Bob decides to enjoy a kidney pie and uses BakeConnect to find available kidney pies in a 2km radius. He finds Alice's offering, registers himself as a member and orders a kidney pie with the desired collection time of 14:00.
  • Carol is a BakeConnect member and wants a cherry pie for lunch. Normally, the earliest collection time would be 12:00 due to baking time, but Alice is already busy with the kidney pie from 11:00 until 14:00 (we assume only one cake can be baked at the moment). Therefore earliest collection time for Carol is 16:00, and she decides to order a cake for 19:00 and enjoy it at dinner.
  • Dan searches for berry cakes and finds Alice's offering. He registers as a member and puts an order for 16:30 collection time. At the end of the day, Bob, Carol and Dan rated their orders with 5 stars (of 5), improving Alice's baker rating.

How to Use

To be added - Provide instructions on how to use the BakeConnect application. Include details on how to set up the development environment, install dependencies, configure the database connection, and run the application. You can also provide examples of API endpoints and their usage.

How to Run Tests

To be added - Explain how to run tests for the BakeConnect application. Include information on setting up the test environment, installing test dependencies, and running the test suite. Specify any commands or configurations required to execute the tests successfully.

Implementation roadmap

Bake & Connect implementation raodmap steps starting from delivering a minimum viable product, Securing the application. After that, shape it into Production.

  • Building Minimum viable product
    • Build core setup (Fast API + MySQL connection)
    • Create user + basic JWT authentication (access token + authenticator)
    • Create bakery
    • Create product
    • Create order using builder pattern
    • Implementing order state flow using state pattern
    • Add all missing GET methods or any other helper method
    • Handle validations & missing scenarios
  • Securing the application
    • Completing JWT authentication (Refresh token + forget password)
  • Shaping into Production
    • Use dependency management tool Poetry
    • Dockerizing the application
    • Manual deployment on Kubernetes link
    • Link it with domain without a certificate. link
  • Making development cycle easier
    • Add linting configurations
    • Covering all modules with unit tests
    • Adding simple CI/CD pipeline
    • Introducing testing environment besides production environment
    • Any refactoring is needed here?
    • Adding documentation for all endpoints
  • Adding any feature de-scoped from MVP or enhancement
    • Rate baker by user
    • Structure/Scrape the locations data
  • Enhancing some performance?
    • Caching frequently accessed data, which is the product listing using LFU (least frequently used) algorithm.
  • Making it more secure?
    • Support authorization using RBAC (role-based access control)
  • More fancy features to come!
    • Send notifications to customers when their orders are ready!
  • Decided to move to another cloud provider?
    • Use Terraform to create your Kubernetes cluster and nodes.

Design decisions

  • Initial database design tables using diagram.io. Alt text
  • Simplified database design tables to tackle the MVP using diagram.io. Alt text
  • State machine for order using diagram.io. Alt text
  • Project structure
fastapi-project
├── app/
│   ├── api/
│   │   ├── users/
│   │   │   ├── router.py  # exposing endpoints
│   │   │   ├── dao.py  # class for accessing database covering all sql-alchemy methods
│   │   │   ├── schemas.py  # pydantic models
│   │   │   ├── models.py  # db models
│   │   │   ├── services.py  # service logic lays here
│   │   └── posts/
│   │       ├── router.py
│   │       ├── schemas.py
│   │       ├── models.py
│   │       ├── dependencies.py
│   │       ├── constants.py
│   │       ├── exceptions.py
│   │       ├── service.py
│   │       └── utils.py
│   ├── models.py  # global models
│   ├── router.py  # global router
│   ├── lifetime.py  # application startup - shutdown
│   ├── application.py  # application initizaliation & configuartion
│   └── __main__.py
├── tests/
│   ├── users
│   ├── products
├── static/
│   ├── index.html
|   └── style.css
├── .env
├── .flake8  # linting rules configurations
├── .gitignore
├── pyproject.toml  # poetry dependency configurations management
└── Dockerfile  # dockerfile for the application
  1. All domain directories inside app/api folder
    1. app/api/ - highest level of an app, contains common models, configs, and constants, etc.
    2. app/api/__main__.py - root of the project, which inits the FastAPI app
  2. Each package has its own router, schemas, models, etc.
    1. router.py - is a core of each module with all the endpoints
    2. schemas.py - for pydantic models
    3. models.py - for db models
    4. service.py - module specific business logic
    5. dao.py - for accessing db models using ORM
    6. utils.py - non-business logic functions, e.g. response normalization, data enrichment, etc.
    7. exceptions.py - module specific exceptions, e.g. PostNotFound, InvalidUserData