A full-stack database-driven web application built with Python Flask and MySQL for managing farmer records, agro-products, farming types, and transactional audit logs — with real-time SQL trigger-based change tracking.
| Layer | Technology |
|---|---|
| Backend | Python 3, Flask, SQLAlchemy |
| Database | MySQL |
| Frontend | HTML5, CSS3, Bootstrap, Jinja2 |
| Security | Werkzeug password hashing, Flask session management |
| DB Features | SQL Triggers, Stored Procedures, ACID-compliant CRUD |
- 👨🌾 Farmer Registration & Management — Add, update, view, and delete farmer profiles
- 🌱 Farming Type Management — Categorize and manage farming types per farmer
- 🛒 Agro-Product Management — Full CRUD for agricultural products linked to farmers
- 🔐 Secure Authentication — Login system with hashed passwords and session handling
- 📋 Automated Audit Logging — SQL triggers automatically log every INSERT, UPDATE, and DELETE to a
trigtable - 📦 Stored Procedure —
procstored procedure for efficient farmer record retrieval - 📊 Relational Database Design — Normalized schema with foreign keys and joins
farmers— core farmer records (name, location, contact, farming type)farming_type— lookup table for farming categoriesagro_products— products associated with each farmerusers— authentication table with hashed passwordstrig— audit log table populated automatically by triggers
-- Fires after every INSERT on the farmers table
AFTER INSERT ON farmers → logs to trig
-- Fires after every UPDATE on the farmers table
AFTER UPDATE ON farmers → logs to trig
-- Fires after every DELETE on the farmers table
AFTER DELETE ON farmers → logs to trig-- Retrieves all farmer records
CALL proc();Farmer_Management_System/
├── main.py # Flask app — routes, auth, DB logic
├── farmers.sql # Full DB schema: tables, triggers, stored procedure
├── templates/ # Jinja2 HTML templates
│ ├── index.html
│ ├── login.html
│ ├── farmers.html
│ ├── add_farmer.html
│ └── ...
├── static/ # CSS, JS, images
│ ├── style.css
│ └── ...
└── README.md
- Python 3.8+
- MySQL 8.0+
- pip
1. Clone the repository
git clone https://github.com/asthasingh0660/Farmer_Management_System.git
cd Farmer_Management_System2. Install dependencies
pip install flask flask-login flask-sqlalchemy pymysql werkzeug3. Set up the database
Open MySQL and run:
SOURCE farmers.sql;This creates all tables, inserts sample data, and sets up the triggers and stored procedure automatically.
4. Configure the database connection
In main.py, update the connection string to match your MySQL credentials:
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:YOUR_PASSWORD@localhost/farmers_db'5. Run the application
python main.py6. Open in browser
http://localhost:5000
| Concept | Implementation |
|---|---|
| ORM vs Raw SQL | SQLAlchemy ORM for models + raw engine.execute() for triggers/procedures |
| SQL Triggers | Automatic audit trail on all DML operations |
| Stored Procedures | Encapsulated query logic callable via CALL proc() |
| Password Security | Werkzeug generate_password_hash / check_password_hash |
| Session Management | Flask-Login for persistent login state |
| Relational Design | Foreign keys linking farmers → products → farming types |
| ACID Compliance | MySQL InnoDB engine ensures transactional integrity |
- REST API endpoints for mobile integration
- Export farmer data to CSV/Excel
- Role-based access control (Admin vs Viewer)
- Dashboard with charts (crop distribution, product counts)
- Dockerize the application for easy deployment
Astha Singh GitHub
This project is open source and available under the MIT License.