# ankushvarma-ui/walletx architecture

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

- Interactive diagram: https://gitdiagram.com/ankushvarma-ui/walletx
- Repository: https://github.com/ankushvarma-ui/walletx

## Overview

This backend is an Express API for account authentication, user profiles, and wallet creation. Requests enter through the versioned routes; authentication and profile/wallet handlers delegate domain work to services, which use PostgreSQL models and a Redis-backed user cache. Authentication covers registration, login, token refresh, and logout; wallet creation validates the user and prevents duplicate wallets. The graph follows documented imports and sampled calls; some route and service implementations were not excerpted, so their relationships rely on SOURCE INDEX references.

Main entry points: [`backend/src/app.js`](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/app.js) (Express app), [`backend/src/middleware/auth.middleware.js`](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/middleware/auth.middleware.js) (Auth middleware), [`backend/src/models/user.model.js`](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/models/user.model.js) (User records), [`backend/src/services/auth.service.js`](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/services/auth.service.js) (Auth workflows)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and routing"]
  node_app["Express app<br/>[app.js]"]
  node_auth_routes["Auth routes<br/>[auth.routes.js]"]
  node_user_routes["User routes<br/>[user.routes.js]"]
  node_wallet_routes["Wallet routes<br/>[wallet.routes.js]"]
  node_error_middleware["Error handling"]
  node_async_handler["Async wrapper<br/>[asyncHandler.js]"]
end

subgraph group_identity["Identity and users"]
  node_auth_middleware["Auth middleware<br/>[auth.middleware.js]"]
  node_auth_controller["Auth handlers<br/>[auth.controller.js]"]
  node_auth_service["Auth workflows<br/>[auth.service.js]"]
  node_user_controller["Profile handler<br/>[user.controller.js]"]
  node_user_service["User workflows<br/>[user.service.js]"]
  node_user_cache["User cache service"]
  node_jwt_utils["JWT utilities<br/>[jwt.js]"]
end

subgraph group_wallet["Wallets"]
  node_wallet_controller["Wallet handler"]
  node_wallet_service["Wallet workflows<br/>[wallet.service.js]"]
end

subgraph group_data["Persistence and cache"]
  node_user_model["User records<br/>[user.model.js]"]
  node_wallet_model["Wallet records<br/>[wallet.model.js]"]
  node_postgres_pool["PostgreSQL pool<br/>[db.js]"]
  node_redis_config["Redis client<br/>[redis.js]"]
end

node_client(("API client"))
node_postgres[("PostgreSQL")]
node_redis[("Redis")]

node_client -->|"sends requests"| node_app
node_app -->|"mounts auth"| node_auth_routes
node_app -->|"mounts users"| node_user_routes
node_app -->|"mounts wallet"| node_wallet_routes
node_app -->|"registers errors"| node_error_middleware
node_auth_routes -->|"dispatches"| node_auth_controller
node_auth_routes -->|"protects logout"| node_auth_middleware
node_user_routes -->|"dispatches"| node_user_controller
node_user_routes -->|"protects routes"| node_auth_middleware
node_wallet_routes -->|"dispatches"| node_wallet_controller
node_wallet_routes -->|"protects routes"| node_auth_middleware
node_auth_controller -->|"calls workflows"| node_auth_service
node_user_controller -->|"gets profile"| node_user_service
node_wallet_controller -->|"calls workflows"| node_wallet_service
node_auth_controller -->|"wraps handlers"| node_async_handler
node_user_controller -->|"wraps handler"| node_async_handler
node_wallet_controller -->|"wraps handler"| node_async_handler
node_auth_service -->|"reads and creates"| node_user_model
node_auth_service -->|"updates cache"| node_user_cache
node_auth_service -->|"generates tokens"| node_jwt_utils
node_auth_middleware -->|"checks cache"| node_user_cache
node_auth_middleware -->|"loads user"| node_user_model
node_user_service -->|"uses records"| node_user_model
node_user_service -->|"uses cache"| node_user_cache
node_wallet_service -->|"validates user"| node_user_model
node_wallet_service -->|"checks and creates"| node_wallet_model
node_user_model -->|"queries"| node_postgres_pool
node_wallet_model -->|"uses pool"| node_postgres_pool
node_postgres_pool -->|"connects"| node_postgres
node_user_cache -->|"uses client"| node_redis_config
node_redis_config -.->|"connects"| node_redis

