# 2001sheheryar-sa/splitwise-pk architecture

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

- Interactive diagram: https://gitdiagram.com/2001sheheryar-sa/splitwise-pk
- Repository: https://github.com/2001sheheryar-sa/splitwise-pk

## Overview

This is a Laravel API for shared-expense groups: users register or log in, create groups and manage members, record split expenses, then create settlements against outstanding balances. The API controllers own these operations and delegate domain work to services; MongoDB-backed models hold users, groups, expenses, and settlements. The README documents equal, exact, and percentage splits and balance-ledger updates. Some routes and supporting modules are unsampled, so uncertain links are omitted rather than inferred.

Main entry points: [`app/Services/ExpenseService.php`](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Services/ExpenseService.php) (Expense service), [`app/Http/Controllers/AuthController.php`](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Http/Controllers/AuthController.php) (Authentication), [`app/Http/Controllers/GroupController.php`](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Http/Controllers/GroupController.php) (Group API), [`app/Services/GroupService.php`](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Services/GroupService.php) (Group service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and auth"]
  node_api_routes["API routes<br/>[api.php]"]
  node_auth_routes["Auth routes<br/>[auth.php]"]
  node_auth_controller["Authentication<br/>[AuthController.php]"]
  node_auth_middleware["Token middleware<br/>[AuthToken.php]"]
  node_token_service["Token service<br/>[TokenService.php]"]
  node_registration["Registration service"]
end

subgraph group_groups["Group management"]
  node_group_controller["Group API"]
  node_group_service["Group service<br/>[GroupService.php]"]
  node_group_policy["Group policy<br/>[GroupPolicy.php]"]
end

subgraph group_ledger["Expenses and settlement"]
  node_expense_controller["Expense API"]
  node_expense_service["Expense service<br/>[ExpenseService.php]"]
  node_settlement_controller["Settlement API"]
  node_settlement_service["Settlement service"]
end

subgraph group_data["Domain data"]
  node_user_model["User model<br/>[User.php]"]
  node_token_model["User token<br/>[UserToken.php]"]
  node_group_model["Group model<br/>[Groups.php]"]
  node_expense_model["Expense model<br/>[Expense.php]"]
  node_settlement_model["Settlement model<br/>[Settlements.php]"]
end

node_user(("User"))
node_mongo[("MongoDB")]

node_user -->|"requests auth"| node_auth_routes
node_auth_routes -->|"routes to"| node_auth_controller
node_api_routes -->|"loads routes"| node_auth_routes
node_auth_controller -->|"registers with"| node_registration
node_auth_controller -->|"issues tokens"| node_token_service
node_auth_controller -->|"looks up user"| node_user_model
node_auth_middleware -->|"checks token"| node_token_model
node_api_routes -->|"registers middleware"| node_auth_middleware
node_user -->|"manages groups"| node_group_controller
node_group_controller -->|"delegates changes"| node_group_service
node_group_controller -->|"requests balances"| node_expense_service
node_group_service -->|"creates and updates"| node_group_model
node_group_policy -->|"authorizes access"| node_group_model
node_expense_controller -->|"delegates expenses"| node_expense_service
node_user -->|"records expenses"| node_expense_controller
node_expense_service -->|"creates and reads"| node_expense_model
node_expense_service -->|"reads settlements"| node_settlement_model
node_settlement_controller -->|"gets balances"| node_expense_service
node_settlement_controller -->|"validates and delegates"| node_settlement_service
node_user -->|"records settlements"| node_settlement_controller
node_settlement_service -->|"creates and updates"| node_settlement_model
node_group_service -->|"transacts on"| node_mongo
node_expense_service -->|"transacts on"| node_mongo
node_group_model -->|"relates members"| node_user_model

click node_api_routes "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/routes/api.php"
click node_auth_routes "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/routes/Api/auth.php"
click node_auth_controller "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Http/Controllers/AuthController.php"
click node_auth_middleware "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Http/Middleware/AuthToken.php"
click node_token_service "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Services/TokenService.php"
click node_registration "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Services/RegistrationService.php"
click node_group_controller "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Http/Controllers/GroupController.php"
click node_group_service "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Services/GroupService.php"
click node_group_policy "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Policies/GroupPolicy.php"
click node_expense_controller "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Http/Controllers/ExpenseController.php"
click node_expense_service "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Services/ExpenseService.php"
click node_settlement_controller "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Http/Controllers/SettlementController.php"
click node_settlement_service "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Services/SettlementService.php"
click node_user_model "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Models/User.php"
click node_token_model "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Models/UserToken.php"
click node_group_model "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Models/Groups.php"
click node_expense_model "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Models/Expense.php"
click node_settlement_model "https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Models/Settlements.php"

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_api_routes,node_auth_routes,node_auth_controller,node_auth_middleware,node_token_service,node_registration,node_user toneBlue
class node_group_controller,node_group_service,node_group_policy,node_mongo toneAmber
class node_expense_controller,node_expense_service,node_settlement_controller,node_settlement_service toneMint
class node_user_model,node_token_model,node_group_model,node_expense_model,node_settlement_model toneRose
```

## Components

### API and auth

- [API routes](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/routes/api.php): `routes/api.php`
- [Auth routes](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/routes/Api/auth.php): `routes/Api/auth.php`
- [Authentication](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Http/Controllers/AuthController.php): `app/Http/Controllers/AuthController.php`
- [Token middleware](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Http/Middleware/AuthToken.php): `app/Http/Middleware/AuthToken.php`
- [Token service](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Services/TokenService.php): `app/Services/TokenService.php`
- [Registration service](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Services/RegistrationService.php): `app/Services/RegistrationService.php`

### Group management

- [Group API](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Http/Controllers/GroupController.php): `app/Http/Controllers/GroupController.php`
- [Group service](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Services/GroupService.php): `app/Services/GroupService.php`
- [Group policy](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Policies/GroupPolicy.php): `app/Policies/GroupPolicy.php`

### Expenses and settlement

- [Expense API](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Http/Controllers/ExpenseController.php): `app/Http/Controllers/ExpenseController.php`
- [Expense service](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Services/ExpenseService.php): `app/Services/ExpenseService.php`
- [Settlement API](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Http/Controllers/SettlementController.php): `app/Http/Controllers/SettlementController.php`
- [Settlement service](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Services/SettlementService.php): `app/Services/SettlementService.php`

### Domain data

- [User model](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Models/User.php): `app/Models/User.php`
- [User token](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Models/UserToken.php): `app/Models/UserToken.php`
- [Group model](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Models/Groups.php): `app/Models/Groups.php`
- [Expense model](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Models/Expense.php): `app/Models/Expense.php`
- [Settlement model](https://github.com/2001sheheryar-sa/splitwise-pk/blob/main/app/Models/Settlements.php): `app/Models/Settlements.php`

### Other components

- **User**
- **MongoDB**

## Connections

- User → Auth routes: requests auth
- Auth routes → Authentication: routes to (evidence: `routes/Api/auth.php`)
- API routes → Auth routes: loads routes
- Authentication → Registration service: registers with (evidence: `app/Http/Controllers/AuthController.php`)
- Authentication → Token service: issues tokens (evidence: `app/Http/Controllers/AuthController.php`)
- Authentication → User model: looks up user (evidence: `app/Http/Controllers/AuthController.php`)
- Token middleware → User token: checks token (evidence: `app/Http/Middleware/AuthToken.php`)
- API routes → Token middleware: registers middleware
- User → Group API: manages groups
- Group API → Group service: delegates changes (evidence: `app/Http/Controllers/GroupController.php`)
- Group API → Expense service: requests balances (evidence: `app/Http/Controllers/GroupController.php`)
- Group service → Group model: creates and updates (evidence: `app/Services/GroupService.php`)
- Group policy → Group model: authorizes access (evidence: `app/Policies/GroupPolicy.php`)
- Expense API → Expense service: delegates expenses (evidence: `app/Http/Controllers/ExpenseController.php`)
- User → Expense API: records expenses
- Expense service → Expense model: creates and reads (evidence: `app/Services/ExpenseService.php`)
- Expense service → Settlement model: reads settlements (evidence: `app/Services/ExpenseService.php`)
- Settlement API → Expense service: gets balances (evidence: `app/Http/Controllers/SettlementController.php`)
- Settlement API → Settlement service: validates and delegates (evidence: `app/Http/Controllers/SettlementController.php`)
- User → Settlement API: records settlements
- Settlement service → Settlement model: creates and updates (evidence: `app/Services/SettlementService.php`)
- Group service → MongoDB: transacts on (evidence: `app/Services/GroupService.php`)
- Expense service → MongoDB: transacts on (evidence: `app/Services/ExpenseService.php`)
- Group model → User model: relates members (evidence: `app/Models/Groups.php`)
