How guilogar/tfm works
Main Components
• Backend Service: This is built in Node.js with Express (as suggested by app.js and routes). It contains API endpoints, middleware, and multiple services to handle tasks such as user authentication, crop events, notifications, scheduled tasks (cron jobs), and integration with external services.
• Database: The backend connects to a PostgreSQL database (as detailed in the README and docker-compose.yml) using Sequelize ORM. It also has interactions with Cosmos DB (e.g., config-cosmos.js and related get/set event services).
• Firebase Service: Both backend and frontend include configuration for Firebase (Firebase service account for the backend and various credentials files for the frontend including Android and public configurations). This supports notifications or authentication services.
• Frontend Client: Developed with Ionic (and likely React given the “REACT_APP” environment variables and file structure in the “frontend/src” directory). It is built to run on web browsers and mobile (Android via Capacitor), offering screens for crops, events, notifications, irrigation, and more.
• Predictions Module: A separate Python-based module (using conda, SQLAlchemy, and psycopg2) that performs predictions related to irrigate data. This module is likely scheduled or triggered via npm tasks and interacts with the PostgreSQL database.
Relationships and Interactions
• The Frontend communicates via RESTful API calls to the Backend Service to fetch data, trigger events, and update state.
• The Backend handles business logic, interfacing with the PostgreSQL database for persistent storage via Sequelize.
• The Backend also interacts with external services such as Cosmos DB (for some specific event or data processing tasks) and Firebase (for push notifications and authentication, plus receiving Firebase tokens).
• The Predictions module runs computations (in Python) which may extract or update data in the PostgreSQL database, likely providing predictive insights on irrigate events.
• Scheduled tasks (cron jobs within the backend) periodically fetch or update events.
• Docker Compose is used to orchestrate several components (e.g., database, backend services) for local development.
Important Architectural Patterns & Technologies
• Separation of Concerns: The clear segmentation into frontend, backend, and predictions accentuates modularity.
• MVC-Like structure in the backend: Routes, services, middleware, and database models are clearly separated.
• Microservice-like aspects: With a distinct Python predictions module and independent deployment for mobile and web frontends, the architecture leverages loosely coupled components.
• Use of modern web technologies: Ionic with React on the frontend, Node.js/Express on the backend, and Sequelize ORM for relational data management.
• Integration with external services: Firebase for notifications and Cosmos DB for non-relational data storage.
Specific Elements
• “Frontend (Ionic/React)” for mobile and web client.
• “Backend (Node.js/Express)” including sub-components like API routes, middleware, and scheduled tasks.
• “PostgreSQL Database (Sequelize)” and “Cosmos DB” for external data sources.
• “Predictions Module (Python)” with libraries SQLAlchemy and psycopg2.
• “Firebase Services” for authentication and notifications.
• Data flow from Frontend → Backend (HTTP calls).
• Backend → Database (CRUD operations via Sequelize) and Backend → Cosmos DB (event syncing).
• Backend → Firebase (for token management/notifications).
• Predictions Module ↔ PostgreSQL Database.
• Different languages or stacks (e.g., blue for Node.js components, green for the database, orange for Python predictions).
• Different deployment or architectural layers.
• Notes for design patterns (like MVC in the backend or separation of concerns between predictions and main API).