Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Architecture refactorization. #50

Merged
merged 50 commits into from
Feb 11, 2024
Merged

Architecture refactorization. #50

merged 50 commits into from
Feb 11, 2024

Conversation

caarmen
Copy link
Owner

@caarmen caarmen commented Feb 3, 2024

Architecture redesign

Redesign the architecture into layers.

  • Top-level: entry points (routes and tasks)
  • Middle-level: domain (use cases)
  • Lower-levels:
    • data (repositories)
    • remote services
  • Spanning multiple levels: core, oauth

Add mermaid diagrams.

Tests

Add tests to cover most of the app (97% coverage currently).

Other changes

  • Use templates instead of string literals for successful connection pages.
  • Use more modern asyncio apis for the fitbit scheduler.

@caarmen caarmen force-pushed the refactor-archi branch 4 times, most recently from bf5aaee to 4e5f4f1 Compare February 3, 2024 22:40
All withings db opeations have been moved to the repository now (which is called by usecases).
Make withings modules which need oauth settings only depend on a subset of settings, WithingsOAuthSettings, instead of the whole Settings.

For the withings oauth update token callback, remove code regarding the db from the oauth config, and put it in the usecase_update_user_oauth instead.

Move the withings.oauth module to oauth.withingsconfig.

Now the services.withings package only has the api module. Will think of a better place to put it...
@caarmen caarmen force-pushed the refactor-archi branch 12 times, most recently from 2654aa9 to cf3950e Compare February 4, 2024 16:33
@caarmen
Copy link
Owner Author

caarmen commented Feb 4, 2024

Rough sketch of architecture in progress:

macro view

flowchart TB
    subgraph main
    end
    subgraph routes
    end

    subgraph tasks
    end

    subgraph domain
    end
    %%subgraph core
    %%end
    subgraph data
    end


    subgraph remoteservices
    end
    subgraph oauth
    end

    domain --> remoteservices
    domain --> data
    %%domain --> core




    %%remoteservices --> core
    remoteservices --> oauth
    %%oauth --> core


    routes --> domain


    tasks --> domain

    main --> routes
    main --> tasks
Loading

detailed view

flowchart TB
    subgraph main
    end
    subgraph routes
        subgraph withingsroutes
        end
        subgraph fitbitroutes
        end
    end

    subgraph tasks
        subgraph fitbittasks
        end
    end

    subgraph logger
    end
    subgraph settings
    end
    subgraph domain
        domainmodels[models]
        usecases
        modelmappers
    end
    subgraph core
        coremodels[models]
        exceptions
    end
    subgraph data
        subgraph repositories
            withingsrepository
            fitbitrepository
            repomodels[models]
        end
        subgraph database
            connection
            dbmodels[models]
        end
    end


    subgraph remoteservices
        fitbitapi
        withingsapi
    end
    subgraph oauth
        withingsoauth
        fitbitoauth
        oauth2[oauth]
    end

    repositories --> database


    usecases --> domainmodels
    usecases --> repositories
    usecases --> remoteservices
    usecases --> core
    modelmappers --> coremodels
    modelmappers --> domainmodels
    modelmappers --> repomodels


    fitbitoauth --> oauth2
    withingsoauth --> oauth2
    remoteservices --> core
    remoteservices --> oauth



    withingsroutes --> usecases
    fitbitroutes --> usecases


    fitbittasks --> usecases

    main --> routes
    main --> tasks
    main --> settings
    main --> logger





Loading

Accept a `FitnessData` with no weight value.
Reload the user db objects after adding them.

Fix a bug creating a new fitbit user for an existing user having a withings account (same slack alias). And vice versa.
When reading oauth_expiration_date from the database, add the utc tzinfo before using it.

Use `datetime.now(timezone.utc)` instead of `datetime.utcnow()`, to get the current time in utc.
…cess_new_weight.

usecase_get_last_weight is just supposed to fetch the new weight from the network.

usecase_process_new_weight calls usecase_get_last_weight and has the other business logic around it (saving the new weight to db, creating the WeightData to give to the slack use case to post to slack).
Add tests for duplicate fitbit and withings notifications.
Add test scenarios for login with existing users.
Move oauth tests to routes folder.
Isolate the message creation into a separate function.

A future commit adds tests for this function.
Rework the scheduler, to avoid warnings about an unawaited coroutine, from tests.

Use asyncio.create_task() to create a task which runs the polling every X seconds.
@caarmen caarmen merged commit edab4a0 into main Feb 11, 2024
2 checks passed
@caarmen caarmen deleted the refactor-archi branch February 11, 2024 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant