# ipushpie/expense-reimbursement-service architecture

> Architecture diagram of the GitHub repository ipushpie/expense-reimbursement-service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ipushpie/expense-reimbursement-service
- Repository: https://github.com/ipushpie/expense-reimbursement-service

## Overview

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: [`backend/src/app.ts`](https://github.com/ipushpie/expense-reimbursement-service/blob/main/backend/src/app.ts) (App), [`frontend/src/app`](https://github.com/ipushpie/expense-reimbursement-service/tree/main/frontend/src/app) (Next.js app), [`backend/src/prisma/client.ts`](https://github.com/ipushpie/expense-reimbursement-service/blob/main/backend/src/prisma/client.ts) (Prisma client), [`docker-compose.yml`](https://github.com/ipushpie/expense-reimbursement-service/blob/main/docker-compose.yml) (Compose stack)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_backend["Backend API"]
  node_node_server["Server<br/>Express bootstrap<br/>[server.ts]"]
  node_node_app["App<br/>Middleware/router setup<br/>[app.ts]"]
  node_node_auth["Auth<br/>Login/session module"]
  node_node_expenses["Expenses<br/>Expense workflow"]
  node_node_reimbursements["Reimbursements<br/>Approval workflow"]
  node_node_departments["Departments<br/>Org data"]
  node_node_audit["Audit<br/>Change history"]
  node_node_middleware["Middleware<br/>Cross-cutting guards"]
  node_node_utils["Backend utils<br/>Shared helpers"]
end

subgraph group_group_frontend["Frontend App"]
  node_node_next["Next.js app<br/>React frontend"]
  node_node_fe_pages["Role pages<br/>Route screens"]
  node_node_fe_components["UI components<br/>Shared UI"]
  node_node_fe_lib["Client lib<br/>API/auth client"]
end

subgraph group_group_data["Data Layer"]
  node_node_prisma_client[("Prisma client<br/>DB client<br/>[client.ts]")]
  node_node_schema["Schema<br/>[schema.prisma]"]
  node_node_seed["Seed data<br/>Bootstrap data<br/>[seed.ts]"]
  node_node_pg[("PostgreSQL<br/>Relational store")]
  node_node_minio[("MinIO<br/>Object storage")]
end

subgraph group_group_deploy["Deployment"]
  node_node_caddy["Caddy<br/>TLS reverse proxy"]
  node_node_compose["Compose stack<br/>Container orchestration<br/>[docker-compose.yml]"]
end

node_node_server -->|"boots"| node_node_app
node_node_app -->|"uses"| node_node_middleware
node_node_app -->|"mounts"| node_node_auth
node_node_app -->|"mounts"| node_node_expenses
node_node_app -->|"mounts"| node_node_reimbursements
node_node_app -->|"mounts"| node_node_departments
node_node_app -->|"mounts"| node_node_audit
node_node_auth -->|"reads/writes"| node_node_prisma_client
node_node_expenses -->|"reads/writes"| node_node_prisma_client
node_node_reimbursements -->|"reads/writes"| node_node_prisma_client
node_node_departments -->|"reads"| node_node_prisma_client
node_node_audit -->|"reads/writes"| node_node_prisma_client
node_node_expenses -->|"uploads receipts"| node_node_minio
node_node_utils -->|"presigns"| node_node_minio
node_node_utils -->|"targets"| node_node_pg
node_node_schema -->|"models"| node_node_pg
node_node_seed -->|"seeds"| node_node_pg
node_node_next -->|"renders"| node_node_fe_pages
node_node_next -->|"composes"| node_node_fe_components
node_node_next -->|"calls"| node_node_fe_lib
node_node_fe_lib -->|"API client"| node_node_app
node_node_compose -->|"runs"| node_node_next
node_node_compose -->|"runs"| node_node_server
node_node_compose -->|"provisions"| node_node_pg
node_node_compose -->|"provisions"| node_node_minio
node_node_caddy -->|"routes to"| node_node_next
node_node_caddy -->|"routes to"| node_node_server

click node_node_server "https://github.com/ipushpie/expense-reimbursement-service/blob/main/backend/src/server.ts"
click node_node_app "https://github.com/ipushpie/expense-reimbursement-service/blob/main/backend/src/app.ts"
click node_node_auth "https://github.com/ipushpie/expense-reimbursement-service/tree/main/backend/src/modules/auth"
click node_node_expenses "https://github.com/ipushpie/expense-reimbursement-service/tree/main/backend/src/modules/expenses"
click node_node_reimbursements "https://github.com/ipushpie/expense-reimbursement-service/tree/main/backend/src/modules/reimbursements"
click node_node_departments "https://github.com/ipushpie/expense-reimbursement-service/tree/main/backend/src/modules/departments"
click node_node_audit "https://github.com/ipushpie/expense-reimbursement-service/tree/main/backend/src/modules/audit"
click node_node_middleware "https://github.com/ipushpie/expense-reimbursement-service/tree/main/backend/src/shared/middleware"
click node_node_utils "https://github.com/ipushpie/expense-reimbursement-service/tree/main/backend/src/shared/utils"
click node_node_prisma_client "https://github.com/ipushpie/expense-reimbursement-service/blob/main/backend/src/prisma/client.ts"
click node_node_schema "https://github.com/ipushpie/expense-reimbursement-service/blob/main/backend/prisma/schema.prisma"
click node_node_seed "https://github.com/ipushpie/expense-reimbursement-service/blob/main/backend/prisma/seed.ts"
click node_node_next "https://github.com/ipushpie/expense-reimbursement-service/tree/main/frontend/src/app"
click node_node_fe_pages "https://github.com/ipushpie/expense-reimbursement-service/tree/main/frontend/src/app"
click node_node_fe_components "https://github.com/ipushpie/expense-reimbursement-service/tree/main/frontend/src/components"
click node_node_fe_lib "https://github.com/ipushpie/expense-reimbursement-service/tree/main/frontend/src/lib"
click node_node_caddy "https://github.com/ipushpie/expense-reimbursement-service/tree/main/Caddyfile"
click node_node_compose "https://github.com/ipushpie/expense-reimbursement-service/blob/main/docker-compose.yml"

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_node_server,node_node_app,node_node_auth,node_node_expenses,node_node_reimbursements,node_node_departments,node_node_audit,node_node_middleware,node_node_utils toneBlue
class node_node_next,node_node_fe_pages,node_node_fe_components,node_node_fe_lib toneAmber
class node_node_prisma_client,node_node_schema,node_node_seed,node_node_pg,node_node_minio toneMint
class node_node_caddy,node_node_compose toneRose
```

## Components

### Backend API

Node.js/Express service with domain modules and shared middleware.

- [Server](https://github.com/ipushpie/expense-reimbursement-service/blob/main/backend/src/server.ts): Express bootstrap · HTTP entrypoint and app wiring for the backend runtime. · `backend/src/server.ts`
- [App](https://github.com/ipushpie/expense-reimbursement-service/blob/main/backend/src/app.ts): Middleware/router setup · Central Express app composition, middleware stack, and route mounting. · `backend/src/app.ts`
- [Auth](https://github.com/ipushpie/expense-reimbursement-service/tree/main/backend/src/modules/auth): Login/session module · Authentication controllers, routes, schemas, and token issuance. · `backend/src/modules/auth`
- [Expenses](https://github.com/ipushpie/expense-reimbursement-service/tree/main/backend/src/modules/expenses): Expense workflow · Draft expense CRUD, receipt upload integration, and currency-aware expense handling. · `backend/src/modules/expenses`
- [Reimbursements](https://github.com/ipushpie/expense-reimbursement-service/tree/main/backend/src/modules/reimbursements): Approval workflow · Request submission, review, approval, rejection, and note capture. · `backend/src/modules/reimbursements`
- [Departments](https://github.com/ipushpie/expense-reimbursement-service/tree/main/backend/src/modules/departments): Org data · Department lookups and budget-related data access. · `backend/src/modules/departments`
- [Audit](https://github.com/ipushpie/expense-reimbursement-service/tree/main/backend/src/modules/audit): Change history · Queryable before/after action records for compliance and traceability. · `backend/src/modules/audit`
- [Middleware](https://github.com/ipushpie/expense-reimbursement-service/tree/main/backend/src/shared/middleware): Cross-cutting guards · Authentication, authorization, validation, upload handling, and error mapping. · `backend/src/shared/middleware`
- [Backend utils](https://github.com/ipushpie/expense-reimbursement-service/tree/main/backend/src/shared/utils): Shared helpers · 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](https://github.com/ipushpie/expense-reimbursement-service/tree/main/frontend/src/app): React frontend · App Router frontend for employee, employer, and auth pages. · `frontend/src/app`
- [Role pages](https://github.com/ipushpie/expense-reimbursement-service/tree/main/frontend/src/app): Route screens · Employee expense/reimbursement pages and employer dashboard/request views. · `frontend/src/app`
- [UI components](https://github.com/ipushpie/expense-reimbursement-service/tree/main/frontend/src/components): Shared UI · Reusable forms, layout pieces, and shadcn/Tailwind primitives. · `frontend/src/components`
- [Client lib](https://github.com/ipushpie/expense-reimbursement-service/tree/main/frontend/src/lib): API/auth client · Frontend API wrapper and session/auth handling utilities. · `frontend/src/lib`

### Data Layer

Relational persistence, object storage, and schema/bootstrap assets.

- [Prisma client](https://github.com/ipushpie/expense-reimbursement-service/blob/main/backend/src/prisma/client.ts): DB client · Typed database access layer used by repositories. · `backend/src/prisma/client.ts`
- [Schema](https://github.com/ipushpie/expense-reimbursement-service/blob/main/backend/prisma/schema.prisma): Prisma model schema · Authoritative relational model for users, expenses, reimbursements, departments, budgets, and audit records. · `backend/prisma/schema.prisma`
- [Seed data](https://github.com/ipushpie/expense-reimbursement-service/blob/main/backend/prisma/seed.ts): Bootstrap data · Demo and initial records for local development and onboarding. · `backend/prisma/seed.ts`
- **PostgreSQL**: Relational store · Primary transactional database for application state.
- **MinIO**: Object storage · S3-compatible receipt storage and presigned download target.

### Deployment

Container and edge-proxy setup for local and production runs.

- [Caddy](https://github.com/ipushpie/expense-reimbursement-service/tree/main/Caddyfile): TLS reverse proxy · Production edge proxy for routing and automatic HTTPS. · `Caddyfile`
- [Compose stack](https://github.com/ipushpie/expense-reimbursement-service/blob/main/docker-compose.yml): Container orchestration · Local end-to-end service wiring for frontend, backend, Postgres, and MinIO. · `docker-compose.yml`

## Connections

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