# not-rishi/quickpool architecture

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

- Interactive diagram: https://gitdiagram.com/not-rishi/quickpool
- Repository: https://github.com/not-rishi/quickpool

## Overview

1. QuickPool is split into two main runtime applications: a Node/Express backend in `backend/` and an Expo/React Native client in `frontend/`. The backend exposes the business API and admin endpoints; the frontend is the mobile UI that consumes those APIs.

2. The backend entrypoint is `backend/server.js`, with `config/db.js` establishing the database connection. The code is organized in a standard request pipeline: routes map HTTP paths to controllers, controllers implement domain actions, middleware handles auth/error cross-cutting concerns, and models represent persisted records.

3. The domain model is centered on route-based ride pooling. Core entities include `User`, `Route`, `Group`, `Queue`, `Swap`, `RideHistory`, plus incident/exception records like `PanicReport` and `NoShowReport`. This suggests the system tracks users, available routes, group formation, queueing, swaps, and ride outcomes over time.

4. Authentication is OTP-based rather than password-based. `authController`, `OTP` model, `generateOTP`, `generateToken`, and `emailService` indicate a flow where the backend generates a one-time code, emails it to the user, verifies it, then issues a token for subsequent requests.

5. Matching and assignment logic is separated into `services/matchingService.js`, which is the main business-logic boundary beyond basic CRUD. That service likely computes route/group placement and queue decisions, while controllers remain thin orchestration layers.

6. Emergency and exception handling are explicit subsystems. `emergencyRoutes.js` and `emergencyController.js` work with `PanicReport` and `NoShowReport`, indicating a separate path for safety events and absence reporting, distinct from normal route participation.

7. Admin functionality is also isolated. `adminRoutes.js`, `adminController.js`, and `backend/admin.html` imply a lightweight admin interface served from the backend for oversight or manual operations, separate from the mobile user flows.

8. The frontend is organized with Expo Router navigation. `app/(auth)` contains login and OTP verification screens, `app/(tabs)` contains the main authenticated app sections, and dedicated screens such as `create-route.tsx` and `routes/[routeId].tsx` cover route creation and route detail views.

9. Frontend state and API access are split cleanly. `context/auth-context.tsx` manages session/auth state, `utils/storage.ts` handles local persistence, and `services/api.ts`, `services/auth.ts`, and `services/routes.ts` wrap backend calls so UI components do not talk to HTTP directly.

10. Shared data shapes are mirrored on the client in `frontend/types/`, including `group`, `history`, `queue`, `route`, and `user`. This aligns the mobile app with backend models and reduces mismatch between API payloads and UI expectations.

11. The overall request flow is: user action in the mobile app → frontend service layer → backend route/controller → middleware checks → model/service logic → database and/or email side effect → response back to the app. Special-case flows branch off for OTP email verification, incident reporting, and admin operations.

12. The repo also includes architecture support artifacts: `docs/api-contract.md` and `docs/architecture.md` document the intended system behavior, while the screenshots folder and `readme assets` capture the product UX. These are useful reference points when drawing the system diagram but are not runtime components.

