System Architecture
The F4E AppSheet system is built on a robust, trigger-driven architecture that ensures data consistency and automates complex business processes. This document provides a comprehensive overview of the system's technical architecture.
High-Level Architecture
Database Schema Overview
The system is built around 16 core tables that handle different aspects of kitchen operations:
Core Tables
| Table | Purpose | Key Relationships |
|---|---|---|
public.kitchen | Kitchen master data | Links to plan, projection |
public.school | School master data | Links to projection, school_bom |
meal_plan | Central meal planning | Links to plan |
plan | Kitchen-specific plans | Central table, links to all others |
projection | School-level projections | Links to plan, consumption |
consumption | Ingredient consumption | Links to projection, picking |
picking | Picking list management | Links to plan, consumption |
product_master | Product catalog | Links to consumption, picking |
ingredients | Recipe ingredients | Links to consumption |
school_bom | School BOM configuration | Links to school, ingredients |
Supporting Tables
| Table | Purpose | Key Relationships |
|---|---|---|
stock_adjustment | Inventory adjustments | Links to kitchen |
stock_count | Physical stock counts | Links to kitchen |
stock_summary | Inventory summaries | Links to kitchen |
plan_recipe_log | Recipe execution logs | Links to plan |
kitchen_mapping | Kitchen management | Links to kitchen |
meals | Meal catalog | Links to ingredients |
⚡ Trigger System Architecture
The system uses 11 critical trigger functions to maintain data consistency and automate business processes:
Plan Status Triggers
Projection Triggers
Data Sync Triggers
Data Flow Architecture
1. Meal Plan Creation Flow
2. Plan Status Change Flow
Database Design Principles
1. Normalization
- 3NF Compliance: All tables follow third normal form
- Referential Integrity: Foreign key constraints ensure data consistency
- Atomic Values: Each field contains a single, atomic value
2. Performance Optimization
- Strategic Indexing: Indexes on frequently queried columns
- Materialized Views: Pre-calculated aggregations for performance
- Trigger Optimization: Efficient trigger functions with cascade prevention
3. Data Integrity
- Audit Trails: All tables include
created_at,updated_at,created_by,updated_by - Status Validation: Business rules enforced through triggers
- Data Validation: Input validation at both application and database levels
Security Architecture
1. Access Control
- Role-Based Access: Different access levels for different user roles
- Data Partitioning: Users only see data relevant to their role
- Audit Logging: All changes tracked with user attribution
2. Data Protection
- Encryption: Sensitive data encrypted in transit and at rest
- Backup Strategy: Regular automated backups
- Recovery Procedures: Point-in-time recovery capabilities
Integration Architecture
1. External System Integration
2. Sync Processes
- Real-time Sync: Critical data synchronized immediately
- Batch Sync: Non-critical data synchronized in batches
- Conflict Resolution: Automated conflict resolution strategies
Scalability Considerations
1. Performance
- Database Optimization: Query optimization and indexing
- Caching Strategy: Materialized views for frequently accessed data
- Load Balancing: Distributed processing for high-volume operations
2. Growth
- Horizontal Scaling: Database partitioning strategies
- Vertical Scaling: Resource allocation optimization
- Monitoring: Performance monitoring and alerting
Automation & Bots
The F4E AppSheet system includes several automated bots that handle critical business processes and notifications. These bots ensure timely communication and document generation without manual intervention.
Bot Architecture
Bot Functions
1. Plan to Active - Generate PDF Bot
- Trigger: When plan status changes from "Open" to "Active"
- Action: Generates PDF documents for meal plans
- Template: Custom Google Doc template (DocId: 1e5igEZvAdoSlATJ0jAq2fy-H2bKD4BtmcuE77bBLs_A)
- File Storage: appsheet-recipes file store
- Naming Convention:
\{Kitchen_Name\}_Plan_\{Plan_ID\}_\{Date\}_\{Meal_Type\}.pdf
2. Generate Delivery Note Bot
- Trigger: DNote Generation event
- Action: Creates delivery notes for orders
- Template: Custom Google Doc template (DocId: 1H4nlXJIbC8stY7vcDWaoZsVyLiPJS-qzIgQlRX5_aCA)
- File Storage: Default file store in
/appsheet/data/kitchen_ops_training-357142272/Files/orders - Naming Convention:
\{Kitchen_Name\}- Order\{Order_Number\} - \{Date\}
3. Notify Warehouse Bot
- Trigger: Order posted event
- Action: Sends email notification to warehouse managers
- Recipients: Warehouse managers (role = "WHSE")
- Email Template: Order details with ingredient quantities
- Subject: "Order {order_no} Created"
4. Notify Kitchen Bot
- Trigger: Order issued event
- Action: Sends email notification to kitchen managers
- Recipients: Kitchen managers for specific kitchen
- Email Template: Order details with issued quantities
- Subject: "Order {order_no} Issued"
Email Configuration
All bot-generated emails and support communications are configured with centralized email management:
- Primary Support Email: appsheet-support@food4education.org
- Auto-Forward Target: appsheet@food4education.org
- CC Recipient: Brian Mwangi
- ETS Integration: All emails are automatically copied to ETS system for tracking and management
Bot Security & Permissions
- Trigger Security: Bots bypass security filters when necessary for system operations
- Data Access: Bots have appropriate permissions to access required tables
- Audit Trail: All bot actions are logged with timestamps and user attribution
- Error Handling: Failed bot operations are logged and can be retried
Technical Stack
| Component | Technology | Purpose |
|---|---|---|
| Mobile App | AppSheet | Cross-platform mobile application |
| Database | PostgreSQL 13+ | Primary data storage |
| Backend | AppSheet Platform | Business logic and API |
| Integration | Google Workspace | Authentication and collaboration |
| Monitoring | Built-in Analytics | Performance and usage tracking |
| Automation | AppSheet Bots | Automated workflows and notifications |
Deployment Architecture
1. Environment Strategy
- Development: Local development environment (Google sheets)
- Staging: Pre-production testing environment (Postgres DB)
- Production: Live system environment
2. Data Migration
- Version Control: Database schema versioning
- Migration Scripts: Automated database migrations
- Rollback Procedures: Safe rollback capabilities
This architecture ensures the F4E AppSheet system is robust, scalable, and maintainable while providing excellent performance for all user roles and business processes.