# jenishp619/farm_n_food architecture

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

- Interactive diagram: https://gitdiagram.com/jenishp619/farm_n_food
- Repository: https://github.com/jenishp619/farm_n_food

## Overview

##### Project Type and Purpose
- This is a full-stack, monolithic Django web application (“Farm_n_Food”) that connects local farmers to consumers.
- It follows Django’s Model-View-Template (MVT) pattern:
- Models (farmfoodapp/models.py) for data
- Views (farmfoodapp/views.py, farmfoodapp/actions.py) for business logic
- Templates (farmfoodapp/templates/…) for presentation
- Static assets (CSS, JS, images) live under /static.

##### File Structure & Architectural Insights
- Top-level files:
- Procfile, .gitlab-ci.yml: deployment on Heroku/GitLab CI
- manage.py: Django CLI entry point
- requirements.txt: Python dependencies
- db.sqlite3 (or MySQL in production)
- farmfood/: Django project settings (settings.py), URL routing (urls.py), ASGI/WGI adapters
- farmfoodapp/: core application (models, serializers, views, URLs, email helpers) + migrations + templates
- static/: served by Django (in dev) or by a CDN/Nginx (in production)

A. Client Tier
- Web Browser / Mobile WebView
- Renders HTML/CSS/JS (templates + static)
B. Presentation Tier
- Load Balancer (Heroku router or Nginx)
- Gunicorn (WSGI) / Daphne (ASGI) processes
C. Application Tier
- Django project (“farmfood”)
- farmfoodapp application
- URL router → view functions/classes → serializers / actions → models
D. Data Tier
- Relational Database (SQLite for dev, MySQL in production)
- Django ORM (models.py)
- Migrations maintaining schema
E. External Services
- SMTP Email Service (farmfoodapp/send_mail.py)
- Optional: CDN or S3 for static/media files
- 3rd-party analytics (e.g., Chart.js in Charts.html)

##### Relationships & Interactions
- Static files served either by Django’s staticfiles app or offloaded to Nginx/CDN

##### Architectural Patterns & Principles
- MVT separation of concerns
- Layered architecture:
- Presentation (templates, static)
- Business logic (views, actions)
- Data access (models, migrations)
- Configuration–Code separation (settings.py, Procfile, .gitlab-ci.yml)
- Twelve-Factor App principles for Heroku deployment