Main entry points: [`frontend/app/_layout.tsx`](https://github.com/not-rishi/quickpool/blob/main/frontend/app/_layout.tsx) (App Router), [`frontend/services/api.ts`](https://github.com/not-rishi/quickpool/blob/main/frontend/services/api.ts) (API Clients), [`backend/server.js`](https://github.com/not-rishi/quickpool/blob/main/backend/server.js) (Server), [`docs/architecture.md`](https://github.com/not-rishi/quickpool/blob/main/docs/architecture.md) (Architecture Doc)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_backend_server["Server<br/>entrypoint<br/>[server.js]"]
  node_backend_db[("DB Config<br/>database config<br/>[db.js]")]
  node_backend_routes["API Routes<br/>http routes"]
  node_backend_controllers["Controllers"]
  node_backend_middleware{{"Middleware<br/>cross-cutting"}}
  node_backend_models[("Models")]
  node_backend_matching["Matching Service<br/>business service<br/>[matchingService.js]"]
  node_backend_email["Email Service<br/>notification service<br/>[emailService.js]"]
  node_backend_auth_utils["OTP + Token<br/>auth utils<br/>[generateOTP.js]"]
  node_backend_auth_models[("OTP Record<br/>auth model<br/>[OTP.js]")]
  node_backend_domain_models[("Ride Records<br/>domain models<br/>[Route.js]")]
  node_backend_admin["Admin UI<br/>admin interface<br/>[admin.html]"]
end

subgraph group_frontend["Frontend"]
  node_frontend_nav["App Router<br/>navigation<br/>[_layout.tsx]"]
  node_frontend_auth["Auth Flow<br/>screens<br/>[login.tsx]"]
  node_frontend_tabs["Main Tabs<br/>screens<br/>[index.tsx]"]
  node_frontend_routes["Route Screens<br/>[create-route.tsx]"]
  node_frontend_state["Auth Context<br/>client state<br/>[auth-context.tsx]"]
  node_frontend_api["API Clients<br/>client services<br/>[api.ts]"]
  node_frontend_storage[("Local Storage<br/>persistence<br/>[storage.ts]")]
  node_frontend_types["Shared Types<br/>type defs<br/>[route.ts]"]
end

subgraph group_docs["Docs"]
  node_docs_api["API Contract<br/>documentation<br/>[api-contract.md]"]
  node_docs_arch["Architecture Doc<br/>documentation<br/>[architecture.md]"]
end

node_backend_server -->|"mounts"| node_backend_routes
node_backend_server -->|"connects"| node_backend_db
node_backend_routes -->|"dispatches"| node_backend_controllers
node_backend_controllers -.->|"guards"| node_backend_middleware
node_backend_controllers -->|"reads/writes"| node_backend_models
node_backend_controllers -->|"delegates"| node_backend_matching
node_backend_controllers -->|"sends mail"| node_backend_email
node_backend_auth_utils -->|"supports"| node_backend_email
node_backend_controllers -->|"issues tokens"| node_backend_auth_utils
node_backend_models -.->|"includes"| node_backend_auth_models
node_backend_models -.->|"includes"| node_backend_domain_models
node_backend_routes -.->|"serves"| node_backend_admin
node_frontend_nav -->|"navigates"| node_frontend_auth
node_frontend_nav -->|"navigates"| node_frontend_tabs
node_frontend_nav -->|"navigates"| node_frontend_routes
node_frontend_auth -->|"updates"| node_frontend_state
node_frontend_state -->|"persists"| node_frontend_storage
node_frontend_tabs -->|"fetches"| node_frontend_api
node_frontend_routes -->|"fetches"| node_frontend_api
node_frontend_api -->|"calls"| node_backend_routes
node_frontend_types -.->|"types"| node_frontend_api
node_docs_api -.->|"describes"| node_backend_routes
node_docs_arch -.->|"describes"| node_backend_server
node_docs_arch -.->|"describes"| node_frontend_nav

click node_backend_server "https://github.com/not-rishi/quickpool/blob/main/backend/server.js"
click node_backend_db "https://github.com/not-rishi/quickpool/blob/main/backend/config/db.js"
click node_backend_matching "https://github.com/not-rishi/quickpool/blob/main/backend/services/matchingService.js"
click node_backend_email "https://github.com/not-rishi/quickpool/blob/main/backend/services/emailService.js"
click node_backend_auth_utils "https://github.com/not-rishi/quickpool/blob/main/backend/utils/generateOTP.js"
click node_backend_auth_models "https://github.com/not-rishi/quickpool/blob/main/backend/models/OTP.js"
click node_backend_domain_models "https://github.com/not-rishi/quickpool/blob/main/backend/models/Route.js"
click node_backend_admin "https://github.com/not-rishi/quickpool/blob/main/backend/admin.html"
click node_frontend_nav "https://github.com/not-rishi/quickpool/blob/main/frontend/app/_layout.tsx"
click node_frontend_auth "https://github.com/not-rishi/quickpool/blob/main/frontend/app/(auth)/login.tsx"
click node_frontend_tabs "https://github.com/not-rishi/quickpool/blob/main/frontend/app/(tabs)/index.tsx"
click node_frontend_routes "https://github.com/not-rishi/quickpool/blob/main/frontend/app/create-route.tsx"
click node_frontend_state "https://github.com/not-rishi/quickpool/blob/main/frontend/context/auth-context.tsx"
click node_frontend_api "https://github.com/not-rishi/quickpool/blob/main/frontend/services/api.ts"
click node_frontend_storage "https://github.com/not-rishi/quickpool/blob/main/frontend/utils/storage.ts"
click node_frontend_types "https://github.com/not-rishi/quickpool/blob/main/frontend/types/route.ts"
click node_docs_api "https://github.com/not-rishi/quickpool/blob/main/docs/api-contract.md"
click node_docs_arch "https://github.com/not-rishi/quickpool/blob/main/docs/architecture.md"

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_server,node_backend_db,node_backend_routes,node_backend_controllers,node_backend_middleware,node_backend_models,node_backend_matching,node_backend_email,node_backend_auth_utils,node_backend_auth_models,node_backend_domain_models,node_backend_admin toneBlue
class node_frontend_nav,node_frontend_auth,node_frontend_tabs,node_frontend_routes,node_frontend_state,node_frontend_api,node_frontend_storage,node_frontend_types toneAmber
class node_docs_api,node_docs_arch toneMint
```

## Components

### Backend

Node/Express API, business logic, and persistence

- [Server](https://github.com/not-rishi/quickpool/blob/main/backend/server.js): entrypoint · Bootstraps the API runtime and mounts routes · `backend/server.js`
- [DB Config](https://github.com/not-rishi/quickpool/blob/main/backend/config/db.js): database config · Initializes the database connection · `backend/config/db.js`
- **API Routes**: http routes · Request boundaries for auth, users, groups, routes, emergencies, and admin
- **Controllers**: domain controllers · Orchestrate business actions for auth, users, groups, routes, emergencies, and admin
- **Middleware**: cross-cutting · Auth and error handling around protected requests
- **Models**: domain models · Persistent entities for users, routes, queues, swaps, history, and reports
- [Matching Service](https://github.com/not-rishi/quickpool/blob/main/backend/services/matchingService.js): business service · Route and group placement, queue decisions, and assignment logic · `backend/services/matchingService.js`
- [Email Service](https://github.com/not-rishi/quickpool/blob/main/backend/services/emailService.js): notification service · Sends OTP and related mail flows · `backend/services/emailService.js`
- [OTP + Token](https://github.com/not-rishi/quickpool/blob/main/backend/utils/generateOTP.js): auth utils · Generates one-time codes and session tokens · `backend/utils/generateOTP.js`
- [OTP Record](https://github.com/not-rishi/quickpool/blob/main/backend/models/OTP.js): auth model · Stores OTP verification data · `backend/models/OTP.js`
- [Ride Records](https://github.com/not-rishi/quickpool/blob/main/backend/models/Route.js): domain models · Core ride-pooling entities: users, routes, groups, queues, swaps, history, and incident reports · `backend/models/Route.js`
- [Admin UI](https://github.com/not-rishi/quickpool/blob/main/backend/admin.html): admin interface · Backend-served HTML for oversight and manual operations · `backend/admin.html`

### Frontend

Expo/React Native mobile app and client state

- [App Router](https://github.com/not-rishi/quickpool/blob/main/frontend/app/_layout.tsx): navigation · Expo Router layout and screen composition · `frontend/app/_layout.tsx`
- [Auth Flow](https://github.com/not-rishi/quickpool/blob/main/frontend/app/(auth)/login.tsx): screens · Login and OTP verification screens · `frontend/app/(auth)/login.tsx`
- [Main Tabs](https://github.com/not-rishi/quickpool/blob/main/frontend/app/(tabs)/index.tsx): screens · Authenticated app sections for group, history, profile, and home · `frontend/app/(tabs)/index.tsx`
- [Route Screens](https://github.com/not-rishi/quickpool/blob/main/frontend/app/create-route.tsx): screens · Create and inspect ride routes · `frontend/app/create-route.tsx`
- [Auth Context](https://github.com/not-rishi/quickpool/blob/main/frontend/context/auth-context.tsx): client state · Session and authentication state management · `frontend/context/auth-context.tsx`
- [API Clients](https://github.com/not-rishi/quickpool/blob/main/frontend/services/api.ts): client services · Typed wrappers around backend HTTP calls for auth and routes · `frontend/services/api.ts`
- [Local Storage](https://github.com/not-rishi/quickpool/blob/main/frontend/utils/storage.ts): persistence · Persists client session and app data on-device · `frontend/utils/storage.ts`
- [Shared Types](https://github.com/not-rishi/quickpool/blob/main/frontend/types/route.ts): type defs · Client-side shapes for users, routes, groups, queues, and history · `frontend/types/route.ts`

### Docs

Architecture and API reference materials

- [API Contract](https://github.com/not-rishi/quickpool/blob/main/docs/api-contract.md): documentation · System behavior and endpoint contract reference · `docs/api-contract.md`
- [Architecture Doc](https://github.com/not-rishi/quickpool/blob/main/docs/architecture.md): documentation · High-level design and component overview · `docs/architecture.md`

## Connections

- Server → API Routes: mounts · Server wires route modules into the HTTP app
- Server → DB Config: connects · Boot sequence establishes database connectivity
- API Routes → Controllers: dispatches · Routes hand requests to domain controllers
- Controllers → Middleware: guards · Protected paths rely on auth and error handling
- Controllers → Models: reads/writes · Controllers persist and fetch domain state
- Controllers → Matching Service: delegates · Route and group assignment uses matching logic
- Controllers → Email Service: sends mail · Auth flows trigger OTP email delivery
- OTP + Token → Email Service: supports · OTP generation feeds the email verification flow
- Controllers → OTP + Token: issues tokens · Authentication verifies OTP and returns session tokens
- Models → OTP Record: includes · OTP is part of the backend persistence layer
- Models → Ride Records: includes · Core ride-pooling and incident entities
- API Routes → Admin UI: serves · Admin endpoints back the lightweight admin interface
- App Router → Auth Flow: navigates · Auth screens are composed in the app router
- App Router → Main Tabs: navigates · Main authenticated sections are mounted after login
- App Router → Route Screens: navigates · Route creation and detail screens are part of the app flow
- Auth Flow → Auth Context: updates · Login and OTP screens update session state
- Auth Context → Local Storage: persists · Auth context stores session data locally
- Main Tabs → API Clients: fetches · Authenticated views load backend data through API clients
- Route Screens → API Clients: fetches · Route screens call backend route APIs
- API Clients → API Routes: calls · Mobile client talks to backend HTTP endpoints
- Shared Types → API Clients: types · Shared client shapes align request and response payloads
- API Contract → API Routes: describes · API contract documents backend endpoints
- Architecture Doc → Server: describes · Architecture docs outline the runtime structure
- Architecture Doc → App Router: describes · Architecture docs cover the client navigation structure
