π Table of Contents
1. System Overview
What is Enkage?
Enkage is a modern, scalable backend API system built with Node.js and Express, designed for knowledge management systems similar to KKMA (Kuwait Kerala Muslim Association). It provides comprehensive management of members, organizations, committees, transactions, and multi-layered authentication.
Tech Stack
π Backend
Node.js + Express
ποΈ Database
PostgreSQL
π Auth
JWT + 2FA
π Validation
Joi
π Files
Multer
π Security
Helmet + CORS
π Logging
Winston
βοΈ Deployment
PM2
Key Features
- β Multi-Layer Authentication: Separate auth for Admin, Committee, and StarClub members
- β Role-Based Access Control: Dynamic permissions based on user roles and positions
- β Hierarchical Organization: 3-layer organizational structure (Center, Zone, Branch)
- β Committee Management: Positions, departments, and delegation support
- β Member Management: Registration, renewal, family members, and referrals
- β Transaction Processing: Payments, refunds, and comprehensive tracking
- β Form Approvals: Multi-level approval workflows
- β File Uploads: Secure file management with folder structure
2. System Architecture
graph TB
Client[Client Application] -->|HTTP/HTTPS| Server[Express Server]
Server --> Middleware[Middleware Layer]
Middleware --> Auth[Authentication]
Middleware --> Validation[Validation]
Middleware --> RateLimit[Rate Limiting]
Middleware --> Security[Security]
Server --> Routes[Routes Layer]
Routes --> Controllers[Controllers]
Controllers --> Services[Services Layer]
Services --> Models[Models]
Models --> ORM[Sequelize ORM]
ORM --> Database[(PostgreSQL Database)]
Services --> Utils[Utilities]
Utils --> Logger[Winston Logger]
Utils --> FileUpload[File Upload]
Utils --> Email[Nodemailer]
Database --> Tables[Tables]
Tables --> Members[Members]
Tables --> Users[Users]
Tables --> Committees[Committees]
Tables --> Transactions[Transactions]
Tables --> Organisations[Organizations]
style Client fill:#667eea,stroke:#333,stroke-width:2px,color:#fff
style Server fill:#764ba2,stroke:#333,stroke-width:2px,color:#fff
style Database fill:#28a745,stroke:#333,stroke-width:2px,color:#fff
style Auth fill:#ffc107,stroke:#333,stroke-width:2px,color:#333
Module Structure
The project follows a modular architecture where each feature is self-contained:
src/modules/
βββ auth/ # User authentication
βββ members/ # Member management
βββ committees/ # Committee management
βββ committeeMembers/ # Committee member assignments
βββ organizations/ # Organization structure
βββ organizationUnits/ # Layer hierarchy
βββ organizationSettings/ # Configuration
βββ transactions/ # Payment processing
βββ formApprovals/ # Approval workflows
βββ fileUpload/ # File management
βββ locations/ # Location data
βββ mixedauth/ # Multi-layer authentication
3. Authentication System Overview
graph TD
Start([User Requests Access]) --> CheckType{What User Type?}
CheckType -->|Admin/Staff| AdminAuth[Admin Authentication]
CheckType -->|Committee Member| CommitteeAuth[Committee Auth]
CheckType -->|StarClub Member| StarClubAuth[StarClub Auth]
AdminAuth --> AdminTable[Query Users Table]
AdminTable --> AdminCheck{Valid
Credentials?} AdminCheck -->|No| AdminError[Login Error] AdminCheck -->|Yes| AdminToken[Generate JWT Token] CommitteeAuth --> FindMember1[Find Member by ID/Email/Civil ID] FindMember1 --> CheckCommittee{Is Committee
Member?} CheckCommittee -->|No| CommitteeError[Not Eligible] CheckCommittee -->|Yes| AuthCheck1{2FA Status?} StarClubAuth --> FindMember2[Find Member by ID/Email/Civil ID] FindMember2 --> CheckReferrer{Has Referred
Members?} CheckReferrer -->|No| StarClubError[Not Eligible] CheckReferrer -->|Yes| AuthCheck2{2FA Status?} AuthCheck1 -->|Pending| Onetime1[Use Onetime Password] AuthCheck1 -->|Active| TOTP1[Use TOTP Code] AuthCheck2 -->|Pending| Onetime2[Use Onetime Password] AuthCheck2 -->|Active| TOTP2[Use TOTP Code] Onetime1 --> Setup2FA1[Setup 2FA with QR Code] Onetime2 --> Setup2FA2[Setup 2FA with QR Code] TOTP1 --> Verify1[Verify TOTP] TOTP2 --> Verify2[Verify TOTP] Verify1 --> LoadPerms1[Load Position Permissions] Verify2 --> DefaultPerms[Load Default Permissions] LoadPerms1 --> MemberToken1[Generate JWT with Committee Data] DefaultPerms --> MemberToken2[Generate JWT] AdminToken --> AdminAccess[Full System Access] MemberToken1 --> CommitteeAccess[Committee Portal Access] MemberToken2 --> StarClubAccess[StarClub Portal Access] style AdminAuth fill:#dc3545,stroke:#333,stroke-width:2px,color:#fff style CommitteeAuth fill:#28a745,stroke:#333,stroke-width:2px,color:#fff style StarClubAuth fill:#ffc107,stroke:#333,stroke-width:2px,color:#333 style AdminAccess fill:#667eea,stroke:#333,stroke-width:3px,color:#fff style CommitteeAccess fill:#28a745,stroke:#333,stroke-width:3px,color:#fff style StarClubAccess fill:#ffc107,stroke:#333,stroke-width:3px,color:#333
Credentials?} AdminCheck -->|No| AdminError[Login Error] AdminCheck -->|Yes| AdminToken[Generate JWT Token] CommitteeAuth --> FindMember1[Find Member by ID/Email/Civil ID] FindMember1 --> CheckCommittee{Is Committee
Member?} CheckCommittee -->|No| CommitteeError[Not Eligible] CheckCommittee -->|Yes| AuthCheck1{2FA Status?} StarClubAuth --> FindMember2[Find Member by ID/Email/Civil ID] FindMember2 --> CheckReferrer{Has Referred
Members?} CheckReferrer -->|No| StarClubError[Not Eligible] CheckReferrer -->|Yes| AuthCheck2{2FA Status?} AuthCheck1 -->|Pending| Onetime1[Use Onetime Password] AuthCheck1 -->|Active| TOTP1[Use TOTP Code] AuthCheck2 -->|Pending| Onetime2[Use Onetime Password] AuthCheck2 -->|Active| TOTP2[Use TOTP Code] Onetime1 --> Setup2FA1[Setup 2FA with QR Code] Onetime2 --> Setup2FA2[Setup 2FA with QR Code] TOTP1 --> Verify1[Verify TOTP] TOTP2 --> Verify2[Verify TOTP] Verify1 --> LoadPerms1[Load Position Permissions] Verify2 --> DefaultPerms[Load Default Permissions] LoadPerms1 --> MemberToken1[Generate JWT with Committee Data] DefaultPerms --> MemberToken2[Generate JWT] AdminToken --> AdminAccess[Full System Access] MemberToken1 --> CommitteeAccess[Committee Portal Access] MemberToken2 --> StarClubAccess[StarClub Portal Access] style AdminAuth fill:#dc3545,stroke:#333,stroke-width:2px,color:#fff style CommitteeAuth fill:#28a745,stroke:#333,stroke-width:2px,color:#fff style StarClubAuth fill:#ffc107,stroke:#333,stroke-width:2px,color:#333 style AdminAccess fill:#667eea,stroke:#333,stroke-width:3px,color:#fff style CommitteeAccess fill:#28a745,stroke:#333,stroke-width:3px,color:#fff style StarClubAccess fill:#ffc107,stroke:#333,stroke-width:3px,color:#333
4. SuperAdmin FlowAdmin
Authentication Flow
graph LR
A[Admin Login Page] -->|Username/Email + Password| B[POST /api/v1/mixed-auth/admin-login]
B --> C{Validate Credentials}
C -->|Invalid| D[Return 401 Error]
C -->|Valid| E[Update Last Login]
E --> F[Generate JWT Token]
F --> G[Return Token + Full Permissions]
G --> H[Access All Modules]
H --> I[Member Management]
H --> J[Committee Management]
H --> K[Organization Management]
H --> L[Transaction Management]
H --> M[User Management]
H --> N[Settings Management]
style A fill:#dc3545,stroke:#333,stroke-width:2px,color:#fff
style G fill:#28a745,stroke:#333,stroke-width:2px,color:#fff
style H fill:#667eea,stroke:#333,stroke-width:3px,color:#fff
Key Features & Permissions
Full System Access
- β Manage all users in the system
- β Create, edit, and delete all members
- β Manage committee structures and assignments
- β Configure organization hierarchy and settings
- β View and manage all transactions
- β Generate onetime passwords for members
- β Reset 2FA for any member
- β Export reports and data
- β System configuration and settings
Common Admin Workflows
graph TD
Login[Admin Logs In] --> Dashboard[Admin Dashboard]
Dashboard --> SetupMember[Setup New Member]
SetupMember --> CreateMember[Create Member Record]
CreateMember --> GenerateOTP[Generate Onetime Password]
GenerateOTP --> NotifyMember[Notify Member]
Dashboard --> ManageCommittee[Manage Committees]
ManageCommittee --> CreateCommittee[Create Committee]
CreateCommittee --> AssignMembers[Assign Committee Members]
AssignMembers --> SetPositions[Assign Positions]
Dashboard --> ApproveForm[Approve Forms]
ApproveForm --> ViewForm[View Form Details]
ViewForm --> ReviewData[Review Submitted Data]
ReviewData --> Decision{Approve/Reject?}
Decision -->|Approve| UpdateStatus[Update Status]
Decision -->|Reject| SendFeedback[Send Feedback]
Dashboard --> ViewReports[View Reports]
ViewReports --> FilterData[Filter by Date/Range]
FilterData --> ExportData[Export to Excel]
style Login fill:#dc3545,stroke:#333,stroke-width:2px,color:#fff
style Dashboard fill:#667eea,stroke:#333,stroke-width:2px,color:#fff
style ApproveForm fill:#28a745,stroke:#333,stroke-width:2px,color:#fff
Admin API Endpoints
POST /api/v1/mixed-auth/admin-login- Admin loginGET /api/v1/members- List all membersPOST /api/v1/members- Create new memberPUT /api/v1/members/:id- Update memberPOST /api/v1/committees- Create committeePOST /api/v1/mixed-auth/admin/generate-onetime-password- Generate OTPPOST /api/v1/mixed-auth/admin/reset-2fa- Reset member 2FAGET /api/v1/transactions/transaction-table- View all transactionsGET /api/v1/form-approvals- View pending approvals
5. Committee Member FlowCommittee
Authentication Flow
graph LR
A[Committee Login Page] -->|Civil ID/Email/Member ID| B[POST /api/v1/mixed-auth/member-login]
B --> C{Member Exists?}
C -->|No| D[Return 404]
C -->|Yes| E{Is Committee Member?}
E -->|No| F[Return 403 Not Eligible]
E -->|Yes| G{2FA Status?}
G -->|Pending| H[Enter Onetime Password]
G -->|Active| I[Enter TOTP Code]
H --> J{Correct OTP?}
J -->|No| K[Return 401 Error]
J -->|Yes| L[Generate QR Code]
L --> M[Complete 2FA Setup]
M --> N[Enter TOTP to Verify]
I --> O{Valid TOTP?}
N --> O
O -->|No| K
O -->|Yes| P[Load Committee Data]
P --> Q[Get Position & Permissions]
Q --> R[Generate JWT with Committee Info]
R --> S[Return Token + Committee Access]
S --> T[Committee Portal Access]
T --> U[View Assigned Forms]
T --> V[Approve/Reject Forms]
T --> W[Manage Committee Tasks]
style A fill:#28a745,stroke:#333,stroke-width:2px,color:#fff
style E fill:#ffc107,stroke:#333,stroke-width:2px,color:#333
style S fill:#28a745,stroke:#333,stroke-width:2px,color:#fff
style T fill:#667eea,stroke:#333,stroke-width:3px,color:#fff
Committee Member Features
Based on Position Permissions
- β View committee-specific reports and data
- β Manage assigned committee members (if permitted)
- β Approve/Reject transactions based on position
- β View and manage assigned cases/forms
- β Access layer-specific data based on committee assignment
- β Department-specific access if assigned
Committee Member Workflows
graph TD
Login[Committee Member Login] --> CheckAuth{First Time?}
CheckAuth -->|Yes| Setup2FA[Setup 2FA]
CheckAuth -->|No| EnterTOTP[Enter TOTP]
Setup2FA --> ShowQR[Show QR Code]
ShowQR --> ScanQR[Scan with Google Authenticator]
ScanQR --> VerifyCode[Verify with TOTP]
EnterTOTP --> VerifyCode
VerifyCode --> Portal[Committee Portal]
Portal --> ViewDashboard[Dashboard]
ViewDashboard --> ShowPending[Pending Approvals]
ViewDashboard --> ShowAssigned[Assigned Tasks]
ShowPending --> SelectForm[Select Form]
SelectForm --> ReviewDetails[Review Details]
ReviewDetails --> CheckPermissions{Has Permission?}
CheckPermissions -->|No| DenyAccess[Access Denied]
CheckPermissions -->|Yes| MakeDecision{Approve/Reject}
MakeDecision -->|Approve| UpdateForm[Mark as Approved]
MakeDecision -->|Reject| AddComments[Add Rejection Comments]
AddComments --> UpdateForm
UpdateForm --> NotifyNext[Notify Next Approver]
UpdateForm --> NotifyMember[Notify Member]
Portal --> ViewReports[View Reports]
ViewReports --> FilterByDept[Filter by Department]
ViewReports --> FilterByLayer[Filter by Layer]
Portal --> ManageDelegation[Manage Delegation]
ManageDelegation --> AssignDelegate[Assign Delegate]
style Login fill:#28a745,stroke:#333,stroke-width:2px,color:#fff
style Portal fill:#667eea,stroke:#333,stroke-width:3px,color:#fff
style MakeDecision fill:#ffc107,stroke:#333,stroke-width:2px,color:#333
Committee Member API Endpoints
POST /api/v1/mixed-auth/member-login- Committee loginPOST /api/v1/mixed-auth/complete-2fa-setup- Setup 2FAGET /api/v1/form-approvals- View assigned formsPUT /api/v1/form-approvals/:id/approve- Approve formPUT /api/v1/form-approvals/:id/reject- Reject formGET /api/v1/committees/:id/members- View committee membersGET /api/v1/transactions- View transactions (filtered by permissions)
6. StarClub Member FlowStarClub
Authentication Flow
graph LR
A[StarClub Login Page] -->|Civil ID/Email/Member ID| B[POST /api/v1/mixed-auth/member-login]
B --> C{Member Exists?}
C -->|No| D[Return 404]
C -->|Yes| E{Has Referred Members?}
E -->|No| F[Return 403 Not Eligible]
E -->|Yes| G{2FA Status?}
G -->|Pending| H[Enter Onetime Password]
G -->|Active| I[Enter TOTP Code]
H --> J{Correct OTP?}
J -->|No| K[Return 401 Error]
J -->|Yes| L[Generate QR Code]
L --> M[Complete 2FA Setup]
M --> N[Enter TOTP to Verify]
I --> O{Valid TOTP?}
N --> O
O -->|No| K
O -->|Yes| P[Generate JWT Token]
P --> S[Return Token + StarClub Access]
S --> T[StarClub Portal Access]
T --> U[View Referral Network]
T --> V[View Referral Statistics]
T --> W[Manage Referred Members]
T --> X[View Referral Reports]
style A fill:#ffc107,stroke:#333,stroke-width:2px,color:#333
style E fill:#dc3545,stroke:#333,stroke-width:2px,color:#fff
style S fill:#ffc107,stroke:#333,stroke-width:2px,color:#333
style T fill:#667eea,stroke:#333,stroke-width:3px,color:#fff
StarClub Member Features
Referral-Based Access
- β View complete referral network tree
- β View referral statistics and analytics
- β Track referred members' status
- β Access referral-based reports
- β View income/benefits from referrals
- β Manage and contact referred members
StarClub Member Workflows
graph TD
Login[StarClub Login] --> CheckAuth{First Time?}
CheckAuth -->|Yes| Setup2FA[Setup 2FA]
CheckAuth -->|No| EnterTOTP[Enter TOTP]
Setup2FA --> ShowQR[Show QR Code]
ShowQR --> ScanQR[Scan with Google Authenticator]
ScanQR --> VerifyCode[Verify with TOTP]
EnterTOTP --> VerifyCode
VerifyCode --> Portal[StarClub Portal]
Portal --> Dashboard[Dashboard]
Dashboard --> ShowStats[Referral Statistics]
Dashboard --> ShowNetwork[Referral Network]
ShowStats --> DisplayTotal[Total Referrals]
DisplayTotal --> DisplayActive[Active Referrals]
DisplayActive --> DisplayBenefits[Earned Benefits]
ShowNetwork --> LoadNetwork[Load Network Tree]
LoadNetwork --> ShowDirect[Direct Referrals]
ShowDirect --> ShowIndirect[Indirect Referrals]
Portal --> ViewMembers[View Referred Members]
ViewMembers --> FilterStatus[Filter by Status]
FilterStatus --> ViewDetails[View Member Details]
ViewDetails --> ContactMember[Contact Member]
Portal --> ViewReports[Referral Reports]
ViewReports --> SelectPeriod[Select Time Period]
SelectPeriod --> GenerateReport[Generate Report]
GenerateReport --> ExportReport[Export Report]
Portal --> ViewTransactions[Related Transactions]
ViewTransactions --> FilterByRef[Filter by Referral]
FilterByRef --> ViewDetails[View Transaction Details]
style Login fill:#ffc107,stroke:#333,stroke-width:2px,color:#333
style Portal fill:#667eea,stroke:#333,stroke-width:3px,color:#fff
style Dashboard fill:#764ba2,stroke:#333,stroke-width:2px,color:#fff
StarClub Member API Endpoints
POST /api/v1/mixed-auth/member-login- StarClub loginPOST /api/v1/mixed-auth/complete-2fa-setup- Setup 2FAGET /api/v1/members/referred-by/:memberId- View referralsGET /api/v1/members/referral-stats/:memberId- Referral statisticsGET /api/v1/members/referral-network/:memberId- Network treeGET /api/v1/transactions/member/:memberId- Related transactions
7. Module Overview
Core Modules Flow
flowchart TB
subgraph AUTH["Authentication Module"]
A1[Mixed Auth]
A2[Admin Auth]
A3[2FA Setup]
A4[JWT Generation]
end
subgraph MEMBERS["Members Module"]
M1[Register Member]
M2[Update Member]
M3[Member Renewal]
M4[Family Members]
M5[Referral Management]
end
subgraph COMMITTEES["Committees Module"]
C1[Create Committee]
C2[Assign Members]
C3[Position Management]
C4[Department Assignment]
C5[Delegation]
end
subgraph TRANSACTIONS["Transactions Module"]
T1[Create Transaction]
T2[Process Payment]
T3[Process Refund]
T4[Status Update]
T5[Payment History]
end
subgraph FORMS["Form Approvals Module"]
F1[Submit Form]
F2[Approval Flow]
F3[Multi-Level Review]
F4[Status Tracking]
end
subgraph ORGANIZATIONS["Organizations Module"]
O1[Layer Hierarchy]
O2[Department Management]
O3[Position Management]
O4[Settings]
end
subgraph REPORTS["Reports Module"]
R1[Transaction Reports]
R2[Member Reports]
R3[Committee Reports]
R4[Financial Reports]
R5[Export to Excel]
end
Client[Client Applications] --> A1
A1 --> M1
A1 --> C1
A1 --> T1
A1 --> F1
M1 --> T1
M1 -.->|Referrals| M1
C1 --> F1
C1 --> R1
O1 --> C1
O1 --> M1
T1 --> R1
M1 --> R1
classDef authModule fill:#dc3545,stroke:#333,stroke-width:2px,color:#fff
classDef membersModule fill:#28a745,stroke:#333,stroke-width:2px,color:#fff
classDef committeesModule fill:#667eea,stroke:#333,stroke-width:2px,color:#fff
classDef transactionsModule fill:#ffc107,stroke:#333,stroke-width:2px,color:#333
classDef formsModule fill:#764ba2,stroke:#333,stroke-width:2px,color:#fff
classDef orgModule fill:#17a2b8,stroke:#333,stroke-width:2px,color:#fff
classDef reportsModule fill:#e83e8c,stroke:#333,stroke-width:2px,color:#fff
class A1,A2,A3,A4 authModule
class M1,M2,M3,M4,M5 membersModule
class C1,C2,C3,C4,C5 committeesModule
class T1,T2,T3,T4,T5 transactionsModule
class F1,F2,F3,F4 formsModule
class O1,O2,O3,O4 orgModule
class R1,R2,R3,R4,R5 reportsModule
Module Description
| Module | Purpose | Key Features |
|---|---|---|
| auth | User authentication | JWT tokens, password management, user CRUD |
| mixedauth | Multi-layer authentication | Admin, Committee, StarClub login with 2FA |
| members | Member management | Registration, renewal, family, referrals, profiles |
| committees | Committee structure | Create committees, assign members, define hierarchy |
| committeeMembers | Committee membership | Assign positions, departments, delegation |
| transactions | Payment processing | Create, pay, refund, track payment history |
| formApprovals | Approval workflows | Submit, review, approve/reject forms |
| organizations | Organization structure | Manage organization hierarchy |
| organizationUnits | Layer management | Center, Zone, Branch hierarchy |
| fileUpload | File management | Upload, organize, secure file storage |
| locations | Location data | Countries, states, districts, cities |
| reports (Integrated) | Reporting & Analytics | Transaction, member, committee reports with Excel export |
8. Data Filtering & Access Control by User Type
How Filtering Works
Three-Tier Access Control System
The system implements role-based filtering at multiple levels:
- User Type Level: Admin sees all, Committee/StarClub see filtered data
- Permission Level: Position-based permissions for committee members
- Hierarchy Level: Organization layer (Center, Zone, Branch) filtering
- Department Level: Department-specific access for committee members
SuperAdmin Filtering
graph LR
AdminLogin[Admin Login] --> AllAccess[Full System Access]
AllAccess --> NoFilter[No Automatic Filters]
NoFilter --> ManualFilter[Manual Filters Available]
ManualFilter --> ByDate[Filter by Date Range]
ManualFilter --> ByMember[Filter by Member]
ManualFilter --> ByType[Filter by Type]
ManualFilter --> ByStatus[Filter by Status]
ManualFilter --> ByOrg[Filter by Organization]
ManualFilter --> ByLayer[Filter by Layer]
ByDate --> ExportAll[Export All Data]
ByMember --> ExportAll
ByType --> ExportAll
ByStatus --> ExportAll
ByOrg --> ExportAll
ByLayer --> ExportAll
style AdminLogin fill:#dc3545,stroke:#333,stroke-width:2px,color:#fff
style AllAccess fill:#28a745,stroke:#333,stroke-width:3px,color:#fff
style NoFilter fill:#ffc107,stroke:#333,stroke-width:2px,color:#333
| Data Type | Admin Access | Automatic Filters | Can View |
|---|---|---|---|
| Members | β Full Access | β None - See All | All members across all organizations, layers, and departments |
| Transactions | β Full Access | β None - See All | All transactions, payments, refunds regardless of organization/layer |
| Committees | β Full Access | β None - See All | All committees, positions, and assignments |
| Forms | β Full Access | β None - See All | All submitted and pending approval forms |
| Reports | β Full Access | β None - Generate All | All organizational, financial, and member reports |
Committee Member Filtering
graph LR
CommitteeLogin[Committee Login] --> LoadCommitteeData[Load Committee Info]
LoadCommitteeData --> CheckPosition{Has Position?}
CheckPosition -->|Yes| LoadPerms[Load Position Permissions]
CheckPosition -->|No| DefaultPerms[Use Default Committee Perms]
LoadPerms --> CheckLayer{Hierarchy Level?}
CheckLayer --> CheckDept{Department Access?}
CheckLayer --> Layer1[Layer 1 Access]
CheckLayer --> Layer2[Layer 2 Access]
CheckLayer --> Layer3[Layer 3 Access]
CheckLayer --> AllLayers[All Layers Access]
CheckDept --> Dept1[Specific Departments]
CheckDept --> AllDepts[All Departments]
Layer1 --> ApplyLayerFilter[Apply Layer Filter]
Layer2 --> ApplyLayerFilter
Layer3 --> ApplyLayerFilter
AllLayers --> NoLayerFilter[No Layer Filter]
Dept1 --> ApplyDeptFilter[Apply Department Filter]
AllDepts --> NoDeptFilter[No Department Filter]
ApplyLayerFilter --> FilteredData1[Filtered Data]
NoLayerFilter --> FilteredData2[Filtered Data]
ApplyDeptFilter --> FilteredData1
NoDeptFilter --> FilteredData2
DefaultPerms --> LimitedAccess[Limited Default Access]
style CommitteeLogin fill:#28a745,stroke:#333,stroke-width:2px,color:#fff
style LoadPerms fill:#ffc107,stroke:#333,stroke-width:2px,color:#333
style ApplyLayerFilter fill:#667eea,stroke:#333,stroke-width:2px,color:#fff
style ApplyDeptFilter fill:#764ba2,stroke:#333,stroke-width:2px,color:#fff
| Data Type | Committee Access | Automatic Filters | Can View |
|---|---|---|---|
| Transactions | βΈοΈ Based on Permissions | β Layer Assignment | Only transactions from members in assigned layer |
| Forms | β Approve/Reject | β Department + Layer | Only forms from assigned department in assigned layer |
| Members | β Limited Access | β Layer + Department | Only members in committee's layer and department |
| Committees | βΈοΈ Own Committee | β Committee ID | Only own committee details and members |
| Reports | βΈοΈ Filtered | β Layer + Department | Only reports for assigned layer and department |
StarClub Member Filtering
graph LR
StarClubLogin[StarClub Login] --> CheckReferrals{Has Referrals?}
CheckReferrals -->|No| DenyAccess[Access Denied]
CheckReferrals -->|Yes| LoadReferrals[Load Referral Network]
LoadReferrals --> DirectRefs[Direct Referrals]
DirectRefs --> IndirectRefs[Indirect Referrals]
IndirectRefs --> NetworkTree[Network Tree]
NetworkTree --> ApplyRefFilter[Apply Referral Filter]
ApplyRefFilter --> FilteredData[Only Referral Data]
FilteredData --> ViewNetwork[View Network]
FilteredData --> ViewStats[View Statistics]
FilteredData --> ViewTransactions[View Transactions]
style StarClubLogin fill:#ffc107,stroke:#333,stroke-width:2px,color:#333
style LoadReferrals fill:#764ba2,stroke:#333,stroke-width:2px,color:#fff
style ApplyRefFilter fill:#667eea,stroke:#333,stroke-width:2px,color:#fff
style DenyAccess fill:#dc3545,stroke:#333,stroke-width:2px,color:#fff
| Data Type | StarClub Access | Automatic Filters | Can View |
|---|---|---|---|
| Referral Network | β Full Access | β Own Referrals Only | All members referred by them (direct & indirect) |
| Transactions | βΈοΈ Filtered | β Referral-Based | Only transactions from referred members |
| Statistics | β Full Access | β Own Network Only | Referral count, active members, benefits earned |
| Members | βΈοΈ Limited | β Referral Network | Only members they referred |
| Reports | β Filtered | β Referral-Based | Only reports related to their referral network |
Transaction Filtering Details
Available Transaction Filters
The transaction table supports comprehensive filtering:
- Date Range:
dateFrom,dateTo- Filter by transaction creation date - Amount Range:
amountMin,amountMax- Filter by transaction amount - Type:
transactionType- membership_fee, renewal_fee, late_fee, etc. - Status:
paymentStatus- pending, completed, failed, cancelled, refunded - Organization:
organizationId- Filter by specific organization - Layer Hierarchy:
center(Layer 1),zone(Layer 2),branch(Layer 3) - Member:
memberId- Filter by specific member - Star Club:
starClubMember- Filter by referring member - Search:
search- Search by name, transaction ID, payment ID - Currency:
currency- Filter by currency (KWD, USD, etc.)
How Filtering is Applied in Code
Example: Transaction Filtering Logic
// 1. User logs in - JWT token contains user info
const user = {
id: 123,
layer: 'committee',
committeeData: { layerId: 5, departmentId: 2 }
}
// 2. Request comes with filters
GET /api/v1/transactions/transaction-table?page=1&limit=20
// 3. Backend applies automatic filters based on user type
if (user.layer === 'committee') {
// Only show transactions from members in same layer
filters.layerId = user.committeeData.layerId;
// Optional: Filter by department if assigned
if (user.committeeData.departmentId) {
filters.departmentId = user.committeeData.departmentId;
}
}
// 4. Query database with applied filters
SELECT * FROM transactions
WHERE layer_id = 5
AND department_id = 2
LIMIT 20 OFFSET 0;
9. Complete API Endpoints Overview
Authentication & Authorization
POST /api/v1/mixed-auth/admin-login- Admin loginPOST /api/v1/mixed-auth/member-login- Member login (Committee/StarClub)POST /api/v1/mixed-auth/complete-2fa-setup- Complete 2FA setupGET /api/v1/mixed-auth/check-auth-status- Check auth statusPOST /api/v1/mixed-auth/admin/generate-onetime-password- Generate OTP (Admin)POST /api/v1/mixed-auth/admin/reset-2fa- Reset 2FA (Admin)GET /api/v1/mixed-auth/admin/view-onetime-password/:memberId/:tabType- View OTP (Admin)GET /api/v1/mixed-auth/admin/auth-status/:memberId/:tabType- Auth status (Admin)
Members Management
POST /api/v1/members- Create memberGET /api/v1/members- List all members (filtered)GET /api/v1/members/:id- Get member detailsPUT /api/v1/members/:id- Update memberDELETE /api/v1/members/:id- Delete memberGET /api/v1/members/:id/family- Get family membersPUT /api/v1/members/:id/renew- Renew membershipGET /api/v1/members/referred-by/:memberId- Get referrals
Committees Management
POST /api/v1/committees- Create committeeGET /api/v1/committees- List committeesGET /api/v1/committees/:id- Get committee detailsPUT /api/v1/committees/:id- Update committeeDELETE /api/v1/committees/:id- Delete committeePOST /api/v1/committee-members- Assign committee memberGET /api/v1/committee-members- List committee membersPUT /api/v1/committee-members/:id- Update assignment
Transactions Management
POST /api/v1/transactions- Create transactionGET /api/v1/transactions- List transactionsGET /api/v1/transactions/:id- Get transaction detailsPUT /api/v1/transactions/:id- Update transactionDELETE /api/v1/transactions/:id- Delete transactionPOST /api/v1/transactions/:id/pay- Process paymentPOST /api/v1/transactions/:id/refund- Process refundGET /api/v1/transactions/:id/payment- Get payment detailsGET /api/v1/transactions/transaction-table- Advanced transaction tableGET /api/v1/transactions/transaction-table-filters- Get filter options
Organizations & Structure
GET /api/v1/organizations- List organizationsGET /api/v1/organization-units- List units (layers)GET /api/v1/departments- List departmentsGET /api/v1/positions- List positionsGET /api/v1/organization-settings- Get settings
Form Approvals
POST /api/v1/form-approvals- Submit formGET /api/v1/form-approvals- List formsPUT /api/v1/form-approvals/:id/approve- Approve formPUT /api/v1/form-approvals/:id/reject- Reject form
File Upload
POST /api/v1/fileupload/:folder/:subfolder- Upload single filePOST /api/v1/fileupload/:folder/:subfolder/multiple- Upload multiple files
9. User Type Comparison
| Feature | SuperAdmin | Committee Member | StarClub Member |
|---|---|---|---|
| Authentication | Username/Email + Password | Civil ID/Email + 2FA (TOTP) | Civil ID/Email + 2FA (TOTP) |
| Member Management | β Full access | β No access | β No access |
| Committee Management | β Full access | βΈοΈ Limited (own committee) | β No access |
| Transaction Management | β Full access | βΈοΈ Approve based on permissions | β No access |
| Form Approvals | β Full access | β Assign and approve forms | β No access |
| Referral Network | β View all | β No access | β Own referrals only |
| Reports & Analytics | β All reports | βΈοΈ Committee-specific | βΈοΈ Referral-specific |
| Settings Management | β Full access | β No access | β No access |
| 2FA Management | β Generate/Reset for all | β Setup only (self) | β Setup only (self) |