How jyrwajr/employee works
1. Top-level shape
- This repo is a two-part employee management system:
- employee-backend: a Next.js server that exposes REST API routes and owns persistence/business rules.
- employee-mobile: an Expo/React Native client that consumes those APIs and provides the user experience.
- The backend is the source of truth for employees, salary, leave, pension, auth, and notifications.
2. Backend execution model
- The backend uses the Next.js App Router under src/app/api/**/route.ts, so each domain operation is implemented as an HTTP endpoint rather than a traditional controller/service monolith.
- Cross-cutting concerns are centralized in src/utils/middleware and response helpers in src/utils/next-response, giving the API a consistent security, validation, and error-handling boundary.
3. Backend domain boundaries
- The API is organized by business capability:
- auth: sign-up, sign-in, refresh, logout, me, init OTP flow, forgot-password, OTP verification.
- employees: CRUD plus subresources for leave and pension.
- salary: salary records and per-employee salary views.
- notification/register: push-token registration for the mobile app.
- These are not just route names; they map to separate service folders in src/services/**, which hold the domain logic behind the routes.
4. Auth and session flow
- Authentication is token-based and appears to use both access and refresh tokens, with JWT helpers in src/libs/auth/jwt.ts and cookie handling in src/libs/auth/cookies.ts.
- Password handling is separated from OTP-based initialization/reset flows, with dedicated auth services for OTP and “use password”.
- The mobile app’s login/signup/forgot-password screens map directly to these auth routes, so auth is a primary integration boundary.
5. Security and request gating
- The backend has explicit middleware for:
- auth enforcement (requiredAuth, withApiAuth)
- role enforcement (requireAdmin, requireSuperAdmin)
- route validation and parameter/search validation
- CORS, logging, security headers, and rate limiting
- This means requests are filtered before reaching domain services, and not every endpoint is equally public; some are app-facing, some admin-only.
- Redis is likely used for rate limiting/cache support via the Upstash env vars in the README.
6. Persistence and data model
- Prisma is the persistence layer, with schema and migrations under src/libs/db/prisma.
- The database tracks users/auth, employees, salaries, pensions, OTP records, and Expo push tokens.
- Seeding is significant here: the repo includes a seed script intended to populate realistic employee and salary history data, so the backend is designed for nontrivial historical records rather than just CRUD.
7. Backend business services
- Domain logic is split into reusable services:
- employee, salary, leave, pension, notification, tokens, and auth
- This suggests routes are thin wrappers while business rules live in services.
- Shared utilities for encryption, hashing, token expiry, OTP generation/expiry, pagination, and UTC/IST conversion support those services.
8. Mobile app architecture
- The mobile app uses Expo Router-style file routing under src/app/**, with route groups for:
- auth
- (drawers)/(tabs) for the main authenticated experience
- (admin) for admin-only screens
- forbidden, settings, pension/[id], etc.
- The UI layer is feature-oriented: each feature folder contains its own API definitions, screens, components, hooks, and validators.
9. Mobile data flow
- Shared infrastructure lives in src/shared:
- API/query utilities and request config
- React Query provider and query helpers
- token/local auth stores
- auth and local-auth providers
- theme, updates, SSL pinning, and error boundary providers
- Feature screens call feature-specific API endpoints, which likely feed into shared query/cache state and auth state.
- This creates a clear flow: screen → feature API/hook → shared HTTP/query layer → backend API → response/cache/store.
10. Mobile security and connectivity
- The mobile app has SSL public key pinning, which is a major architectural constraint: the client is designed to trust only specific backend certificate hashes.
- It also includes network-aware behavior, retry logic, and an auth redirect layer, so connectivity and session state affect navigation.
- Push notifications are handled as a feature with a provider, hook, and a service that registers the device token back to the backend.
11. Admin vs employee experiences
- The mobile app contains distinct experiences for general users and admins:
- general app tabs for home/leave/pension/profile/statement
- admin screens for employee lists, details, and salary views
- That split mirrors backend authorization, so the architecture enforces role-based access both in UI routing and server-side middleware.
12. Operational/tooling boundaries
- Backend depends on Node.js, Prisma migrations/seeding, and environment variables for DB/JWT/Redis config.
- Mobile depends on Expo/EAS, native prebuild support for SSL pinning, and OTA updates for certificate rotation.
- This means deployment is coupled across tiers: backend certificate changes can force a mobile hash update, and that operational dependency is explicit in the README.
13. Primary integration points
- The important system boundaries to draw are:
- Mobile app ↔ backend REST API
- Backend ↔ PostgreSQL/MySQL via Prisma
- Backend ↔ Redis-like cache/rate-limit store
- Mobile ↔ push notification registration endpoint
- Most of the application logic lives on the backend, while the mobile app is a secure, stateful client with feature-local UI and data fetching.
Main entry points: api API routes · services Domain services · prisma Prisma DB · features User features
Components 24
employee-backend
Next.js API server, domain services, and persistence.
- API routes · REST endpoints under src/app/api for auth, employees, salary, and notifications.
employee-backend/src/app/api - Auth routes · Sign-in, sign-up, refresh, logout, me, OTP init, OTP verify, forgot-password.
employee-backend/src/app/api/auth - Employee routes · Employee CRUD plus leave and pension subresource endpoints.
employee-backend/src/app/api/employees - Salary routes · Salary record endpoints and per-employee salary views.
employee-backend/src/app/api/salary - Push routes · Mobile device token registration endpoint.
employee-backend/src/app/api/notification/register - Request gate · Auth, role checks, validation, CORS, logging, security headers, and rate limiting.
employee-backend/src/utils/middleware - Response utils · Consistent success/error/params/search validation wrappers for API routes.
employee-backend/src/utils/next-response - Domain services · Reusable business logic behind the route handlers.
employee-backend/src/services - Auth logic · Token/session and OTP/password flows.
employee-backend/src/services/auth - Employee logic · Employee CRUD and related business rules.
employee-backend/src/services/employee - Salary logic · Salary persistence and employee salary views.
employee-backend/src/services/salary - Leave logic · Leave subresource business rules.
employee-backend/src/services/leave - Pension logic · Pension subresource business rules.
employee-backend/src/services/pension - Notification logic · Expo push token registration and notification support.
employee-backend/src/services/notification - Prisma DB · Schema, migrations, seed data, and database access layer.
employee-backend/src/libs/db/prisma - Auth libs · JWT, cookies, bcrypt, and password helpers.
employee-backend/src/libs/auth - Core utils · Encryption, OTP/time helpers, pagination, validation, logging, and HTTP utilities.
employee-backend/src/utils
employee-mobile
Expo/React Native client and feature modules.
- App routes · Route groups for auth, main tabs, admin, forbidden, settings, and detail screens.
employee-mobile/src/app - Feature modules · Feature-local screens, API definitions, hooks, validators, and components.
employee-mobile/src/features - Auth feature · Login, sign-up, forgot-password, OTP forms, and auth API integration.
employee-mobile/src/features/auth - Employee feature · Admin employee list, details, and salary drill-down screens.
employee-mobile/src/features/employee - User features · Home, leave, pension, profile, salary, and settings experiences.
employee-mobile/src/features - Push feature · Notification provider, hook, and device token registration service.
employee-mobile/src/features/pushNotification - Shared client · API/query utilities, stores, providers, auth redirect, SSL pinning, network handling, and common UI.
employee-mobile/src/shared
Connections 43
- API routes → Auth routes: auth · Auth endpoints are grouped under the API router.
- API routes → Employee routes: employees · Employee endpoints are grouped under the API router.
- API routes → Salary routes: salary · Salary endpoints are grouped under the API router.
- API routes → Push routes: register · Push-token registration is exposed as an API route.
- Auth routes → Request gate: guarded by · Auth routes pass through request gates and validation.
- Employee routes → Request gate: guarded by · Role and auth checks protect employee endpoints.
- Salary routes → Request gate: guarded by · Salary endpoints are filtered by middleware.
- Push routes → Request gate: guarded by · Push registration is filtered by middleware.
- Auth routes → Response utils: returns · Routes use shared response wrappers.
- Employee routes → Response utils: returns · Routes use shared response wrappers.
- Domain services → Auth logic: auth · Auth business logic is encapsulated in a service module.
- Domain services → Employee logic: employee · Employee business logic is encapsulated in a service module.
- Domain services → Salary logic: salary · Salary business logic is encapsulated in a service module.
- Domain services → Leave logic: leave · Leave business logic is encapsulated in a service module.
- Domain services → Pension logic: pension · Pension business logic is encapsulated in a service module.
- Domain services → Notification logic: notification · Notification business logic is encapsulated in a service module.
- Auth logic → Auth libs: tokens/passwords · Auth logic relies on JWT, cookies, and hashing helpers.
- Auth logic → Prisma DB: stores · Auth state and OTP data are persisted via Prisma.
- Employee logic → Prisma DB: persists · Employee records are read and written in the database.
- Salary logic → Prisma DB: persists · Salary history is stored in the database.
- Leave logic → Prisma DB: persists · Leave data is stored in the database.
- Pension logic → Prisma DB: persists · Pension data is stored in the database.
- Notification logic → Prisma DB: stores tokens · Expo push tokens are persisted with user/auth linkage.
- API routes → Domain services: delegates · Routes are thin wrappers over domain services.
- API routes → Core utils: uses · Routes and services share utility helpers.
- App routes → Auth feature: auth · Auth screens live in routed feature modules.
- App routes → Employee feature: admin · Admin employee screens are routed from the app layer.
- App routes → User features: main UX · Authenticated user flows are composed from feature modules.
- App routes → Push feature: notifications · Push notification behavior is wired into the app.
- Feature modules → Auth feature: contains · Feature module for authentication.
- Feature modules → Employee feature: contains · Feature module for employee admin UI.
- Feature modules → User features: contains · Feature modules for home, leave, pension, profile, salary, and settings.
- Feature modules → Push feature: contains · Feature module for push notifications.
- Auth feature → Shared client: uses · Auth feature uses shared API, state, and redirect infrastructure.
- Employee feature → Shared client: uses · Employee feature uses shared API and UI primitives.
- User features → Shared client: uses · Main experience uses shared infrastructure and components.
- Push feature → Shared client: uses · Push notifications depend on shared network and state tools.
- Auth feature → Auth routes: calls · Auth UI maps directly to backend auth endpoints.
- Employee feature → Employee routes: calls · Admin employee views consume employee APIs.
- User features → Salary routes: calls · Salary and statement screens consume salary APIs.
- User features → Employee routes: calls · Leave, pension, and profile screens consume employee APIs.
- Push feature → Push routes: calls · Device token registration posts to the backend.
- Shared client → API routes: requests · Shared client HTTP layer talks to the backend REST API.