FarmConnect is a comprehensive livestock management platform that simplifies farm operations for owners and suppliers. This REST API backend provides secure, role-based access to manage livestock health, medicine and feed inventory, resource requests, and feedback systems.
- JWT-based authentication with secure token management
- Role-based access control (Owner/Supplier roles)
- ASP.NET Core Identity integration
- Protected API endpoints
- Livestock Management: Track and manage livestock records (Owner role)
- Medicine Management: Create, edit, and manage medicine inventory (Supplier role)
- Feed Management: Handle feed products and inventory tracking (Supplier role)
- Request System: Submit and manage resource requests between roles
- Feedback System: Customer feedback and supplier response management
- Framework: ASP.NET Core 8.0
- Database: SQL Server 2022 / Azure SQL Database
- ORM: Entity Framework Core 8.0
- Authentication: ASP.NET Core Identity + JWT Bearer Tokens
- User Management: ASP.NET Identity
- API Documentation: Swagger/OpenAPI
- Architecture: RESTful API with Repository pattern
├── Controllers/ # API Controllers
│ ├── AuthenticationController.cs
│ ├── FeedbackController.cs
│ ├── FeedController.cs
│ ├── LivestockController.cs
│ ├── MedicineController.cs
│ └── RequestController.cs
├── Data/ # Database Context
│ └── ApplicationDbContext.cs
├── Models/ # Entity Models
│ ├── ApplicationUser.cs # ASP.NET Identity User Model
│ ├── User.cs # Frontend-compatible User Model
│ ├── Feed.cs
│ ├── Feedback.cs
│ ├── Livestock.cs
│ ├── Medicine.cs
│ ├── Request.cs
│ ├── LoginModel.cs
│ └── UserRoles.cs
├── Services/ # Business Logic Layer
├── Migrations/ # EF Core Migrations
└── Properties/ # Launch Settings
- .NET 8 SDK
- SQL Server 2022 (or SQL Server Express)
- Entity Framework Core Tools
git clone https://github.com/ChhatreshKhatri/FarmConnect-WebApi.git
cd FarmConnect-WebApidotnet restore
dotnet tool restoreUpdate the connection string in appsettings.json based on your database choice:
For Local SQL Server:
{
"ConnectionStrings": {
"ConStr": "Your-Local-SQL-Server-Connection-String"
}
}For Azure SQL Database:
{
"ConnectionStrings": {
"AzureSQL": "Your-Azure-SQL-Connection-String"
}
}Note: The application uses the
AzureSQLconnection string by default. If you want to use local SQL Server, updateProgram.csto useConStrinstead.
dotnet ef migrations add InitialCreate
dotnet ef database updatedotnet build
dotnet run- Swagger UI: Navigate to
http://localhost:8080/swagger - API Base URL:
http://localhost:8080
Configure JWT authentication in appsettings.json:
{
"Jwt": {
"Key": "your-secret-key",
"Issuer": "localhost"
}
}The application supports two user roles managed through ASP.NET Identity:
- Owner: Can manage livestock, view medicines/feeds, submit requests
- Supplier: Can manage medicine/feed inventory, handle requests
- AspNetUsers: Primary user table
- AspNetRoles: Role definitions (Owner, Supplier)
- AspNetUserRoles: User-role assignments
- Entity Tables: All entities reference AspNetUsers.Id as foreign key
POST /api/register- User registrationPOST /api/login- User login (returns JWT)
GET /api/livestock- Get all livestockGET /api/livestock/user/{userId}- Get livestock by user IDPOST /api/livestock- Create new livestock recordPUT /api/livestock/{id}- Update livestock recordDELETE /api/livestock/{id}- Delete livestock record
GET /api/medicine- Get all medicinesGET /api/medicine/user/{userId}- Get medicines by user IDPOST /api/medicine- Create new medicine (Supplier)PUT /api/medicine/{id}- Update medicine (Supplier)DELETE /api/medicine/{id}- Delete medicine (Supplier)
GET /api/feed- Get all feedsGET /api/feed/user/{userId}- Get feeds by user IDPOST /api/feed- Create new feed (Supplier)PUT /api/feed/{id}- Update feed (Supplier)DELETE /api/feed/{id}- Delete feed (Supplier)
GET /api/request- Get requestsGET /api/request/user/{userId}- Get requests by user IDPOST /api/request- Submit new requestPUT /api/request/{id}- Update request status
GET /api/feedback- Get feedbackGET /api/feedback/user/{userId}- Get feedback by user IDPOST /api/feedback- Submit feedbackDELETE /api/feedback/{id}- Delete feedback
This API powers the FarmConnect Next.js frontend application.
Frontend Repository: FarmConnect-Next.jsApp