How ipushpie/expense-reimbursement-service works
1. What this repo is
- A full-stack expense reimbursement system with three main personas: employees, employers, and admins.
- The core business flow is: employees create expenses with receipts, group them into reimbursement requests, and employers approve or reject them.
2. Top-level architecture
- The repo is split into a backend API (backend/), a Next.js frontend (frontend/), and infrastructure/deployment files at the root.
- Persistent state lives in PostgreSQL via Prisma, while uploaded receipts live in MinIO object storage.
- In production, Caddy sits in front as the TLS reverse proxy.
3. Backend runtime and request pipeline
- The backend is a Node.js + Express + TypeScript service.
- src/server.ts and src/app.ts likely wire the HTTP server, middleware stack, routes, and startup concerns.
- Cross-cutting middleware is centralized under src/shared/middleware: authentication, authorization, validation, file upload handling, and error handling.
4. Backend feature boundaries
- The backend is organized by domain modules rather than by technical layer:
- auth
- expenses
- reimbursements
- departments
- audit
- Most modules follow a controller/service/repository pattern, with request schemas alongside the routes for input validation.
- departments appears lighter-weight, likely serving read-focused or simpler data access compared with the workflow-heavy modules.
5. Business workflow: expenses
- The expense module handles draft expense creation and maintenance, including editing and deletion before submission.
- Receipt uploads are part of this flow, so expense creation is coupled to object storage, not just database persistence.
- Currency handling is important here because expenses can originate in multiple currencies.
6. Business workflow: reimbursements
- Reimbursement requests group one or more expenses into a submit/approve/reject workflow.
- Employees initiate submission; employers review requests and add approval or rejection notes.
- The frontend exposes list/detail/new pages for this workflow, indicating request state transitions are a central UI and API concern.
7. Auditability and compliance
- The audit module records actions with before/after values, which means changes are tracked as part of the domain rather than only through logs.
- This creates a separate queryable history layer for employers and admins, distinct from operational expense/reimbursement records.
- The architecture is therefore not just transactional; it is also event/history oriented.
8. Multi-currency and budget semantics
- The system supports multiple currencies and normalizes totals to USD for consistent reporting.
- The README states exchange-rate snapshots are stored at submission time, so totals remain historically stable even if rates change later.
- Department budgets are “soft” constraints: they warn and inform dashboards but do not block submission.
9. Data and persistence layer
- Prisma is the ORM layer, with the schema in backend/prisma/schema.prisma and seed data in backend/prisma/seed.ts.
- PostgreSQL is the authoritative relational store for users, expenses, reimbursements, departments, budgets, and audit records.
- The seed file plus demo accounts suggest the repo is designed to bootstrap a usable environment quickly for local development and demos.
10. File storage layer
- Receipts are stored in MinIO, which acts as an S3-compatible object store.
- The backend uses upload middleware and storage utilities, and downloads are delivered through presigned URLs with limited lifetime.
- This keeps binary files out of the database and separates document access from core API authorization.
11. Frontend architecture
- The frontend is a Next.js 15 + React 19 application using the App Router under src/app.
- Pages are split by domain and role, including employee expense/reimbursement screens and employer dashboards/requests.
- Shared UI is built from shadcn/ui and Tailwind, with reusable layout and form components in src/components.
12. Frontend-to-backend integration
- src/lib/api.ts and src/lib/auth.ts are the main client-side integration points for API access and session/auth handling.
- Protected backend endpoints use JWT bearer tokens, so the frontend is responsible for attaching auth state to requests.
- The frontend structure suggests server-rendered route pages plus client-side form interactions where needed.
13. Operational concerns
- The repo includes rate limiting in the backend, with separate tiers for auth, writes, uploads, and global traffic.
- Environment configuration is centralized in a single root .env, shared across services rather than per package.
- Dockerfiles exist for backend and frontend, and docker-compose.yml orchestrates the local stack end-to-end.
14. Deployment topology
- In local/dev mode, frontend, backend, Postgres, and MinIO are exposed directly.
- In production, Caddy handles routing and automatic TLS certificate management via Let’s Encrypt.
- The deployment model is therefore a containerized multi-service stack with a reverse-proxy edge and separate application/data services.
Main entry points: app.ts App · app Next.js app · client.ts Prisma client · docker-compose.yml Compose stack
Components 20
Backend API
Node.js/Express service with domain modules and shared middleware.
- Server · HTTP entrypoint and app wiring for the backend runtime.
backend/src/server.ts - App · Central Express app composition, middleware stack, and route mounting.
backend/src/app.ts - Auth · Authentication controllers, routes, schemas, and token issuance.
backend/src/modules/auth - Expenses · Draft expense CRUD, receipt upload integration, and currency-aware expense handling.
backend/src/modules/expenses - Reimbursements · Request submission, review, approval, rejection, and note capture.
backend/src/modules/reimbursements - Departments · Department lookups and budget-related data access.
backend/src/modules/departments - Audit · Queryable before/after action records for compliance and traceability.
backend/src/modules/audit - Middleware · Authentication, authorization, validation, upload handling, and error mapping.
backend/src/shared/middleware - Backend utils · Currency conversion, logging, response formatting, and storage helpers.
backend/src/shared/utils
Frontend App
Next.js app router UI for employee and employer workflows.
- Next.js app · App Router frontend for employee, employer, and auth pages.
frontend/src/app - Role pages · Employee expense/reimbursement pages and employer dashboard/request views.
frontend/src/app - UI components · Reusable forms, layout pieces, and shadcn/Tailwind primitives.
frontend/src/components - Client lib · Frontend API wrapper and session/auth handling utilities.
frontend/src/lib
Data Layer
Relational persistence, object storage, and schema/bootstrap assets.
- Prisma client · Typed database access layer used by repositories.
backend/src/prisma/client.ts - Schema · Authoritative relational model for users, expenses, reimbursements, departments, budgets, and audit records.
backend/prisma/schema.prisma - Seed data · Demo and initial records for local development and onboarding.
backend/prisma/seed.ts - PostgreSQL · Primary transactional database for application state.
- MinIO · S3-compatible receipt storage and presigned download target.
Deployment
Container and edge-proxy setup for local and production runs.
- Caddy · Production edge proxy for routing and automatic HTTPS.
Caddyfile - Compose stack · Local end-to-end service wiring for frontend, backend, Postgres, and MinIO.
docker-compose.yml
Connections 27
- Server → App: boots · Server process starts and configures the Express application.
- App → Middleware: uses · App wires cross-cutting middleware into the request pipeline.
- App → Auth: mounts · Auth routes are mounted into the HTTP router.
- App → Expenses: mounts · Expense routes are mounted into the HTTP router.
- App → Reimbursements: mounts · Reimbursement routes are mounted into the HTTP router.
- App → Departments: mounts · Department routes are mounted into the HTTP router.
- App → Audit: mounts · Audit routes are mounted into the HTTP router.
- Auth → Prisma client: reads/writes · Auth service persists and verifies user/session data through Prisma.
- Expenses → Prisma client: reads/writes · Expense repository stores draft and submitted expense records.
- Reimbursements → Prisma client: reads/writes · Reimbursement workflow persists requests and approval state.
- Departments → Prisma client: reads · Department data is primarily query-backed.
- Audit → Prisma client: reads/writes · Audit events are recorded and queried from the database.
- Expenses → MinIO: uploads receipts · Receipt binaries are stored externally and linked to expenses.
- Backend utils → MinIO: presigns · Storage helpers generate limited-lived access URLs.
- Backend utils → PostgreSQL: targets · Database-facing helpers and repositories operate on PostgreSQL.
- Schema → PostgreSQL: models · Prisma schema defines the relational database structure.
- Seed data → PostgreSQL: seeds · Seed script initializes demo/local data in PostgreSQL.
- Next.js app → Role pages: renders · App Router pages compose the user-facing flows.
- Next.js app → UI components: composes · Pages rely on shared UI and layout components.
- Next.js app → Client lib: calls · Frontend pages use API and auth client helpers.
- Client lib → App: API client · Frontend talks to backend endpoints with bearer auth.
- Compose stack → Next.js app: runs · Compose starts the frontend container in local environments.
- Compose stack → Server: runs · Compose starts the backend container in local environments.
- Compose stack → PostgreSQL: provisions · Compose includes the PostgreSQL service.
- Compose stack → MinIO: provisions · Compose includes the MinIO service.
- Caddy → Next.js app: routes to · Caddy forwards browser traffic to the frontend.
- Caddy → Server: routes to · Caddy forwards API traffic to the backend.