##### Checklist
- [ ] Clear labels matching file-tree names (e.g., “farmfood/urls.py → URL Dispatcher”)
- [ ] Notes on deployment artifacts (Procfile, .gitlab-ci.yml)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Tier
    Client["Web Browser / Mobile WebView"]:::client
    Static["Static Assets"]:::static
    Templates["Django Templates"]:::static
    ChartTemplate["Chart Template\n(analytics/Charts.html)"]:::static
    CustomJS["Chart.js / Custom JS"]:::static

    %% Presentation Tier: Load Balancer & Processes
    LoadBalancer["Load Balancer\n(Heroku Router or Nginx)"]:::proxy
    Procfile["Procfile"]:::proxy
    CICD[".gitlab-ci.yml"]:::proxy
    CLI["Django CLI\n(manage.py)"]:::proxy

    subgraph "Heroku Dyno" 
        direction TB
        WSGI["WSGI Adapter\n(Gunicorn)"]:::proxy
        ASGI["ASGI Adapter\n(Daphne/Channels)"]:::proxy
    end

    %% Application Tier: Django Project & App
    subgraph "Django Application" 
        direction TB
        Settings["Settings\n(farmfood/settings.py)"]:::app
        URLRouter["URL Dispatcher\n(farmfood/urls.py)"]:::app
        AppURLs["App URLs\n(farmfoodapp/urls.py)"]:::app
        Views["Views\n(farmfoodapp/views.py)"]:::app
        Actions["Actions\n(farmfoodapp/actions.py)"]:::app
        Serializers["Serializers\n(farmfoodapp/app_serializers.py)"]:::app
        Models["Models\n(farmfoodapp/models.py)"]:::app
        Migrations["Migrations\n(farmfoodapp/migrations/)"]:::app
        Tests["Tests\n(farmfoodapp/tests.py)"]:::app
        Req["requirements.txt"]:::app
    end

    %% Data Tier
    DB["Relational DB\n(db.sqlite3 / MySQL)"]:::db

    %% External Services
    EmailModule["SMTP Email Service\n(farmfoodapp/send_mail.py)"]:::external

    %% Relationships
    Client -->|HTTP| LoadBalancer
    Static -->|served over HTTP| Client
    Templates -->|HTML| Client
    ChartTemplate -->|AJAX requests| URLRouter
    CustomJS -->|AJAX requests| URLRouter

    LoadBalancer -->|HTTP| WSGI
    LoadBalancer -->|HTTP| ASGI
    CLI -->|invoke commands| URLRouter

    Procfile -->|defines dyno| WSGI
    Procfile -->|defines dyno| ASGI
    CICD -->|CI/CD pipeline| Procfile
    CICD -->|runs tests| Tests

    Req -->|installs deps| WSGI
    Req -->|installs deps| ASGI

    WSGI -->|WSGI call| URLRouter
    ASGI -->|ASGI call| URLRouter

    URLRouter -->|route| AppURLs
    AppURLs -->|route| Views
    Views -->|call| Actions
    Views -->|use| Serializers
    Views -->|query/write| Models
    Views -->|render| Templates
    Views -->|send email via SMTP| EmailModule

    Models -->|ORM SQL| DB
    Migrations -->|schema migrations| DB

    %% Click Events
    click Static "https://github.com/jenishp619/farm_n_food/tree/main/static/"
    click Templates "https://github.com/jenishp619/farm_n_food/tree/main/farmfoodapp/templates/"
    click ChartTemplate "https://github.com/jenishp619/farm_n_food/blob/main/farmfoodapp/templates/analytics/Charts.html"
    click CustomJS "https://github.com/jenishp619/farm_n_food/blob/main/static/js/custom.js"
    click Procfile "https://github.com/jenishp619/farm_n_food/tree/main/Procfile"
    click CICD "https://github.com/jenishp619/farm_n_food/blob/main/.gitlab-ci.yml"
    click CLI "https://github.com/jenishp619/farm_n_food/blob/main/manage.py"
    click WSGI "https://github.com/jenishp619/farm_n_food/blob/main/farmfood/wsgi.py"
    click ASGI "https://github.com/jenishp619/farm_n_food/blob/main/farmfood/asgi.py"
    click Settings "https://github.com/jenishp619/farm_n_food/blob/main/farmfood/settings.py"
    click URLRouter "https://github.com/jenishp619/farm_n_food/blob/main/farmfood/urls.py"
    click AppURLs "https://github.com/jenishp619/farm_n_food/blob/main/farmfoodapp/urls.py"
    click Views "https://github.com/jenishp619/farm_n_food/blob/main/farmfoodapp/views.py"
    click Actions "https://github.com/jenishp619/farm_n_food/blob/main/farmfoodapp/actions.py"
    click Serializers "https://github.com/jenishp619/farm_n_food/blob/main/farmfoodapp/app_serializers.py"
    click Models "https://github.com/jenishp619/farm_n_food/blob/main/farmfoodapp/models.py"
    click Migrations "https://github.com/jenishp619/farm_n_food/tree/main/farmfoodapp/migrations/"
    click Tests "https://github.com/jenishp619/farm_n_food/blob/main/farmfoodapp/tests.py"
    click Req "https://github.com/jenishp619/farm_n_food/blob/main/requirements.txt"
    click DB "https://github.com/jenishp619/farm_n_food/blob/main/db.sqlite3"
    click EmailModule "https://github.com/jenishp619/farm_n_food/blob/main/farmfoodapp/send_mail.py"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000
    classDef proxy fill:#90EE90,stroke:#000
    classDef app fill:#FFA500,stroke:#000
    classDef db fill:#D3D3D3,stroke:#000
    classDef external fill:#D8BFD8,stroke:#000
    classDef static fill:#E6E6FA,stroke:#000
```
