# saab04/express-app architecture

> Architecture diagram of the GitHub repository saab04/express-app, 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/saab04/express-app
- Repository: https://github.com/saab04/express-app

## Overview

This is an Express coin-flip game with user accounts, a coin balance, and a once-daily 100-coin reward. Users sign up or log in, receive a cookie-based JWT, then access authenticated dashboard, reward, account, and coin-flip routes. Reward claims and coin-flip bets update the user record in MongoDB. The graph includes the sampled browser scripts and route/controller behavior; the templates and other client-side game behavior were not sampled, so their internal interactions are not inferred.

Main entry points: [`routes/auth.js`](https://github.com/saab04/express-app/blob/main/routes/auth.js) (Auth routes), [`routes/dashboard.js`](https://github.com/saab04/express-app/blob/main/routes/dashboard.js) (Dashboard routes), [`server.js`](https://github.com/saab04/express-app/blob/main/server.js) (Express server), [`public/js/global.js`](https://github.com/saab04/express-app/blob/main/public/js/global.js) (Shared browser script)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web entry and pages"]
  node_server["Express server<br/>[server.js]"]
  node_global_script["Shared browser script<br/>[global.js]"]
  node_page_templates["Game and account pages"]
end

subgraph group_identity["Accounts and authentication"]
  node_auth_routes["Auth routes<br/>[auth.js]"]
  node_auth_middleware["JWT middleware<br/>[authMiddleware.js]"]
  node_auth_controller["Account controller<br/>[authController.js]"]
  node_auth_forms["Login and signup<br/>[login.js]"]
  node_signup_script["Signup script<br/>[signup.js]"]
end

subgraph group_game["Wallet and game"]
  node_dashboard_routes["Dashboard routes<br/>[dashboard.js]"]
  node_balance_controller["Balance controller"]
  node_reward_script["Reward interface<br/>[reward.js]"]
end

subgraph group_data["User data"]
  node_user_model["User model<br/>[User.js]"]
end

node_browser(("Player browser"))
node_mongo[("MongoDB")]

node_browser -->|"requests pages"| node_server
node_server -->|"mounts routes"| node_auth_routes
node_server -->|"mounts routes"| node_dashboard_routes
node_server -->|"connects"| node_mongo
node_auth_routes -->|"checks sessions"| node_auth_middleware
node_auth_routes -->|"dispatches auth"| node_auth_controller
node_dashboard_routes -->|"protects pages"| node_auth_middleware
node_dashboard_routes -->|"dispatches actions"| node_balance_controller
node_dashboard_routes -->|"renders pages"| node_page_templates
node_auth_routes -->|"renders forms"| node_page_templates
node_auth_controller -->|"reads and writes"| node_user_model
node_balance_controller -->|"reads and updates"| node_user_model
node_auth_forms -->|"posts credentials"| node_auth_routes
node_signup_script -->|"posts signup"| node_auth_routes
node_global_script -->|"checks session"| node_auth_routes
node_global_script -->|"posts logout"| node_auth_routes
node_global_script -->|"gets rewards"| node_dashboard_routes
node_reward_script -->|"claims reward"| node_dashboard_routes
node_reward_script -->|"uses reward helper"| node_global_script

click node_server "https://github.com/saab04/express-app/blob/main/server.js"
click node_auth_routes "https://github.com/saab04/express-app/blob/main/routes/auth.js"
click node_auth_middleware "https://github.com/saab04/express-app/blob/main/middleware/authMiddleware.js"
click node_auth_controller "https://github.com/saab04/express-app/blob/main/controllers/authController.js"
click node_auth_forms "https://github.com/saab04/express-app/blob/main/public/js/login.js"
click node_signup_script "https://github.com/saab04/express-app/blob/main/public/js/signup.js"
click node_dashboard_routes "https://github.com/saab04/express-app/blob/main/routes/dashboard.js"
click node_balance_controller "https://github.com/saab04/express-app/blob/main/controllers/balanceController.js"
click node_reward_script "https://github.com/saab04/express-app/blob/main/public/js/reward.js"
click node_global_script "https://github.com/saab04/express-app/blob/main/public/js/global.js"
click node_page_templates "https://github.com/saab04/express-app/tree/main/views"
click node_user_model "https://github.com/saab04/express-app/blob/main/models/User.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_server,node_global_script,node_page_templates,node_browser toneBlue
class node_auth_routes,node_auth_middleware,node_auth_controller,node_auth_forms,node_signup_script,node_mongo toneAmber
class node_dashboard_routes,node_balance_controller,node_reward_script toneMint
class node_user_model toneRose
```

## Components

### Web entry and pages

- [Express server](https://github.com/saab04/express-app/blob/main/server.js): `server.js`
- [Shared browser script](https://github.com/saab04/express-app/blob/main/public/js/global.js): `public/js/global.js`
- [Game and account pages](https://github.com/saab04/express-app/tree/main/views): `views`

### Accounts and authentication

- [Auth routes](https://github.com/saab04/express-app/blob/main/routes/auth.js): `routes/auth.js`
- [JWT middleware](https://github.com/saab04/express-app/blob/main/middleware/authMiddleware.js): `middleware/authMiddleware.js`
- [Account controller](https://github.com/saab04/express-app/blob/main/controllers/authController.js): `controllers/authController.js`
- [Login and signup](https://github.com/saab04/express-app/blob/main/public/js/login.js): `public/js/login.js`
- [Signup script](https://github.com/saab04/express-app/blob/main/public/js/signup.js): `public/js/signup.js`

### Wallet and game

- [Dashboard routes](https://github.com/saab04/express-app/blob/main/routes/dashboard.js): `routes/dashboard.js`
- [Balance controller](https://github.com/saab04/express-app/blob/main/controllers/balanceController.js): `controllers/balanceController.js`
- [Reward interface](https://github.com/saab04/express-app/blob/main/public/js/reward.js): `public/js/reward.js`

### User data

- [User model](https://github.com/saab04/express-app/blob/main/models/User.js): `models/User.js`

### Other components

- **Player browser**
- **MongoDB**

## Connections

- Player browser → Express server: requests pages (evidence: `server.js`)
- Express server → Auth routes: mounts routes (evidence: `server.js`)
- Express server → Dashboard routes: mounts routes (evidence: `server.js`)
- Express server → MongoDB: connects (evidence: `server.js`)
- Auth routes → JWT middleware: checks sessions (evidence: `routes/auth.js`)
- Auth routes → Account controller: dispatches auth (evidence: `routes/auth.js`)
- Dashboard routes → JWT middleware: protects pages (evidence: `routes/dashboard.js`)
- Dashboard routes → Balance controller: dispatches actions (evidence: `routes/dashboard.js`)
- Dashboard routes → Game and account pages: renders pages (evidence: `routes/dashboard.js`)
- Auth routes → Game and account pages: renders forms (evidence: `routes/auth.js`)
- Account controller → User model: reads and writes (evidence: `controllers/authController.js`)
- Balance controller → User model: reads and updates (evidence: `controllers/balanceController.js`)
- Login and signup → Auth routes: posts credentials (evidence: `public/js/login.js`)
- Signup script → Auth routes: posts signup (evidence: `public/js/signup.js`)
- Shared browser script → Auth routes: checks session (evidence: `public/js/global.js`)
- Shared browser script → Auth routes: posts logout (evidence: `public/js/global.js`)
- Shared browser script → Dashboard routes: gets rewards (evidence: `public/js/global.js`)
- Reward interface → Dashboard routes: claims reward (evidence: `public/js/reward.js`)
- Reward interface → Shared browser script: uses reward helper (evidence: `public/js/reward.js`)
