diff --git a/README.md b/README.md index 9218408..00bec0f 100644 --- a/README.md +++ b/README.md @@ -40,28 +40,80 @@ A web application for tracking grocery prices and shopping events. Built with Fa ## Data Model -### Groceries -- `id`: Primary key -- `name`: Grocery name -- `price`: Current price -- `category`: Food category -- `organic`: Boolean flag -- `weight`: Weight/volume -- `weight_unit`: Unit (g, kg, ml, l, piece) +### Core Entities -### Shops -- `id`: Primary key -- `name`: Shop name -- `city`: Location city -- `address`: Optional full address +#### Groceries (`groceries` table) +- `id`: Integer, Primary key, Auto-increment +- `name`: String, Grocery name (indexed, required) +- `category`: String, Food category (required) +- `organic`: Boolean, Organic flag (default: false) +- `weight`: Float, Weight/volume (optional) +- `weight_unit`: String, Unit of measurement (default: "piece") + - Supported units: "g", "kg", "ml", "l", "piece" +- `created_at`: DateTime, Creation timestamp (auto-generated) +- `updated_at`: DateTime, Last update timestamp (auto-updated) -### Shopping Events -- `id`: Primary key -- `shop_id`: Foreign key to shops -- `date`: Purchase date -- `total_amount`: Optional total cost -- `notes`: Optional notes -- `groceries`: Many-to-many relationship with amounts +#### Shops (`shops` table) +- `id`: Integer, Primary key, Auto-increment +- `name`: String, Shop name (indexed, required) +- `city`: String, Location city (required) +- `address`: String, Full address (optional) +- `created_at`: DateTime, Creation timestamp (auto-generated) + +#### Shopping Events (`shopping_events` table) +- `id`: Integer, Primary key, Auto-increment +- `shop_id`: Integer, Foreign key to shops (required) +- `date`: DateTime, Purchase date (required, default: current time) +- `total_amount`: Float, Total cost of shopping event (optional, auto-calculated) +- `notes`: String, Optional notes about the purchase +- `created_at`: DateTime, Creation timestamp (auto-generated) + +### Association Table + +#### Shopping Event Groceries (`shopping_event_groceries` table) +Many-to-many relationship between shopping events and groceries with additional data: +- `id`: Integer, Primary key, Auto-increment +- `shopping_event_id`: Integer, Foreign key to shopping_events (required) +- `grocery_id`: Integer, Foreign key to groceries (required) +- `amount`: Float, Quantity purchased in this event (required, > 0) +- `price`: Float, Price at time of purchase (required, ≥ 0) + +### Relationships + +``` +┌─────────────────┐ ┌─────────────────────────────┐ ┌─────────────────┐ +│ Shops │ │ Shopping Event Groceries │ │ Groceries │ +│ │ │ (Association Table) │ │ │ +│ • id │ ←──────→│ • shopping_event_id │ ←──────→│ • id │ +│ • name │ 1:N │ • grocery_id │ N:M │ • name │ +│ • city │ │ • amount │ │ • category │ +│ • address │ │ • price │ │ • organic │ +│ • created_at │ │ │ │ • weight │ +└─────────────────┘ └─────────────────────────────┘ │ • weight_unit │ + │ │ │ • created_at │ + │ │ │ • updated_at │ + │ 1:N │ └─────────────────┘ + ▼ │ +┌─────────────────┐ │ +│ Shopping Events │ ←───────────────────────┘ +│ │ 1:N +│ • id │ +│ • shop_id │ +│ • date │ +│ • total_amount │ +│ • notes │ +│ • created_at │ +└─────────────────┘ +``` + +### Key Features + +- **Price History**: Each grocery purchase stores the price at that time, enabling price tracking +- **Flexible Quantities**: Support for decimal amounts (e.g., 1.5 kg of apples) +- **Auto-calculation**: Total amount can be automatically calculated from individual items +- **Free Items**: Supports items with price 0 (samples, promotions, etc.) +- **Audit Trail**: All entities have creation timestamps for tracking +- **Data Integrity**: Foreign key constraints ensure referential integrity ## Setup Instructions