# মডেল স্কিমা গাইড

এই file-e backend-er sob important schema ke khub sohoj Bangla vabe bojhano hoyeche.
Kon schema ki rakhe, kontar sathe connect kore, ar kivabe kaj kore - shob ek jaygay.

## ১) common helper

### `tenant.plugin.js`
- Ei helper sob tenant-aware model-e `tenantId` add kore.
- SaaS system-e ek company-r data onno company theke alada rakhar jonno eta use hoy.
- Mane same software-e onek company thakleo data mix hoy na.

### `softDelete.plugin.js`
- Ei helper `isDeleted` ar `deletedAt` add kore.
- Data permanent delete na kore chhupiye rakhe.
- Pore chaile abar show kora jete pare.

## ২) `Tenant.model.js`

### ki rakhe
- Company ba workspace er basic info.
- Example: company name, slug, status, timezone, currency.

### kar sathe connect
- `User.model.js`-e `ownerUserId` diye connect hoy.
- almost sob business model-e `tenantId` diye connect hoy.

### kivabe kaj kore
- Prottek company-r alada tenant thake.
- Jekono data-r sathe `tenantId` thakle bojha jay seta konta company-r.

## ৩) `User.model.js`

### ki rakhe
- Login user er info.
- Example: name, email, passwordHash, role, active status.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `Department.model.js` er sathe `departmentId`.
- `Employee.model.js` er sathe `userId`.

### kivabe kaj kore
- Eta login ar role control er main schema.
- User ke tenant er sathe bind kore rakhe.

## ৪) `Department.model.js`

### ki rakhe
- Department er list.
- Example: HR, Engineering, Sales.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `User.model.js` er sathe `managerUserId`.
- `Employee.model.js` er sathe `departmentId`.

### kivabe kaj kore
- Ek company-r vitore alada alada department rakhe.
- Manager ar employee department-wise organize thake.

## ৫) `Employee.model.js`

### ki rakhe
- Employee-r profile ar job details.
- Example: employee code, designation, join date, salary, status.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `User.model.js` er sathe `userId`.
- `Department.model.js` er sathe `departmentId`.
- `User.model.js` er sathe `managerUserId`.

### kon kon model-er sathe kaaj kore
- `Attendance.model.js`
- `LeaveRequest.model.js`
- `PayrollRecord.model.js`
- `LoanRequest.model.js`
- `AssetAssignment.model.js`
- `PerformanceReview.model.js`

### kivabe kaj kore
- Eta employee-r main master record.
- Onno almost shob HR module ei employee ke reference kore.

## ৬) `Attendance.model.js`

### ki rakhe
- Daily হাজিরার record.
- Example: present, absent, check-in, check-out, overtime.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `Employee.model.js` er sathe `employeeId`.

### kivabe kaj kore
- Ek employee-r ek diner hajira ekta record hisebe save hoy.
- Same employee-r onek diner record alada alada thake.

## ৭) `LeavePolicy.model.js`

### ki rakhe
- Leave-r niom ar quota.
- Example: annual quota, carry forward, paid/unpaid.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.

### kivabe kaj kore
- Ei policy diye employee-r leave count hoy.
- Leave application er somoy ei rule follow kora hoy.

## ৮) `LeaveRequest.model.js`

### ki rakhe
- Employee leave application.
- Example: start date, end date, reason, status.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `Employee.model.js` er sathe `employeeId`.
- `LeavePolicy.model.js` er sathe `leavePolicyId`.
- `User.model.js` er sathe `reviewedBy`.

### kivabe kaj kore
- Employee leave apply kore.
- HR ba manager approve/reject kore.
- Policy theke quota check hoy.

## ৯) `PayrollCycle.model.js`

### ki rakhe
- Payroll er period.
- Example: month, year, startDate, endDate, status.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `User.model.js` er sathe `processedBy`.

### kivabe kaj kore
- Ek month-er payroll ke ekta cycle hisebe dhore rakhe.
- Poroborti-te oi cycle-er vitore salary record save hoy.

## ১০) `PayrollRecord.model.js`

### ki rakhe
- Employee salary calculation er final result.
- Example: gross salary, deductions, tax, net salary, payment status.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `PayrollCycle.model.js` er sathe `payrollCycleId`.
- `Employee.model.js` er sathe `employeeId`.

### kivabe kaj kore
- Prottek payroll cycle-e prottek employee-r alada salary record thake.
- Salary paid na pending seta bujha jay.

## ১১) `ApprovalRequest.model.js`

### ki rakhe
- Approval workflow er record.
- Example: type, subject, status, steps, urgency.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `User.model.js` er sathe `requestedBy` ar `approverUserId`.
- `Department.model.js` er sathe `departmentId`.

### kon kon module-er sathe kaj kore
- `LeaveRequest`
- `LoanRequest`
- `Asset`
- `Recruitment`

### kivabe kaj kore
- Ek request ekadhik level-e approve hote pare.
- Example: Dept Head -> HR Manager -> Management.

## ১২) `JobOpening.model.js`

### ki rakhe
- Recruitment job post.
- Example: title, department, openings, status.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `Department.model.js` er sathe `departmentId`.

### kivabe kaj kore
- Kon department-e konta recruit hocche seta dekha jay.
- Candidate ei job opening-er under-e apply kore.

## ১৩) `Candidate.model.js`

