# jyrwajr/employee architecture

> Architecture diagram of the GitHub repository jyrwajr/employee, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jyrwajr/employee
- Repository: https://github.com/jyrwajr/employee

## Overview

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: [`employee-backend/src/app/api`](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/app/api) (API routes), [`employee-backend/src/services`](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/services) (Domain services), [`employee-backend/src/libs/db/prisma`](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/libs/db/prisma) (Prisma DB), [`employee-mobile/src/features`](https://github.com/jyrwajr/employee/tree/master/employee-mobile/src/features) (User features)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["employee-backend"]
  node_backend_api["API routes<br/>next app router"]
  node_backend_auth_routes["Auth routes<br/>route set"]
  node_backend_employee_routes["Employee routes<br/>route set"]
  node_backend_salary_routes["Salary routes<br/>route set"]
  node_backend_notify_routes["Push routes<br/>route set"]
  node_backend_middleware{{"Request gate<br/>middleware"}}
  node_backend_response["Response utils<br/>http helpers"]
  node_backend_services["Domain services<br/>service layer"]
  node_backend_auth_service["Auth logic"]
  node_backend_employee_service["Employee logic"]
  node_backend_salary_service["Salary logic"]
  node_backend_leave_service["Leave logic"]
  node_backend_pension_service["Pension logic"]
  node_backend_notification_service["Notification logic"]
  node_backend_db[("Prisma DB<br/>persistence")]
  node_backend_auth_lib["Auth libs<br/>jwt/cookie/hash"]
  node_backend_utils["Core utils<br/>shared helpers"]
end

subgraph group_mobile["employee-mobile"]
  node_mobile_app["App routes<br/>expo router"]
  node_mobile_features["Feature modules<br/>feature layer"]
  node_mobile_auth_feature["Auth feature"]
  node_mobile_employee_feature["Employee feature"]
  node_mobile_main_features["User features"]
  node_mobile_push_feature["Push feature"]
  node_mobile_shared["Shared client<br/>runtime infra"]
end

subgraph group_shared["Shared runtime"]
end

node_backend_api -->|"auth"| node_backend_auth_routes
node_backend_api -->|"employees"| node_backend_employee_routes
node_backend_api -->|"salary"| node_backend_salary_routes
node_backend_api -->|"register"| node_backend_notify_routes
node_backend_auth_routes -->|"guarded by"| node_backend_middleware
node_backend_employee_routes -->|"guarded by"| node_backend_middleware
node_backend_salary_routes -->|"guarded by"| node_backend_middleware
node_backend_notify_routes -->|"guarded by"| node_backend_middleware
node_backend_auth_routes -->|"returns"| node_backend_response
node_backend_employee_routes -->|"returns"| node_backend_response
node_backend_services -->|"auth"| node_backend_auth_service
node_backend_services -->|"employee"| node_backend_employee_service
node_backend_services -->|"salary"| node_backend_salary_service
node_backend_services -->|"leave"| node_backend_leave_service
node_backend_services -->|"pension"| node_backend_pension_service
node_backend_services -->|"notification"| node_backend_notification_service
node_backend_auth_service -->|"tokens/passwords"| node_backend_auth_lib
node_backend_auth_service -->|"stores"| node_backend_db
node_backend_employee_service -->|"persists"| node_backend_db
node_backend_salary_service -->|"persists"| node_backend_db
node_backend_leave_service -->|"persists"| node_backend_db
node_backend_pension_service -->|"persists"| node_backend_db
node_backend_notification_service -->|"stores tokens"| node_backend_db
node_backend_api -->|"delegates"| node_backend_services
node_backend_api -->|"uses"| node_backend_utils
node_mobile_app -->|"auth"| node_mobile_auth_feature
node_mobile_app -->|"admin"| node_mobile_employee_feature
node_mobile_app -->|"main UX"| node_mobile_main_features
node_mobile_app -->|"notifications"| node_mobile_push_feature
node_mobile_features -->|"contains"| node_mobile_auth_feature
node_mobile_features -->|"contains"| node_mobile_employee_feature
node_mobile_features -->|"contains"| node_mobile_main_features
node_mobile_features -->|"contains"| node_mobile_push_feature
node_mobile_auth_feature -->|"uses"| node_mobile_shared
node_mobile_employee_feature -->|"uses"| node_mobile_shared
node_mobile_main_features -->|"uses"| node_mobile_shared
node_mobile_push_feature -->|"uses"| node_mobile_shared
node_mobile_auth_feature -->|"calls"| node_backend_auth_routes
node_mobile_employee_feature -->|"calls"| node_backend_employee_routes
node_mobile_main_features -->|"calls"| node_backend_salary_routes
node_mobile_main_features -->|"calls"| node_backend_employee_routes
node_mobile_push_feature -->|"calls"| node_backend_notify_routes
node_mobile_shared -->|"requests"| node_backend_api

click node_backend_api "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/app/api"
click node_backend_auth_routes "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/app/api/auth"
click node_backend_employee_routes "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/app/api/employees"
click node_backend_salary_routes "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/app/api/salary"
click node_backend_notify_routes "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/app/api/notification/register"
click node_backend_middleware "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/utils/middleware"
click node_backend_response "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/utils/next-response"
click node_backend_services "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/services"
click node_backend_auth_service "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/services/auth"
click node_backend_employee_service "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/services/employee"
click node_backend_salary_service "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/services/salary"
click node_backend_leave_service "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/services/leave"
click node_backend_pension_service "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/services/pension"
click node_backend_notification_service "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/services/notification"
click node_backend_db "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/libs/db/prisma"
click node_backend_auth_lib "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/libs/auth"
click node_backend_utils "https://github.com/jyrwajr/employee/tree/master/employee-backend/src/utils"
click node_mobile_app "https://github.com/jyrwajr/employee/tree/master/employee-mobile/src/app"
click node_mobile_features "https://github.com/jyrwajr/employee/tree/master/employee-mobile/src/features"
click node_mobile_auth_feature "https://github.com/jyrwajr/employee/tree/master/employee-mobile/src/features/auth"
click node_mobile_employee_feature "https://github.com/jyrwajr/employee/tree/master/employee-mobile/src/features/employee"
click node_mobile_main_features "https://github.com/jyrwajr/employee/tree/master/employee-mobile/src/features"
click node_mobile_push_feature "https://github.com/jyrwajr/employee/tree/master/employee-mobile/src/features/pushNotification"
click node_mobile_shared "https://github.com/jyrwajr/employee/tree/master/employee-mobile/src/shared"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_backend_api,node_backend_auth_routes,node_backend_employee_routes,node_backend_salary_routes,node_backend_notify_routes,node_backend_middleware,node_backend_response,node_backend_services,node_backend_auth_service,node_backend_employee_service,node_backend_salary_service,node_backend_leave_service,node_backend_pension_service,node_backend_notification_service,node_backend_db,node_backend_auth_lib,node_backend_utils toneBlue
class node_mobile_app,node_mobile_features,node_mobile_auth_feature,node_mobile_employee_feature,node_mobile_main_features,node_mobile_push_feature,node_mobile_shared toneAmber
```

## Components

### employee-backend

Next.js API server, domain services, and persistence.

- [API routes](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/app/api): next app router · REST endpoints under src/app/api for auth, employees, salary, and notifications. · `employee-backend/src/app/api`
- [Auth routes](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/app/api/auth): route set · Sign-in, sign-up, refresh, logout, me, OTP init, OTP verify, forgot-password. · `employee-backend/src/app/api/auth`
- [Employee routes](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/app/api/employees): route set · Employee CRUD plus leave and pension subresource endpoints. · `employee-backend/src/app/api/employees`
- [Salary routes](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/app/api/salary): route set · Salary record endpoints and per-employee salary views. · `employee-backend/src/app/api/salary`
- [Push routes](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/app/api/notification/register): route set · Mobile device token registration endpoint. · `employee-backend/src/app/api/notification/register`
- [Request gate](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/utils/middleware): middleware · Auth, role checks, validation, CORS, logging, security headers, and rate limiting. · `employee-backend/src/utils/middleware`
- [Response utils](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/utils/next-response): http helpers · Consistent success/error/params/search validation wrappers for API routes. · `employee-backend/src/utils/next-response`
- [Domain services](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/services): service layer · Reusable business logic behind the route handlers. · `employee-backend/src/services`
- [Auth logic](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/services/auth): service · Token/session and OTP/password flows. · `employee-backend/src/services/auth`
- [Employee logic](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/services/employee): service · Employee CRUD and related business rules. · `employee-backend/src/services/employee`
- [Salary logic](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/services/salary): service · Salary persistence and employee salary views. · `employee-backend/src/services/salary`
- [Leave logic](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/services/leave): service · Leave subresource business rules. · `employee-backend/src/services/leave`
- [Pension logic](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/services/pension): service · Pension subresource business rules. · `employee-backend/src/services/pension`
- [Notification logic](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/services/notification): service · Expo push token registration and notification support. · `employee-backend/src/services/notification`
- [Prisma DB](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/libs/db/prisma): persistence · Schema, migrations, seed data, and database access layer. · `employee-backend/src/libs/db/prisma`
- [Auth libs](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/libs/auth): jwt/cookie/hash · JWT, cookies, bcrypt, and password helpers. · `employee-backend/src/libs/auth`
- [Core utils](https://github.com/jyrwajr/employee/tree/master/employee-backend/src/utils): shared helpers · 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](https://github.com/jyrwajr/employee/tree/master/employee-mobile/src/app): expo router · Route groups for auth, main tabs, admin, forbidden, settings, and detail screens. · `employee-mobile/src/app`
- [Feature modules](https://github.com/jyrwajr/employee/tree/master/employee-mobile/src/features): feature layer · Feature-local screens, API definitions, hooks, validators, and components. · `employee-mobile/src/features`
- [Auth feature](https://github.com/jyrwajr/employee/tree/master/employee-mobile/src/features/auth): feature · Login, sign-up, forgot-password, OTP forms, and auth API integration. · `employee-mobile/src/features/auth`
- [Employee feature](https://github.com/jyrwajr/employee/tree/master/employee-mobile/src/features/employee): feature · Admin employee list, details, and salary drill-down screens. · `employee-mobile/src/features/employee`
- [User features](https://github.com/jyrwajr/employee/tree/master/employee-mobile/src/features): features · Home, leave, pension, profile, salary, and settings experiences. · `employee-mobile/src/features`
- [Push feature](https://github.com/jyrwajr/employee/tree/master/employee-mobile/src/features/pushNotification): feature · Notification provider, hook, and device token registration service. · `employee-mobile/src/features/pushNotification`
- [Shared client](https://github.com/jyrwajr/employee/tree/master/employee-mobile/src/shared): runtime infra · API/query utilities, stores, providers, auth redirect, SSL pinning, network handling, and common UI. · `employee-mobile/src/shared`

## Connections

- 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.