click node_app "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/app.js"
click node_auth_routes "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/routes/auth.routes.js"
click node_user_routes "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/routes/user.routes.js"
click node_wallet_routes "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/routes/wallet.routes.js"
click node_error_middleware "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/middleware/error.middleware.js"
click node_auth_middleware "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/middleware/auth.middleware.js"
click node_auth_controller "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/controllers/auth.controller.js"
click node_auth_service "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/services/auth.service.js"
click node_user_controller "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/controllers/user.controller.js"
click node_user_service "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/services/user.service.js"
click node_user_model "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/models/user.model.js"
click node_wallet_controller "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/controllers/wallet.controller.js"
click node_wallet_service "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/services/wallet.service.js"
click node_wallet_model "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/models/wallet.model.js"
click node_postgres_pool "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/config/db.js"
click node_user_cache "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/services/userCache.service.js"
click node_redis_config "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/config/redis.js"
click node_jwt_utils "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/utils/jwt.js"
click node_async_handler "https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/utils/asyncHandler.js"

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_app,node_auth_routes,node_user_routes,node_wallet_routes,node_error_middleware,node_async_handler,node_client toneBlue
class node_auth_middleware,node_auth_controller,node_auth_service,node_user_controller,node_user_service,node_user_cache,node_jwt_utils,node_postgres,node_redis toneAmber
class node_wallet_controller,node_wallet_service toneMint
class node_user_model,node_wallet_model,node_postgres_pool,node_redis_config toneRose
```

## Components

### API and routing

- [Express app](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/app.js): `backend/src/app.js`
- [Auth routes](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/routes/auth.routes.js): `backend/src/routes/auth.routes.js`
- [User routes](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/routes/user.routes.js): `backend/src/routes/user.routes.js`
- [Wallet routes](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/routes/wallet.routes.js): `backend/src/routes/wallet.routes.js`
- [Error handling](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/middleware/error.middleware.js): `backend/src/middleware/error.middleware.js`
- [Async wrapper](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/utils/asyncHandler.js): `backend/src/utils/asyncHandler.js`

### Identity and users

- [Auth middleware](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/middleware/auth.middleware.js): `backend/src/middleware/auth.middleware.js`
- [Auth handlers](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/controllers/auth.controller.js): `backend/src/controllers/auth.controller.js`
- [Auth workflows](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/services/auth.service.js): `backend/src/services/auth.service.js`
- [Profile handler](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/controllers/user.controller.js): `backend/src/controllers/user.controller.js`
- [User workflows](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/services/user.service.js): `backend/src/services/user.service.js`
- [User cache service](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/services/userCache.service.js): `backend/src/services/userCache.service.js`
- [JWT utilities](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/utils/jwt.js): `backend/src/utils/jwt.js`

### Wallets

- [Wallet handler](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/controllers/wallet.controller.js): `backend/src/controllers/wallet.controller.js`
- [Wallet workflows](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/services/wallet.service.js): `backend/src/services/wallet.service.js`

### Persistence and cache

- [User records](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/models/user.model.js): `backend/src/models/user.model.js`
- [Wallet records](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/models/wallet.model.js): `backend/src/models/wallet.model.js`
- [PostgreSQL pool](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/config/db.js): `backend/src/config/db.js`
- [Redis client](https://github.com/ankushvarma-ui/walletx/blob/main/backend/src/config/redis.js): `backend/src/config/redis.js`

### Other components

- **API client**
- **PostgreSQL**
- **Redis**

## Connections

- API client → Express app: sends requests (evidence: `backend/src/app.js`)
- Express app → Auth routes: mounts auth (evidence: `backend/src/app.js`)
- Express app → User routes: mounts users (evidence: `backend/src/app.js`)
- Express app → Wallet routes: mounts wallet (evidence: `backend/src/app.js`)
- Express app → Error handling: registers errors (evidence: `backend/src/app.js`)
- Auth routes → Auth handlers: dispatches (evidence: `backend/src/routes/auth.routes.js`)
- Auth routes → Auth middleware: protects logout (evidence: `backend/src/routes/auth.routes.js`)
- User routes → Profile handler: dispatches (evidence: `backend/src/routes/user.routes.js`)
- User routes → Auth middleware: protects routes (evidence: `backend/src/routes/user.routes.js`)
- Wallet routes → Wallet handler: dispatches (evidence: `backend/src/routes/wallet.routes.js`)
- Wallet routes → Auth middleware: protects routes (evidence: `backend/src/routes/wallet.routes.js`)
- Auth handlers → Auth workflows: calls workflows (evidence: `backend/src/controllers/auth.controller.js`)
- Profile handler → User workflows: gets profile (evidence: `backend/src/controllers/user.controller.js`)
- Wallet handler → Wallet workflows: calls workflows (evidence: `backend/src/controllers/wallet.controller.js`)
- Auth handlers → Async wrapper: wraps handlers (evidence: `backend/src/controllers/auth.controller.js`)
- Profile handler → Async wrapper: wraps handler (evidence: `backend/src/controllers/user.controller.js`)
- Wallet handler → Async wrapper: wraps handler (evidence: `backend/src/controllers/wallet.controller.js`)
- Auth workflows → User records: reads and creates (evidence: `backend/src/services/auth.service.js`)
- Auth workflows → User cache service: updates cache (evidence: `backend/src/services/auth.service.js`)
- Auth workflows → JWT utilities: generates tokens (evidence: `backend/src/services/auth.service.js`)
- Auth middleware → User cache service: checks cache (evidence: `backend/src/middleware/auth.middleware.js`)
- Auth middleware → User records: loads user (evidence: `backend/src/middleware/auth.middleware.js`)
- User workflows → User records: uses records (evidence: `backend/src/services/user.service.js`)
- User workflows → User cache service: uses cache (evidence: `backend/src/services/user.service.js`)
- Wallet workflows → User records: validates user (evidence: `backend/src/services/wallet.service.js`)
- Wallet workflows → Wallet records: checks and creates (evidence: `backend/src/services/wallet.service.js`)
- User records → PostgreSQL pool: queries (evidence: `backend/src/models/user.model.js`)
- Wallet records → PostgreSQL pool: uses pool (evidence: `backend/src/models/wallet.model.js`)
- PostgreSQL pool → PostgreSQL: connects (evidence: `backend/src/config/db.js`)
- User cache service → Redis client: uses client (evidence: `backend/src/services/userCache.service.js`)
- Redis client → Redis: connects
