nwheels-io / NWheels

DIY full-stack+BI+DevOps in no time: tiny DSLs transpiled into maintainable codebases for selected technology stacks
MIT License
20 stars 9 forks source link

MVP demo application #83

Closed felix-b closed 5 years ago

felix-b commented 6 years ago

We need an MVP demo application that would demonstrate the strengths of the framework.

felix-b commented 6 years ago

MVP application spec

Here I summarize a discussion that took place offline

Requirements

Create a billing application for a power plant operator. The application will be responsible for:

The application will serve the following actors:

  1. Sensors (running on an IoT cloud): push consumption data to the application
  2. Operator users: use administration UI for back-office management
  3. Customers: use personal dashboard UI for payment and periodic reporting

Brief requirements:

  1. a customer can have one or more associated sensors
  2. each sensor is associated with a tariff plan; the association can be changed at any time
  3. tariff plans are managed globally
  4. customers are billed monthly
  5. payments are charged through an online payment service (e.g. PayPal).
  6. payments must be available in different currencies, including cryptocurrencies such as BitCoin -- according to customer's choice.
felix-b commented 6 years ago

Comments and suggestions are welcome! A BDD-style specification (given-when-then) would be very useful...

felix-b commented 6 years ago

Proposed analysis

Concept summary

This is a typical event processing system, where we:

  1. receive a stream of sensor events (kWh meter readings)
  2. receive a stream of configuration events (customers/pricing configuration)
  3. process sensor events by applying pricing plans which are/were effective at the time of sensor reading
  4. mutate the state of the system by storing results in customer invoices

Why event-driven? Since this system charges customers for a service, an inevitable situation must be handled where the system incorrectly charges a customer because of data corruption or human mistakes. The system must be robust in replaying its functions over the corrected inputs.

This doesn't automatically mean we're going into any special kind of technology that supports event sourcing (e.g. EventStore). We can implement event sourcing approach at specific points where it's actually necessary.

Detailed analysis

Retroactive recalculations

It wouldn't be necessary in an ideal world. But in reality, some Invoices might be sometimes found incorrect. This can be caused (for example) by:

The Billing job will be responsible for retroactive recalculations.

One pitfall to avoid during retroactive recalculations, is accidentally rewriting the past. As a mitigation, these restrictions apply:

felix-b commented 6 years ago

Data flow diagram

nwheels-mvp-dataflow-diagram 1

Entity relationship diagram

nwheels-mvp-demo-erd 1 1

(work in progress -- suggestions are welcome)

godrose commented 6 years ago

Looking good. No need in supporting all kinds of price plans and currencies right from the start. Also i recommend replacing the word "tariff" with "price plan"

godrose commented 6 years ago

Why there's need in two different apps? One app might be enough for demo purposes. The user will be redirected according to their identity to the correspondent root view

felix-b commented 6 years ago

@godrose yes, I agree about not implementing variations of pricing strategies etc right from the start. Just wanted to illustrate how they are planned to be implemented.

"Pricing Plan" indeed sounds better. "Rate Plan" can also be good -- here is an indication of usage from Google Books

As for having 1 or 2 apps, I'd like to demonstrate a production-ready system, so I'd rather apply considerations about production. Since the apps serve two different kinds of users, I'm considering these points:

One interesting alternative is display 2 different login forms on a common login page. But then we have 3 apps: login, back office, and dashboard.

felix-b commented 6 years ago

List of microservices (~ subdomains)

Service Responsibilities API Endpoints
Sensor service (red color, daemon) Sensors subdomain; store sensor readings (1) push sensor readings (2) TX = submit transaction requests (3) QX = run entity queries
Customer service (cyan color, daemon) Customers subdomain; manage pricing plans and contracts TX, QX
Billing service (purple color, daemon) Billing subdomain; query and invalidate invoices TX, QX
Billing job (purple color, batch job) Generate invoices based on data from Sensors and Customers subdomains N/A
Payment service (green color, daemon) Payment subdomain + process payments through integration with online payment services TX, QX + callback endpoints specific to payment services
Login service (yellow color, daemon) User Accounts subdomain + authenticate users TX, QX
Admin App service Host back-office web app Web
Dashboard App service Host dashboard web app Web
felix-b commented 6 years ago

The MVP application is a driver for design and implementation of programming models in use. I gather related issues in the list below:

felix-b commented 6 years ago

Progress update

What's ready for review by now:

The solution is structured as follows:

Note that the solution doesn't yet consume NWheels NuGet packages. Temporarily, a class library named NWheelsTempApiLib contains mocks of all NWheels APIs (https://github.com/felix-b/NWheels/tree/pr-mvp/Samples/02-ElectricityBilling/ElectricityBilling/NWheelsTempApiLib). The mocks are just for the application code to compile, they can't execute.

This is still mid-work. The most of the progress was with the Sensor Service (https://github.com/felix-b/NWheels/tree/pr-mvp/Samples/02-ElectricityBilling/ElectricityBilling/ElectricityBilling.SensorService)