# Source Tree Analysis - Main This document provides an annotated overview of the project's source code structure, focusing on the `internal/` directory which contains the core application logic. ``` internal/ ├── app/ # Application Layer: Handles HTTP requests, DTOs, and orchestrates services. │ ├── api/ # API Definitions and Routing (Echo framework). │ ├── controller/ # Request Handlers for various domains (User, Device, Plan, Pig Farm, Monitor). │ │ ├── device/ # Device-related API controllers. │ │ ├── management/ # Management-related API controllers (e.g., Pig Batch). │ │ ├── monitor/ # Monitoring-related API controllers. │ │ ├── plan/ # Plan-related API controllers. │ │ └── user/ # User-related API controllers. │ ├── dto/ # Data Transfer Objects: Request/response models for API. │ ├── middleware/ # HTTP Middleware (e.g., authentication, audit logging). │ ├── service/ # Application Services: Business logic orchestration. │ └── webhook/ # Webhook handlers (e.g., ChirpStack). ├── core/ # Core Application Components: Initialization and data setup. │ ├── application.go # Main application setup. │ ├── component_initializers.go # Initializes various application components. │ └── data_initializer.go # Initializes core data. ├── domain/ # Domain Layer: Business logic and entities. │ ├── audit/ # Audit-related domain services. │ ├── device/ # Device-related domain services. │ ├── notify/ # Notification domain services. │ ├── pig/ # Pig and Pig Batch related domain services. │ ├── scheduler/ # Scheduling domain services. │ ├── task/ # Task-related domain services. │ └── token/ # Token management domain services. └── infra/ # Infrastructure Layer: External concerns (DB, logging, config, external APIs). ├── config/ # Configuration management. ├── database/ # Database connection and ORM setup (PostgreSQL, SQLite). ├── logs/ # Logging utilities. ├── models/ # GORM Models (Database schema definitions). ├── notify/ # Notification implementations (Lark, SMTP, WeChat). ├── repository/ # Data Repositories: Database interaction logic. ├── transport/ # External Communication (e.g., LoRaWAN ChirpStack). │ ├── lora/ # LoRaWAN specific transport. │ └── proto/ # Protocol buffer definitions. └── utils/ # General utilities. ```