# via-develop/data-nursery architecture

> Architecture diagram of the GitHub repository via-develop/data-nursery, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/via-develop/data-nursery
- Repository: https://github.com/via-develop/data-nursery

## Overview

##### Main System Components

The system should be represented with these primary components:

a) Frontend Layer:
- Manager Frontend (manager_front)
- Dashboard interface
- Farm management
- Settings management
- Statistics and predictions
- Nursery Frontend (nursery_front)
- Work management
- QR scanning functionality
- Statistics viewing
- Planter registration

b) Backend Layer:
- Authentication Service
- Crop Management Service
- Planter Management Service
- Database Layer (indicated by alembic migrations)
- ML Model Integration (evident from model/*.pkl files)
- Scheduled Tasks (schedule directory)

##### Specific Implementation Details

Frontend Section:
**┌─────────────────────┐    ┌─────────────────────┐**
- Manager Frontend  │    │  Nursery Frontend   │
- (Next.js Client)   │    │   (Next.js Client)  │
- ┘    └─────────────────────┘

Backend Services:
**┌─────────────────────────────────────────────┐**
- FastAPI Backend               │
- ┬─────────────┬────────────────┤
- Auth     │   Crops     │    Planter     │
- Service   │  Service    │    Service     │
- ┴─────────────┴────────────────┘

Data Layer:
**┌─────────────┐    ┌─────────────┐    ┌─────────────┐**
- Database   │    │  ML Models  │    │ Scheduled   │
- (SQL)      │    │  (LightGBM) │    │   Tasks     │
- ┘    └─────────────┘    └─────────────┘

##### Additional Elements

- Data flow directions
- API endpoint groupings
- Database migration connections
- File upload paths
- Scheduled task triggers

##### Key Interactions to Highlight

- QR code scanning flow
- Real-time planter status updates
- ML prediction pipeline
- Data synchronization between manager and nursery interfaces
- Authentication and authorization paths

##### Technical Stack Indicators

Technology labels:
- Next.js for frontends
- FastAPI for backend
- SQLAlchemy for ORM
- Alembic for migrations
- LightGBM for ML models
- JWT for authentication

Remember to include cross-cutting concerns such as:
- Authentication/Authorization flows
- File upload handling
- Error handling
- Logging mechanisms
- Scheduled task execution

This system design should effectively communicate the architecture of the automated seeding data platform while highlighting the separation between manager and nursery interfaces, and their interaction with the backend services.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        MF["Manager Frontend"]
        MF_D["Dashboard"]:::frontend
        MF_FM["Farm Management"]:::frontend
        MF_S["Settings"]:::frontend
        MF_SP["Statistics & Predictions"]:::frontend
        
        NF["Nursery Frontend"]
        NF_WM["Work Management"]:::frontend
        NF_QR["QR Scanner"]:::frontend
        NF_S["Statistics"]:::frontend
        
        MF --> MF_D
        MF --> MF_FM
        MF --> MF_S
        MF --> MF_SP
        
        NF --> NF_WM
        NF --> NF_QR
        NF --> NF_S
    end
    
    subgraph Backend
        AS["Authentication Service"]:::backend
        AS_A["Admin Auth"]:::backend
        AS_M["Auth Models"]:::backend
        AS_R["Auth Routes"]:::backend
        
        CMS["Crop Management"]:::backend
        CMS_A["Admin Management"]:::backend
        CMS_M["Crop Models"]:::backend
        CMS_R["Crop Routes"]:::backend
        
        PMS["Planter Management"]:::backend
        PMS_A["Admin Management"]:::backend
        PMS_M["Planter Models"]:::backend
        PMS_R["Planter Routes"]:::backend
        
        AS --> AS_A
        AS --> AS_M
        AS --> AS_R
        
        CMS --> CMS_A
        CMS --> CMS_M
        CMS --> CMS_R
        
        PMS --> PMS_A
        PMS --> PMS_M
        PMS --> PMS_R
    end
    
    subgraph Data
        DB["Database"]:::database
        DB_M["Migrations"]:::database
        
        ML["ML Models"]:::ml
        ML_F["Model Files"]:::ml
        
        ST["Scheduled Tasks"]:::schedule
        ST_M["Main Schedule"]:::schedule
        
        UTILS["Utilities"]:::utils
        UTILS_DB["Database Utils"]:::utils
        UTILS_FU["File Upload"]:::utils
        UTILS_JWT["JWT Utils"]:::utils
        UTILS_LOG["Logging"]:::utils
        
        DB --> DB_M
        ML --> ML_F
        ST --> ST_M
        
        UTILS --> UTILS_DB
        UTILS --> UTILS_FU
        UTILS --> UTILS_JWT
        UTILS --> UTILS_LOG
    end
    
    MF --> AS
    MF --> CMS
    MF --> PMS
    
    NF --> AS
    NF --> CMS
    NF --> PMS
    
    AS --> DB
    CMS --> DB
    PMS --> DB
    
    CMS --> ML
    PMS --> ML
    
    ST --> CMS
    ST --> PMS

    %% Click events for component mapping
    click MF "https://github.com/via-develop/data-nursery/tree/main/manager_front/src"
    click MF_D "https://github.com/via-develop/data-nursery/tree/main/manager_front/src/components/dashboard"
    click MF_FM "https://github.com/via-develop/data-nursery/tree/main/manager_front/src/components/management"
    click MF_S "https://github.com/via-develop/data-nursery/tree/main/manager_front/src/components/setting"
    click MF_SP "https://github.com/via-develop/data-nursery/tree/main/manager_front/src/components/statistics"
    
    click NF "https://github.com/via-develop/data-nursery/tree/main/nursery_front/src"
    click NF_WM "https://github.com/via-develop/data-nursery/tree/main/nursery_front/src/pages/work"
    click NF_QR "https://github.com/via-develop/data-nursery/blob/main/nursery_front/src/pages/QR-scanner.jsx"
    click NF_S "https://github.com/via-develop/data-nursery/tree/main/nursery_front/src/components/statistics"
    
    click AS "https://github.com/via-develop/data-nursery/tree/main/backend/src/auth"
    click AS_A "https://github.com/via-develop/data-nursery/tree/main/backend/src/auth/admin"
    click AS_M "https://github.com/via-develop/data-nursery/blob/main/backend/src/auth/models.py"
    click AS_R "https://github.com/via-develop/data-nursery/blob/main/backend/src/auth/router.py"
    
    click CMS "https://github.com/via-develop/data-nursery/tree/main/backend/src/crops"
    click CMS_A "https://github.com/via-develop/data-nursery/tree/main/backend/src/crops/admin"
    click CMS_M "https://github.com/via-develop/data-nursery/blob/main/backend/src/crops/models.py"
    click CMS_R "https://github.com/via-develop/data-nursery/blob/main/backend/src/crops/router.py"
    
    click PMS "https://github.com/via-develop/data-nursery/tree/main/backend/src/planter"
    click PMS_A "https://github.com/via-develop/data-nursery/tree/main/backend/src/planter/admin"
    click PMS_M "https://github.com/via-develop/data-nursery/blob/main/backend/src/planter/models.py"
    click PMS_R "https://github.com/via-develop/data-nursery/blob/main/backend/src/planter/router.py"
    
    click DB "https://github.com/via-develop/data-nursery/tree/main/backend/alembic"
    click DB_M "https://github.com/via-develop/data-nursery/tree/main/backend/alembic/versions"
    
    click ML "https://github.com/via-develop/data-nursery/tree/main/backend/model"
    click ML_F "https://github.com/via-develop/data-nursery/blob/main/backend/model/lgb_kfold_*.pkl"
    
    click ST "https://github.com/via-develop/data-nursery/tree/main/backend/schedule"
    click ST_M "https://github.com/via-develop/data-nursery/blob/main/backend/schedule/schadule_main.py"
    
    click UTILS_DB "https://github.com/via-develop/data-nursery/blob/main/backend/utils/database.py"
    click UTILS_FU "https://github.com/via-develop/data-nursery/blob/main/backend/utils/file_upload.py"
    click UTILS_JWT "https://github.com/via-develop/data-nursery/blob/main/backend/utils/jwt_utils.py"
    click UTILS_LOG "https://github.com/via-develop/data-nursery/blob/main/backend/utils/log_config.py"

    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef ml fill:#9b59b6,stroke:#8e44ad,color:white
    classDef schedule fill:#e67e22,stroke:#d35400,color:white
    classDef utils fill:#95a5a6,stroke:#7f8c8d,color:white
```
