# Plenty
## User Flow
```mermaid
flowchart
Orders-->|select_order|OrderDetail
```
Home-->CurrentOrder?{Is there a current order?}
CurrentOrder?-->|yes|OrderDetail
CurrentOrder?-->|no|Admin?{Is the user an admin?}
Admin?-->|yes|CreateOrder
Admin?-->|no|NothingToDo!Enjoy/ProductsExplorers
Home-->|tab|PastOrders
Home-->|tab|MyProducers
OrderDetail
OrderDetail includes:
- Order status
- Dates
- List of producers?
- Your Tasks
- Activity
Your order:
- Sum of total amount of each product
- List of avatars / initials of who ordered it
## Technical Architecture
### DNAs
#### Plenty
Zomes:
- Profiles
- File-storage
- Peer-status
- Alerts?
##### Household
User stories
- When you enter the app, after having created your profile, you have 2 options:
- Create a household
- Join a household
- Just one of the available ones in the DHT
- Selecting a household creates a request to join that household
- One of the household members can approve the request
- TODO: mitigate impersonation attacks here
- Out of band handshake with number?
- Household members should be able to leave the household
- If all household members leave a household, it should get automatically archived
```mermaid
graph TD;
ACTIVE_HOUSEHOLDS-->Household1;
ACTIVE_HOUSEHOLDS-->Household2;
Household1-->|join_request|BobPubKey;
Household1-->|member|AlicePubKey;
```
```rust
struct Household {
nickname: String,
photo: Option<EntryHash>,
}
struct HousholdMembershipClaim {
household_hash: ActionHash,
member_create_link_hash: ActionHash // Member create link
}
```
##### Producers
User stories:
- Anyone should be able to create a producer, they automatically become their liason
- The liason of a producer can configure the roles for a producer
- Editors: who can edit the products. Liason is implied.
- Everyone
- List of people
- Sorters: the ones that receive the delivery, check and sort
- Liason
- List of people
- The editors of a producer should be able to edit the products for the producer.
```rust
enum ProducerEditors {
Liason
AllMembers,
Members(Vec<AgentPubKey>)
}
struct Producer {
name: String,
photo: EntryHash,
contact_email: String,
phone_number: String,
location: String,
producer_details: String, // Textarea
liason: AgentPubKey,
editors: ProducerEditors,
}
enum PackagingUnit {
Piece,
Kilograms,
Grams,
Liters,
Pounds,
Ounces
}
struct Packaging {
unit: PackagingUnit,
amount: f32,
estimate: bool
}
struct Product {
producer_hash: ActionHash,
name: String,
product_id: String,
description: String,
categories: Vec<String>,
packaging: Packaging,
maximum_available: Option<u32>,
price: u32,
vat_percentage: u32,
margin_percentage: Option<u32>,
origin: Option<String>,
ingredients: Option<String>,
}
```
```mermaid
flowchart LR
ALL_PRODUCT_CATEGORIES-->meat
ALL_PRODUCT_CATEGORIES-->rice
ALL_PRODUCT_CATEGORIES-->chocolate
ALL_PRODUCERS-->producer1
ALL_PRODUCERS-->producer2
producer1-->product1
meat-->product1
```
##### Orders
User stories:
- General manager creates an order
- The liasons for all the producers are notified
- Liasons respond whether or not the producers are available, and if so, that the products are up to date
- Aggregate order paper for producer, in PDF
- Optional breakdown by household order
- Check that delivery matches order
- Something was not available
- price has changed
- Something was missing in the delivery
- The amount was different than the ordered one
- When the order goes to Processed
- Trigger notification to households that the food is ready to be picked up
- Give a summary of any changes that happened to the order
- Give a number of how much to pay
- The bookkeeper receives the payment from the households
- In the case that the payment was wrong, it notifies them about it, and requests that they change it
```rust
enum OrderStatus {
Preparing, // Triggers a notification to all liasons and mark when done
Open {
deadline: Timestamp,
available_producers: Vec<ActionHash> // What about updates here?
}, // Triggers a notification to all members
Closed {
household_orders: Vec<ActionHash> // Check maximum amount of products is not exceeded, TODO: how to resolve conflicts? maybe liason can update the household order
}, // Can't edit your order
Processed { // done automatically once all the liasons agree that everything is correct
producers_deliveries: Vec<ActionHash>
}, // Food is sorted and can be picked up
Finished { // done automatically once all the payments have been checked and all the invoices have been paid
household_payments: Vec<ActionHash>, // Actually these are actionhashes for the `paid` links from the order to the household
producers_invoices: Vec<ActionHash>,
} // The members have payed the organization, and
// The invoices for the producers have been uploaded by the liasons
// The invoices for the producers have been paid by the bookkeeper
}
struct Order {
status: OrderStatus
}
struct ProductOrder {
original_product_hash: ActionHash,
orderded_product_hash: ActionHash,
amount: u32
}
struct HouseholdOrder {
household_hash: ActionHash,
order_hash: ActionHash,
products: Vec<ProductOrder>
}
struct FixedProductDeliveryForHouseholds {
amount: u32,
households_hashes: Vec<ActionHash> // Usually just one
}
struct EstimatedProductDeliveryForHouseholds {
products: Vec<f32>, // Usually weight?
households_hashes: Vec<ActionHash> // Usually just one
}
enum DeliveredAmount {
FixedAmountProduct {
delivered_products: Vec<FixedProductDeliveryForHouseholds>,
price_per_unit_changed: Option<u32>
},
EstimatedProduct {
delivered_products_by_household: Vec<EstimatedProductDeliveryForHouseholds>,
price_per_unit_changed: Option<u32>
}
}
enum ProductDelivery {
NotAvailable,
Missing(String), // There was a mistake
Delivered(DeliveredAmount)
}
struct ProducerDelivery {
producer_hash: ActionHash,
order_hash: ActionHash,
products: HashMap<ActionHash, ProductDelivery>
}
struct ProducerInvoice {
order_hash: ActionHash,
producer_hash: ActionHash,
invoice: EntryHash
}
enum BadPaymentReason {
PaymentMissing,
BadAmount {
amount_expected: u32,
amount_paid: u32
},
Other(String)
}
```
```mermaid
flowchart LR
ACTIVE_ORDERS-->order1
order1-->|producer_ready|producer1
order1-->|not_available|producer2
order1-->household_order1
order1-->household_order2
household1-->household_order1
order1-->|processed|producer1_delivery
order1-->|processed|producer2_delivery
bookkeeper-->|request_confirm_payment, order_hash, amount|household1
household1-->|bad_payment, BadPaymentReason|household1
order1-->|household_order_paid|household2
order1-->|producer_order_paid|producer1_invoice
order1-->|producer_order_paid|producer2_invoice
```
##### Roles
- Admin: first one to create the buyers club
- Edit producers
- Change liason
- Producer details
- Products
- Edit households
- Delete households
- Add and remove members
- Create invite link
- Gets all the roles at first
- Set the bookkeeper role
- Set the order manager role
- Order managers
- Create order
- Open order
- Close order
- Bookkeeper
- Mark payments as completed
- Mark invoices as paid
- Upload invoices for producers
For each producer:
- Liason
- Edit producer
- Edit products
- Transfer liason
- Update and delete ProducerDeliveries
- Editors
- Can only edit the products
#### Notifications
- Notifications UI
- Notifications settings
- Sending email
- Persistent notifications?