### ki rakhe
- Job applicant er info.
- Example: name, email, stage, score, resume URL.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `JobOpening.model.js` er sathe `jobOpeningId`.

### kivabe kaj kore
- Kon candidate kon job-e apply korse seta track kore.
- Screening, interview, offer, hired stage change hoy.

## ১৪) `PerformanceReview.model.js`

### ki rakhe
- Employee performance review.
- Example: rating, strengths, improvements, goals.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `Employee.model.js` er sathe `employeeId`.
- `User.model.js` er sathe `reviewerUserId`.

### kivabe kaj kore
- Reviewer employee-r kaj evaluate kore.
- Future promotion ba feedback er jonno use hoy.

## ১৫) `LoanRequest.model.js`

### ki rakhe
- Employee loan application.
- Example: amount, tenure months, monthly deduction, status.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `Employee.model.js` er sathe `employeeId`.
- `User.model.js` er sathe `approvedBy`.

### kivabe kaj kore
- Employee loan apply kore.
- Finance ba management approve kore.
- Salary theke monthly deduction hoy.

## ১৬) `Asset.model.js`

### ki rakhe
- Company asset inventory.
- Example: laptop, monitor, chair, phone.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `AssetAssignment.model.js` er sathe assignment connect hoy.

### kivabe kaj kore
- Kon asset available, assigned, maintenance, retired seta track kore.
- SaaS system-e tenantId chara eta safe na.

## ১৭) `AssetAssignment.model.js`

### ki rakhe
- Kon employee kon asset peyeche seta.
- Example: assignedAt, expectedReturnAt, returnedAt, status.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `Asset.model.js` er sathe `assetId`.
- `Employee.model.js` er sathe `employeeId`.

### kivabe kaj kore
- Asset employee ke dile assignment record hoy.
- Pore return korle status change hoy.

## ১৮) `Announcement.model.js`

### ki rakhe
- Company notice ba announcement.
- Example: title, body, audience, publishAt.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `Department.model.js` er sathe `departmentId`.
- `User.model.js` er sathe `createdBy`.

### kivabe kaj kore
- All staff, specific department, ba specific role-ke notice pathano jay.

## ১৯) `Subscription.model.js`

### ki rakhe
- SaaS subscription information.
- Example: planCode, billingInterval, amount, status.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `Plan.model.js` er data follow kore.
- Payment transaction er sathe update hoy.

### kivabe kaj kore
- Tenant kon plan-e ache seta rakhe.
- Free, weekly, monthly, yearly plan manage kore.

## ২০) `Plan.model.js`

### ki rakhe
- Available SaaS plan list.
- Example: free, weekly, monthly, yearly.

### kar sathe connect
- Direct vabe `Subscription.model.js` er `planCode` er sathe related.

### kivabe kaj kore
- Frontend e plan list dekhay.
- User plan select kore payment e jay.

## ২১) `PaymentTransaction.model.js`

### ki rakhe
- Payment transaction er sob record.
- Example: trxId, amount, gateway, status, raw response.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `Subscription.model.js` er sathe `subscriptionId`.
- `Plan.model.js` er sathe `planCode`.

### kivabe kaj kore
- SSLCommerz payment success, fail, cancel, IPN track kore.
- Payment proof hisebe kaj kore.

## ২২) `Invoice.model.js`

### ki rakhe
- Billing invoice.
- Example: invoice number, amount due, amount paid, due date, status.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `Subscription.model.js` er sathe `subscriptionId`.

### kivabe kaj kore
- Monthly ba yearly billing invoice maintain kore.
- Paid ba overdue status dekha jay.

## ২৩) `ReportJob.model.js`

### ki rakhe
- Report generate howar request.
- Example: reportType, filters, format, status, outputUrl.

### kar sathe connect
- `Tenant.model.js` er sathe `tenantId`.
- `User.model.js` er sathe `requestedBy`.

### kivabe kaj kore
- Report run hole queue, running, completed status rakhe.
- Pore download URL store kora hoy.

## ২৪) chhoto connection summary

### Tenant connection
- Almost sob business model-e `tenantId` ache.
- Eta SaaS separation er main base.

### User connection
- Login, approve, create, review, process er jonne user use hoy.
- `requestedBy`, `reviewedBy`, `processedBy`, `ownerUserId` e user reference thake.

### Employee connection
- Attendance, leave, payroll, loan, asset, performance er central model.
- Ek employee-r sathe onek related record thakte pare.

### Department connection
- Employee, manager, job opening, announcement-er sathe department connect hoy.

### Payment connection
- Plan -> Subscription -> PaymentTransaction -> Invoice
- Eta SaaS billing flow.

## ২৫) flow example

### Example 1: employee leave
1. Employee login kore.
2. LeaveRequest create hoy.
3. LeavePolicy diye quota check hoy.
4. ApprovalRequest diye manager approve kore.
5. Final status save hoy.

### Example 2: asset assign
1. Asset create hoy.
2. Employee ke assign kora hoy.
3. AssetAssignment record save hoy.
4. Return hole status update hoy.

### Example 3: paid plan
1. Tenant plan select kore.
2. Subscription create hoy.
3. SSLCommerz payment transaction save hoy.
4. Success hole subscription active hoy.
5. Invoice update hoy.

---
Ei file dekhe sohoje bujha jabe konta kontar sathe connect, ar konta kivabe kaj kore.
Jodi chao, ami ei file-er shuru-te aro chhoto ekta summary add kore dite pari.
