How ngoctruongbui2003/smart-agriculture-system works
Main Components
• NestJS Application Server – This is the core of the project that ties everything together. It’s built using Nest’s modular architecture, so each “module” (auth, field, mail, sensor, users, watering-history, weather) becomes a distinct component.
• Modules/Domain Components – Within the server, you have several modules:
◦ Auth Module – Handles authentication and related services.
◦ Field, Users, and Weather Modules – Represent domain-specific logic and API endpoints.
◦ Sensor Module – Notably includes a WebSocket gateway (sensor.gateway.ts) for real-time data updates.
◦ Mail Module – Provides email integration (using email templates, e.g., gas-alert.hbs and weekly-report.hbs).
◦ Watering History Module – Likely handles historical data logging.
• MQTT Broker – The mosquitto folder (with its configuration file) indicates that MQTT (via Mosquitto) is used, probably to ingest or relay sensor or external IoT data.
• Database (Implied) – The “schemas” directory (for fields, sensors, users, etc.) hints at a persistent layer (likely using MongoDB via Mongoose or another ORM/ODM) that stores application data.
• Deployment & Infrastructure – Dockerfile, docker-compose.yml, and CI/CD configuration under .github/workflows show that containerization and automated deployment are part of the solution.
Relationships and Interactions
• That controllers and services within each module interact with each other – e.g., controllers receive HTTP requests and delegate to corresponding services.
• That the Sensor Module includes a WebSocket gateway which manages real-time communication with clients.
• Optionally, add an external Email Service component connected to the Mail Module.
Architectural Patterns & Design Principles
• Modular Architecture – Each domain function (authentication, sensor management, mailing, etc.) is encapsulated in its own module, promoting separation of concerns.
• Service & Controller Pattern (MVC-like) – Within each module, controllers handle requests, while providers (services) encapsulate business logic.
• Inter-Service Communication – If necessary, indicate data flows between modules (e.g., sensor data might trigger notifications via the Mail Module).
• Containerization – Represent the deployment infrastructure with a Docker container group that includes the NestJS server, the MQTT broker (Mosquitto), and potentially the database.
Incorporate Relevant Technologies
• Framework: NestJS with TypeScript.
• WebSockets: Used in the sensor module via a gateway for real-time communication.
• MQTT Broker: Mosquitto for messaging.
• CI/CD & Deployment: GitHub Actions (.github/workflows), Docker, docker-compose, and even pointers to cloud deployment with NestJS Mau.