Skip to content

Backend Modules

Each module lives in MedRegia.API/Modules/[ModuleName]/ and follows the same four-layer structure.

Module Layer Pattern

[ModuleName]/
├── Domain/          ← Pure POCO models — no logic, no annotations
│   ├── [Entity].cs
│   └── Enums/[EnumName].cs
├── Data/            ← SQL only — no business logic
│   ├── Interfaces/I[Entity]Repository.cs
│   └── Repositories/[Entity]Repository.cs
├── Business/        ← All business logic lives here
│   ├── DTOs/
│   ├── Interfaces/I[Entity]Service.cs
│   ├── Profiles/[Entity]Profile.cs  (AutoMapper)
│   └── Services/[Entity]Service.cs
└── Controller/      ← HTTP layer — maps DTOs, calls services, returns ActionResults
    └── [Entity]Controller.cs

Identity Module

Route prefix: /api/auth, /api/users, /api/roles, /api/permissions, /api/policies

Handles authentication, user accounts, and the entire RBAC system.

Entities

EntityKey Fields
Userid, firstName, lastName, email, passwordHash, roleId, isActive
Roleid, name, description, isSystem, isActive
Permissionid, collection, action, description
Policyid, name, description, isActive

Controllers

ControllerDescription
AuthControllerPOST /api/auth/login — issues a signed JWT
UsersControllerCRUD for user accounts, GET /api/users/me/permissions
RolesControllerCRUD for roles; system roles cannot be deleted
PermissionsControllerRead-only list of all defined permissions
PoliciesControllerCRUD for policies; assign/remove permissions to a policy

VendorManagement Module

Route prefix: /api/vendors, /api/invoices, /api/transactions

The core business domain — manages the full vendor payment lifecycle.

Entities

EntityKey FieldsComputed Fields
Vendorid, name, address, phone, email, vendorType, drugLicenseNumber1, drugLicenseNumber2, isActiveoutstandingBalance, totalInvoiceValue, totalPaidAmount
Invoiceid, vendorId, invoiceNumber, amount, invoiceDate, dueDate, isActivepaidAmount, pendingAmount, status
Transactionid, invoiceId, amount, transactionDate, transactionType, isActive

Enums

EnumValues
VendorTypeManufacturer, Wholesaler, Agency, Dealer, Pharmacy, OwnPharmacy
InvoiceStatusPartiallyPaid, FullyPaid, Overdue, Canceled (computed, not stored)
TransactionTypeUPI, Cash, NetBanking

Invoice Status Logic

Invoice status is computed in C# — it is never stored in the database:

Canceled    → isActive == false
FullyPaid   → pendingAmount <= 0
Overdue     → dueDate.Date < today
Otherwise   → PartiallyPaid

Controllers

ControllerDescription
VendorsControllerFull CRUD + paginated/filtered list + export
InvoicesControllerFull CRUD + rich filtering (date range, amount range, status, vendor)
TransactionsControllerFull CRUD + filtering by invoice, date range, payment type

Settings Module

Route prefix: /api/settings

Manages application-wide configuration key-value pairs. Settings are pre-seeded — they can only be updated through the API, never created or deleted.

Known Settings

KeyDescription
CurrencyDisplay currency symbol (e.g. , $)

Dashboard Module

Route prefix: /api/dashboard

Read-only aggregate queries that power the dashboard overview cards. Intentionally has no service layer — the controller queries repositories directly (documented exception to the standard pattern for cross-module aggregation).

Endpoints

EndpointDescription
GET /api/dashboard/summaryKPIs: totalVendors, totalInvoices, totalDue, totalPaid, recentTransactions
GET /api/dashboard/top-vendorsTop vendors by outstanding balance
GET /api/dashboard/recent-invoicesMost recent invoices
GET /api/dashboard/monthly-transactionsTransaction amounts grouped by month

Reports Module

Route prefix: /api/reports

Generates downloadable .xlsx Excel files using ClosedXML. No service layer beyond IReportService.

EndpointFile
GET /api/reports/vendorsvendors_YYYYMMDD.xlsx
GET /api/reports/invoicesinvoices_YYYYMMDD.xlsx
GET /api/reports/transactionstransactions_YYYYMMDD.xlsx

Onboarding Module

Route prefix: /api/onboarding

Handles the one-time first-run setup. All endpoints are intentionally public (no [Authorize]) so setup can be completed before any user exists.

EndpointDescription
GET /api/onboarding/statusReturns isOnboarded: true/false
POST /api/onboarding/setupCreates the pharmacy vendor + admin user in one atomic operation

UserProfile Module

Route prefix: /api/profile

Allows authenticated users to view and update their own profile and change their password. No admin permission required — users always have access to their own profile.

MedRegia — Pharmaceutical Vendor Management Platform