# haviwijayalath/farmlink architecture

> Architecture diagram of the GitHub repository haviwijayalath/farmlink, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/haviwijayalath/farmlink
- Repository: https://github.com/haviwijayalath/farmlink

## Overview

##### Project type and purpose
- FarmLink is a full-stack, PHP-based MVC web application that connects farmers and buyers in a wholesale market.
- Built from scratch (no framework) using PHP for backend logic, HTML/CSS for presentation, and JavaScript for client-side behavior.

##### File structure
- Top-level “app” directory implements the MVC layers:
– app/config: configuration (database credentials, environment)
– app/bootstrap.php: application entry setup
– app/libraries: Core router, base Controller, Database class
– app/helpers: cross-cutting utilities (mailer, sessions, flash messages, notifications, URL)
– app/controllers: one controller per resource (Admin, Buyers, Farmers, etc.)
– app/models: domain objects matching controllers (User, Order, Appointment, Complaint…)
– app/views: view templates organized by module (admin, buyer, consultant, d_person, farmers, forum, home, users)
- “public” directory is the document root:
– public/index.php: front controller
– public/css, js, images: static assets
– .htaccess files for URL rewriting
- composer.json for dependency metadata (even if no external PHP packages are used)

##### README
- Confirms MVC architecture and tech stack (PHP, HTML, CSS, JS)

##### Components
a. Main components
1. Client (Browser)
2. Web Server / PHP-FPM (serving public/index.php + .htaccess rewrites)
3. Front Controller (public/index.php)
4. Router (app/libraries/Core)
5. Controllers (app/controllers)
6. Models & Data Access (app/models + app/libraries/Database)
7. Views (app/views)
8. Configuration & Bootstrap (app/bootstrap.php + app/config)
9. Helpers & Libraries (mailer_config, session_helper, notification_helper…)
10. Relational Database (MySQL or PostgreSQL)
11. External Services (SMTP/email provider via mailer_config)
b. Relationships & data flow
– Browser → HTTP Request → Web Server
– Web Server → public/index.php → Router
– Router → Appropriate Controller
– Controller → Models → Database
– Database → Query Results → Model
– Controller → View (passing model data)
– View → Render HTML → Response to Browser
– Controller → Helpers → External Services (e.g., send email via SMTP)
– Static assets (CSS/JS/images) served directly by Web Server to Browser
c. Architectural patterns & design principles
– MVC: separation of concerns between models, views, controllers
– Front-controller & router pattern for clean URLs
– Layered architecture: presentation → application logic → data access
– Dependency inversion in helper/libraries for cross-cutting concerns
d. Key technologies, frameworks, libraries
– PHP (7.x or 8.x)
– Apache or Nginx + PHP-FPM
– MySQL/PostgreSQL (via app/libraries/Database)
– HTML5, CSS3, JavaScript (notifications.js, client validation)
– .htaccess for URL rewriting

##### Elements
– Clear, concise labels for every component (e.g., “Router (app/libraries/Core)”)
- Green for helpers/external services
- Orange for static asset delivery

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser((Browser)):::client
        WebServer("Web Server / PHP-FPM"):::webserver
        StaticAssets("Static Assets\n(public/css, js, images)"):::static
        FrontController("Front Controller\npublic/index.php"):::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        Router("Router\napp/libraries/Core.php"):::app
        Controllers("Controllers\napp/controllers/*.php"):::app
        Models("Models\napp/models/*.php"):::app
        Views("Views\napp/views/"):::frontend
        Helpers("Helpers & Utilities\napp/helpers/*.php"):::helper
    end

    %% Data Layer
    subgraph "Data Layer"
        Config("Config & Bootstrap\napp/bootstrap.php\napp/config/"):::config
        DBClass("Database Layer\napp/libraries/Database.php"):::data
        Database[(Relational Database)]:::db
    end

    ExternalSMTP[(SMTP Service)]:::external

    %% Connections
    Browser -->|HTTP Request| WebServer
    WebServer -->|Rewrite & Dispatch| FrontController
    WebServer -->|Serve Static| StaticAssets
    FrontController -->|initialize| Config
    FrontController -->|route to| Router
    Router -->|dispatch| Controllers
    Controllers -->|use| Models
    Models -->|query via| DBClass
    DBClass -->|SQL Queries| Database
    Controllers -->|render| Views
    Views -->|HTML Response| Browser
    Controllers -->|invoke| Helpers
    Helpers -->|SMTP Calls| ExternalSMTP

    %% Click Events
    click FrontController "https://github.com/haviwijayalath/farmlink/blob/main/public/index.php"
    click Router "https://github.com/haviwijayalath/farmlink/blob/main/app/libraries/Core.php"
    click Controllers "https://github.com/haviwijayalath/farmlink/tree/main/app/controllers/"
    click Models "https://github.com/haviwijayalath/farmlink/tree/main/app/models/"
    click Views "https://github.com/haviwijayalath/farmlink/tree/main/app/views/"
    click Helpers "https://github.com/haviwijayalath/farmlink/tree/main/app/helpers/"
    click Config "https://github.com/haviwijayalath/farmlink/blob/main/app/bootstrap.php"
    click Config "https://github.com/haviwijayalath/farmlink/tree/main/app/config/"
    click DBClass "https://github.com/haviwijayalath/farmlink/blob/main/app/libraries/Database.php"
    click StaticAssets "https://github.com/haviwijayalath/farmlink/tree/main/public/css/"

    %% Styles
    classDef client fill:#E8F5FE,stroke:#0288D1,color:#01579B;
    classDef webserver fill:#E3F2FD,stroke:#64B5F6,color:#1976D2;
    classDef frontend fill:#BBDEFB,stroke:#2196F3,color:#0D47A1;
    classDef app fill:#C8E6C9,stroke:#66BB6A,color:#2E7D32;
    classDef helper fill:#DCEDC8,stroke:#9CCC65,color:#33691E;
    classDef data fill:#FFE0B2,stroke:#FFB74D,color:#E65100;
    classDef db fill:#CFD8DC,stroke:#90A4AE,color:#37474F;
    classDef config fill:#F3E5F5,stroke:#BA68C8,color:#4A148C;
    classDef static fill:#FFF3E0,stroke:#FFCC80,color:#E65100;
    classDef external fill:#E1F5FE,stroke:#4FC3F7,color:#01579B;
```
