How zithtech/zithspace-be works
Purpose and runtime
Zithmi Backend V2 is a TypeScript/Express, multi-tenant business platform API. It combines project delivery, HR operations, payroll, recruitment, CRM/proposals, finance, documents, and client-portal capabilities in one server. src/app.ts is the application entry point; production compiled output is under dist/app.js. Docker deployment is defined by Dockerfile and docker-compose.yml.
HTTP composition and domain boundary
The application is route/controller-oriented for legacy and shared domains: route modules expose HTTP APIs and controllers implement request-facing orchestration. Key areas include authentication, projects/tickets/sprints, attendance/time tracking, invoices/transactions, employees, and document hub.
• src/routes/auth.ts
• src/controllers/authController.ts
• src/routes/projects.ts
Newer bounded modules use a clearer HTTP → controller → service → repository → dedicated database layout, rather than the flat controller set. Each module owns its routes, migrations, pool, validation, and domain services.
• src/modules/payroll/http.ts
• src/modules/leave-v2/http.ts
• src/modules/opening-management/http.ts
Tenant identity, authentication, and authorization
Tenant resolution is an upstream request boundary, supporting tenant context before protected domain handling. Authentication uses JWT utilities and middleware; authorization combines generic permission middleware with the RBAC module. PostgreSQL RLS is the intended final tenant-isolation layer, backed by tenant-aware Prisma/database configuration.
• src/middleware/tenantContext.ts
• src/middleware/auth.ts
• src/middleware/permission.ts
• src/modules/rbac/rbac.service.ts
• src/config/database.ts
• prisma/schema.prisma
Primary protected flow: request → tenant context → JWT/client-portal auth → permission or module gate → route/controller → persistence/service. Client-portal access is a separate security boundary.
• src/middleware/clientPortalAuth.ts
• src/middleware/portalModuleGate.ts
• src/routes/clientPortal.ts
Persistence and schema evolution
PostgreSQL is the core datastore. Prisma schema and migrations define the shared platform data model; additional SQL migration streams and module-local pools/schemas support newer or specialized subsystems. This means database ownership is mixed: shared Prisma-backed entities coexist with direct module repositories and dedicated pools.
• prisma/schema.prisma
• prisma/migrations/0_baseline/migration.sql
• src/database/migrations/015_create_tenant_ai_settings.sql
• src/modules/payroll/db/pool.ts
• src/modules/leave-v2/db/migrations/001_init.sql
Operational HR and finance workflows
HR functionality covers employee lifecycle, attendance, leave, onboarding/exit, and reimbursements. Payroll V2 is a discrete processing subsystem: employee assignments and structures feed pay-run calculation, approval/finalization, payslip generation, bank files, and reports.
• src/controllers/attendanceController.ts
• src/modules/leave-v2/services/leaveRequest.service.ts
• src/modules/payroll/services/payRun.service.ts
• src/modules/payroll/services/payRunCalc.ts
• src/modules/payroll/services/payslipPdf.ts
Reimbursement V2 similarly separates policies, claims, approvals, advances, budgets, and finance/reporting.
• src/modules/reimbursement-v2/routes/index.ts
• src/modules/reimbursement-v2/services/claim.service.ts
• src/modules/reimbursement-v2/services/approval.service.ts
Delivery, CRM, recruitment, and portals
Project-delivery flows center on clients, projects, tickets, QA, releases, timesheets, and sprint reporting; client portal APIs expose selected delivery artifacts externally. CRM/revenue features manage leads, proposals, bid assistance, templates, invoices, and mail. Recruitment spans requisitions/openings, applicants, approvals, postings, referrals, and candidate pipeline processing.
• src/controllers/ticketController.ts
• src/controllers/sprintReportController.ts
• src/controllers/ProposalController.ts
• src/modules/opening-management/services/opening.service.ts
• src/modules/pipeline/services/candidateService.ts
Async processing and integrations
Background work handles calendar/mail synchronization, scheduled mail, timer auto-pause, trash purging, leave accrual, and payslip generation. RabbitMQ is explicitly configured and queue/worker pairs isolate long-running synchronization and document-generation work from HTTP requests.
• src/config/rabbitmq.ts
• src/workers/CalendarSyncWorker.ts
• src/workers/MailSyncWorker.ts
• src/modules/payroll/jobs/payslipWorker.ts
• src/modules/leave-v2/jobs/accrualWorker.ts
External integration boundaries include Google, Microsoft, and Zoho calendar/mail providers; configurable AI providers; Redis/cache utilities; Cloudflare R2-style object storage; PDFs, email, sockets, and push notifications.
• src/services/calendar/CalendarProviderFactory.ts
• src/services/mail/MailProviderFactory.ts
• src/services/ai/resolver.ts
• src/utils/r2Client.ts
• src/utils/redis.ts
Main entry points: permission.ts Permissions & RBAC · schema.prisma Shared PostgreSQL · projects.ts Legacy shared APIs · http.ts Payroll V2
Components 19
HTTP & Security
- Express application · Composes the multi-tenant API.
src/app.ts - Tenant context · Establishes tenant identity before protected handling.
src/middleware/tenantContext.ts - JWT authentication
src/middleware/auth.ts - Permissions & RBAC
src/middleware/permission.ts - Client portal boundary · Separate authentication and module-access boundary.
src/routes/clientPortal.ts - Legacy shared APIs · Route/controller APIs for auth, projects, attendance, finance, and documents.
src/routes/projects.ts
Domain Modules
- Payroll V2 · Owns HTTP, services, repository, migrations, and pool.
src/modules/payroll/http.ts - Leave V2 · Owns leave requests and accrual processing.
src/modules/leave-v2/http.ts - Reimbursement V2 · Claims, approvals, advances, budgets, and reporting.
src/modules/reimbursement-v2/routes/index.ts - Recruitment modules · Openings and candidate pipeline processing.
src/modules/opening-management/http.ts - Pay-run calculation · Calculates, approves, and finalizes pay runs.
src/modules/payroll/services/payRun.service.ts
Data & Async
- Shared PostgreSQL · Shared platform model with tenant RLS intent.
prisma/schema.prisma - Module databases · Direct repositories and specialized module schemas coexist with Prisma.
src/modules/payroll/db/pool.ts - Schema migrations · Shared and module-local schema evolution streams.
prisma/migrations/0_baseline/migration.sql - RabbitMQ · Queues long-running synchronization and document jobs.
src/config/rabbitmq.ts - Background workers · Calendar/mail sync, leave accrual, and scheduled maintenance.
src/workers/CalendarSyncWorker.ts - Payslip worker · Generates payslips asynchronously.
src/modules/payroll/jobs/payslipWorker.ts
External Services
- Calendar & mail providers · Google, Microsoft, and Zoho provider boundary.
src/services/calendar/CalendarProviderFactory.ts - Platform services · AI, Redis cache, object storage, email, sockets, and push.
src/services/ai/resolver.ts
Connections 22
- Express application → Tenant context: all requests
- Tenant context → JWT authentication: protected API
- JWT authentication → Permissions & RBAC: authenticated principal
- Permissions & RBAC → Legacy shared APIs: authorized request
- Permissions & RBAC → Payroll V2: module access
- Permissions & RBAC → Leave V2: module access
- Permissions & RBAC → Reimbursement V2: module access
- Permissions & RBAC → Recruitment modules: module access
- Express application → Client portal boundary: portal requests
- Legacy shared APIs → Shared PostgreSQL: shared persistence
- Payroll V2 → Pay-run calculation: orchestrates
- Pay-run calculation → Module databases: payroll data
- Leave V2 → Module databases: module persistence
- Reimbursement V2 → Shared PostgreSQL: platform persistence
- Recruitment modules → Shared PostgreSQL: platform persistence
- Schema migrations → Shared PostgreSQL: evolves shared schema
- Pay-run calculation → RabbitMQ: queues payslips
- RabbitMQ → Payslip worker: payslip jobs
- RabbitMQ → Background workers: async jobs
- Background workers → Calendar & mail providers: calendar and mail sync
- Legacy shared APIs → Platform services: uses platform integrations
- Payroll V2 → Platform services: PDF and notifications