How tejas-dherange/society-connect works
Purpose and entry points
Nivasetu is a modular-monolith apartment-society operations platform: residents file and track maintenance complaints; admins manage resolutions, publish notices, and view analytics. The browser SPA starts at frontend/src/main.tsx and routes through frontend/src/router/AppRouter.tsx. The Node/Express API starts at backend/src/server.ts, with application middleware and route composition in backend/src/app.ts.
Client application boundary
React/Vite provides separate resident and admin experiences. Route protection and role-aware navigation are centered on frontend/src/router/ProtectedRoute.tsx, frontend/src/layouts/ResidentLayout.tsx, and frontend/src/layouts/AdminLayout.tsx. Auth state is held client-side in Zustand; Axios centralizes API calls and JWT refresh behavior through frontend/src/stores/authStore.ts and frontend/src/lib/axiosInstance.ts. Feature APIs isolate REST transport from pages under frontend/src/api/.
HTTP API and cross-cutting controls
Express exposes versioned REST endpoints for auth, complaints, notices, and dashboard aggregation. Modules follow controller → service → repository separation, with HTTP/validation concerns at the edge and Prisma persistence behind repositories; see backend/src/modules/complaints/complaints.routes.ts, backend/src/modules/complaints/complaints.service.ts, and backend/src/modules/complaints/complaints.repository.ts. Authentication, authorization, error translation, logging, rate limiting, CORS, and Swagger are composed around this API in backend/src/app.ts and backend/src/common/middleware/authenticate.ts.
Identity and authorization
Residents self-register and authenticate with short-lived access JWTs plus refresh-token rotation. Auth endpoints and user persistence are organized in backend/src/modules/auth/auth.controller.ts, backend/src/modules/auth/auth.service.ts, and backend/src/modules/auth/auth.repository.ts. RBAC separates RESIDENT ownership-scoped complaint access from ADMIN cross-society management, enforced at routes/services and mirrored in protected frontend routes.
Core society workflows
Complaint submission accepts multipart photo uploads, persists complaint state/history, and supports resident detail/timeline views plus admin status and priority changes. The primary module is backend/src/modules/complaints/complaints.service.ts, with Cloudinary/Multer integration at backend/src/common/upload/cloudinaryUpload.ts. Notices are authenticated reads but admin-authored/soft-deleted; important notices are pinned and initiate resident email broadcasts via backend/src/modules/notices/notices.service.ts. Dashboard queries produce admin KPIs, status/category distributions, overdue counts, and recent activity through backend/src/modules/dashboard/dashboard.service.ts.
Persistence and asynchronous processing
PostgreSQL is the system of record, accessed through Prisma; domain entities include users, complaints, photos, histories, notices, and notification delivery records in backend/prisma/schema.prisma, using the client from backend/src/common/database/prisma.ts. Redis backs BullMQ email jobs: application services enqueue work, and a worker calls Resend independently of HTTP request latency via backend/src/common/queue/emailQueue.ts and backend/src/common/queue/emailWorker.ts. Notification records preserve delivery state.
Scheduled operations and deployment
An embedded node-cron process periodically marks unresolved complaints overdue according to environment configuration; its logic is backend/src/jobs/overdueDetector.ts and standalone launch path is backend/src/cli/startOverdueCron.ts. Material external services are Neon/local PostgreSQL, Redis, Cloudinary image storage/CDN, and Resend email. Production targets a Vercel static frontend and a Node backend on DigitalOcean/VPS, with PM2/Nginx deployment guidance in DEPLOYMENT.md.
Main entry points: app.ts Express app · complaints.service.ts Complaints service · prisma.ts Prisma data access · notices.service.ts Notices service
Components 20
Browser SPA
- React/Vite entry
frontend/src/main.tsx - App router
frontend/src/router/AppRouter.tsx - Protected layouts · Resident and admin route boundaries.
frontend/src/router/ProtectedRoute.tsx - Auth store and Axios · Holds session state and refreshes access tokens.
frontend/src/stores/authStore.ts
Node API
- Express server
backend/src/server.ts - Express app · Composes CORS, rate limits, logging, errors, Swagger, and versioned REST routes.
backend/src/app.ts - Authentication middleware
backend/src/common/middleware/authenticate.ts
Domain workflows
- Auth module · Registration, login, and refresh-token rotation.
backend/src/modules/auth/auth.service.ts - Complaints service · Ownership-scoped resident workflows and admin status or priority changes.
backend/src/modules/complaints/complaints.service.ts - Complaint routes · Multipart complaint API boundary.
backend/src/modules/complaints/complaints.routes.ts - Notices service · Admin publishing, pinning, soft deletion, and resident broadcasts.
backend/src/modules/notices/notices.service.ts - Dashboard service · KPIs, distributions, overdue counts, and activity.
backend/src/modules/dashboard/dashboard.service.ts
Async and scheduled
- Email queue
backend/src/common/queue/emailQueue.ts - Email worker · Sends asynchronously outside HTTP request latency.
backend/src/common/queue/emailWorker.ts - Overdue detector · Marks unresolved complaints overdue.
backend/src/jobs/overdueDetector.ts
Persistence and external services
- Prisma data access
backend/src/common/database/prisma.ts - PostgreSQL · Users, complaints, photos, histories, notices, and notification deliveries.
backend/prisma/schema.prisma - Cloudinary upload
backend/src/common/upload/cloudinaryUpload.ts - Redis
- Resend
Connections 23
- React/Vite entry → App router: mounts routes
- App router → Protected layouts: guards experiences
- Protected layouts → Auth store and Axios: reads role/session
- Auth store and Axios → Express server: REST with JWT refresh
- Express server → Express app: starts
- Express app → Authentication middleware: applies controls
- Express app → Auth module: auth endpoints
- Express app → Complaint routes: complaint endpoints
- Complaint routes → Complaints service: validates and delegates
- Authentication middleware → Complaints service: enforces identity and role
- Express app → Notices service: notice endpoints
- Express app → Dashboard service: dashboard endpoints
- Auth module → Prisma data access: persists identities and tokens
- Complaints service → Prisma data access: persists workflow state
- Complaints service → Cloudinary upload: stores photos
- Notices service → Prisma data access: persists notices and delivery state
- Dashboard service → Prisma data access: aggregates records
- Prisma data access → PostgreSQL: queries
- Notices service → Email queue: enqueues broadcasts
- Email queue → Redis: stores jobs
- Redis → Email worker: delivers jobs
- Email worker → Resend: sends email
- Overdue detector → Complaints service: updates overdue state