# viinuthaa/guessy architecture

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

## Overview

Guessy is a virtual-points prediction-market web app. Users browse or create markets, authenticate, take YES/NO positions, and view their portfolio and trade history; trades update market prices, while resolution pays winning positions and supports leaderboard scoring. The Next.js pages call a separate Express API, which performs the domain operations and persists state through Prisma to PostgreSQL. The sampled source shows these API paths and pricing calls; resolution and leaderboard are implemented in the API but have no sampled frontend entry point.

Main entry points: [`server/index.js`](https://github.com/viinuthaa/guessy/blob/main/server/index.js) (Express API), [`app/page.tsx`](https://github.com/viinuthaa/guessy/blob/main/app/page.tsx) (Market browser), [`app/market/[id]/page.tsx`](https://github.com/viinuthaa/guessy/blob/main/app/market/%5Bid%5D/page.tsx) (Market detail), [`app/auth/page.tsx`](https://github.com/viinuthaa/guessy/blob/main/app/auth/page.tsx) (Sign-in form)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_market_ui["Market browser<br/>[page.tsx]"]
  node_market_detail["Market detail<br/>[page.tsx]"]
  node_profile_ui["Portfolio view<br/>[page.tsx]"]
end

subgraph group_identity["Accounts"]
  node_auth_ui["Sign-in form<br/>[page.tsx]"]
  node_authentication["Token authentication<br/>[index.js]"]
end

subgraph group_markets["Markets and trading"]
  node_api["Express API<br/>[index.js]"]
  node_market_catalog["Market catalog<br/>[index.js]"]
  node_trade_engine["Trade processing<br/>[index.js]"]
  node_price_model["Dynamic pricing<br/>[pricing.js]"]
  node_price_history["Price history<br/>[index.js]"]
end

subgraph group_outcomes["Results and rankings"]
  node_market_resolution["Market resolution<br/>[index.js]"]
  node_leaderboard["Trader leaderboard<br/>[index.js]"]
end

subgraph group_persistence["Persistence"]
  node_account_data["Users and trades<br/>[schema.prisma]"]
  node_market_data["Market records<br/>[schema.prisma]"]
  node_postgres[("PostgreSQL")]
end

node_user(("User"))

node_user -->|"browses markets"| node_market_ui
node_user -->|"signs in"| node_auth_ui
node_user -->|"places guesses"| node_market_detail
node_market_ui -->|"loads and creates"| node_api
node_auth_ui -->|"registers or logs in"| node_api
node_market_detail -->|"loads and trades"| node_api
node_profile_ui -->|"loads portfolio"| node_api
node_api -->|"checks protected routes"| node_authentication
node_api -->|"handles market routes"| node_market_catalog
node_api -->|"handles trade requests"| node_trade_engine
node_trade_engine -->|"calculates prices"| node_price_model
node_trade_engine -->|"records prices"| node_price_history
node_api -->|"handles resolution"| node_market_resolution
node_api -->|"computes rankings"| node_leaderboard
node_api -->|"reads and updates"| node_account_data
node_api -->|"reads and updates"| node_market_data
node_price_history -->|"persists history"| node_postgres
node_account_data -->|"persists accounts and trades"| node_postgres
node_market_data -->|"persists markets"| node_postgres

click node_market_ui "https://github.com/viinuthaa/guessy/blob/main/app/page.tsx"
click node_market_detail "https://github.com/viinuthaa/guessy/blob/main/app/market/%5Bid%5D/page.tsx"
click node_profile_ui "https://github.com/viinuthaa/guessy/blob/main/app/profile/page.tsx"
click node_auth_ui "https://github.com/viinuthaa/guessy/blob/main/app/auth/page.tsx"
click node_api "https://github.com/viinuthaa/guessy/blob/main/server/index.js"
click node_authentication "https://github.com/viinuthaa/guessy/blob/main/server/index.js"
click node_market_catalog "https://github.com/viinuthaa/guessy/blob/main/server/index.js"
click node_trade_engine "https://github.com/viinuthaa/guessy/blob/main/server/index.js"
click node_price_model "https://github.com/viinuthaa/guessy/blob/main/server/pricing.js"
click node_price_history "https://github.com/viinuthaa/guessy/blob/main/server/index.js"
click node_market_resolution "https://github.com/viinuthaa/guessy/blob/main/server/index.js"
click node_leaderboard "https://github.com/viinuthaa/guessy/blob/main/server/index.js"
click node_account_data "https://github.com/viinuthaa/guessy/blob/main/prisma/schema.prisma"
click node_market_data "https://github.com/viinuthaa/guessy/blob/main/prisma/schema.prisma"

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_market_ui,node_market_detail,node_profile_ui,node_user toneBlue
class node_auth_ui,node_authentication toneAmber
class node_api,node_market_catalog,node_trade_engine,node_price_model,node_price_history toneMint
class node_market_resolution,node_leaderboard toneRose
class node_account_data,node_market_data,node_postgres toneIndigo
```

## Components

### Web experience

- [Market browser](https://github.com/viinuthaa/guessy/blob/main/app/page.tsx): `app/page.tsx`
- [Market detail](https://github.com/viinuthaa/guessy/blob/main/app/market/%5Bid%5D/page.tsx): `app/market/[id]/page.tsx`
- [Portfolio view](https://github.com/viinuthaa/guessy/blob/main/app/profile/page.tsx): `app/profile/page.tsx`

### Accounts

- [Sign-in form](https://github.com/viinuthaa/guessy/blob/main/app/auth/page.tsx): `app/auth/page.tsx`
- [Token authentication](https://github.com/viinuthaa/guessy/blob/main/server/index.js): `server/index.js`

### Markets and trading

- [Express API](https://github.com/viinuthaa/guessy/blob/main/server/index.js): `server/index.js`
- [Market catalog](https://github.com/viinuthaa/guessy/blob/main/server/index.js): `server/index.js`
- [Trade processing](https://github.com/viinuthaa/guessy/blob/main/server/index.js): `server/index.js`
- [Dynamic pricing](https://github.com/viinuthaa/guessy/blob/main/server/pricing.js): `server/pricing.js`
- [Price history](https://github.com/viinuthaa/guessy/blob/main/server/index.js): `server/index.js`

### Results and rankings

- [Market resolution](https://github.com/viinuthaa/guessy/blob/main/server/index.js): `server/index.js`
- [Trader leaderboard](https://github.com/viinuthaa/guessy/blob/main/server/index.js): `server/index.js`

### Persistence

- [Users and trades](https://github.com/viinuthaa/guessy/blob/main/prisma/schema.prisma): `prisma/schema.prisma`
- [Market records](https://github.com/viinuthaa/guessy/blob/main/prisma/schema.prisma): `prisma/schema.prisma`
- **PostgreSQL**

### Other components

- **User**

## Connections

- User → Market browser: browses markets (evidence: `README.md`)
- User → Sign-in form: signs in (evidence: `README.md`)
- User → Market detail: places guesses (evidence: `README.md`)
- Market browser → Express API: loads and creates (evidence: `app/page.tsx`)
- Sign-in form → Express API: registers or logs in (evidence: `app/auth/page.tsx`)
- Market detail → Express API: loads and trades (evidence: `app/market/[id]/page.tsx`)
- Portfolio view → Express API: loads portfolio (evidence: `app/profile/page.tsx`)
- Express API → Token authentication: checks protected routes (evidence: `server/index.js`)
- Express API → Market catalog: handles market routes (evidence: `server/index.js`)
- Express API → Trade processing: handles trade requests (evidence: `server/index.js`)
- Trade processing → Dynamic pricing: calculates prices (evidence: `server/index.js`)
- Trade processing → Price history: records prices (evidence: `server/index.js`)
- Express API → Market resolution: handles resolution (evidence: `server/index.js`)
- Express API → Trader leaderboard: computes rankings (evidence: `server/index.js`)
- Express API → Users and trades: reads and updates (evidence: `server/index.js`)
- Express API → Market records: reads and updates (evidence: `server/index.js`)
- Price history → PostgreSQL: persists history (evidence: `server/index.js`)
- Users and trades → PostgreSQL: persists accounts and trades
- Market records → PostgreSQL: persists markets
