# doubleghosty/resellos architecture

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

- Interactive diagram: https://gitdiagram.com/doubleghosty/resellos
- Repository: https://github.com/doubleghosty/resellos

## Overview

#### Purpose and deployment shape
ResellOS is a SaaS for managing and automating resale marketplace operations: inventory, analytics, AI listings, account controls, pricing/relisting, and AI negotiation. It consists of a Next.js web application intended for Vercel and a separate persistent Node.js worker for 24/7 marketplace automation. Core entry points are `src/app/page.tsx`, `src/app/dashboard/page.tsx`, `src/proxy.ts`, and `worker/src/index.ts`.

#### Web application and access boundary
The Next.js 16 App Router application serves a public marketing site plus authenticated dashboard routes. Supabase Auth session handling and dashboard protection are enforced at the request boundary in `src/proxy.ts`; application layouts divide public and dashboard UI in `src/app/layout.tsx` and `src/app/dashboard/layout.tsx`. Authentication screens live at `src/app/login/page.tsx` and `src/app/signup/page.tsx`.

#### Dashboard operational surface
The dashboard is the human control plane for connected marketplace accounts, inventory, listings, automation state, messages, AI generation, and settings. Main route boundaries are `src/app/dashboard/accounts/page.tsx`, `src/app/dashboard/inventory/page.tsx`, `src/app/dashboard/automation/page.tsx`, `src/app/dashboard/ai-studio/page.tsx`, and `src/app/dashboard/messages/page.tsx`. Server actions for account and inventory mutations are colocated in `src/app/dashboard/accounts/actions.ts` and `src/app/dashboard/inventory/actions.ts`.

#### Data platform and tenant security
Supabase provides Postgres, Auth, and RLS-backed multi-user persistence. Schema evolution is defined in `supabase/migrations/0001_init.sql`, `supabase/migrations/0002_stripe.sql`, and `supabase/migrations/0003_listings_sync.sql`. The app uses distinct browser, server, admin, and middleware/proxy Supabase clients under `src/lib/supabase/`, creating a boundary between user-scoped operations and privileged backend/worker access.

#### Marketplace account connection and synchronization
Users connect accounts through `src/app/api/accounts/connect/route.ts` and request inventory/listing synchronization through `src/app/api/accounts/resync/route.ts`. Marketplace session material is encrypted before database storage by `src/lib/crypto.ts`; the worker uses compatible cryptography in `worker/src/crypto.ts`. Both deployments must share `SESSION_ENCRYPTION_KEY`. The worker then decrypts credentials only when operating the account.

#### AI and commercial APIs
Listing generation is exposed through `src/app/api/generate-listing/route.ts` and implemented with Anthropic/Claude integration in `src/lib/ai.ts`. Billing is Stripe-based: checkout, customer portal, and signed webhook intake are at `src/app/api/billing/checkout/route.ts`, `src/app/api/billing/portal/route.ts`, and `src/app/api/billing/webhook/route.ts`, supported by `src/lib/stripe.ts`. Stripe subscription state is persisted through the Supabase schema.

#### Persistent automation worker
`worker/src/index.ts` is an independent Node runtime that polls/coordinates automation against Supabase. Its core stages are relisting, scheduled pricing, and AI-supported negotiation in `worker/src/engine/relist.ts`, `worker/src/engine/pricing.ts`, and `worker/src/engine/negotiation.ts`. `worker/src/store.ts` is its persistence interface; `worker/src/rate-limiter.ts` and `worker/src/config.ts` constrain runtime behavior and configuration.

#### External marketplace boundary
Vinted integration is isolated behind adapters at `worker/src/adapters/vinted.ts` and `worker/src/adapters/vinted-http.ts`. This boundary converts worker intents into authenticated Vinted HTTP operations, including account-driven automation and synchronization. It deliberately does not evade DataDome or other anti-bot controls; failures such as 403 responses remain an expected operational risk rather than a hidden infrastructure concern.

Main entry points: [`supabase/migrations/0001_init.sql`](https://github.com/doubleghosty/resellos/blob/master/supabase/migrations/0001_init.sql) (Supabase), [`src/app/dashboard/page.tsx`](https://github.com/doubleghosty/resellos/blob/master/src/app/dashboard/page.tsx) (Dashboard shell), [`src/app/dashboard/accounts/actions.ts`](https://github.com/doubleghosty/resellos/blob/master/src/app/dashboard/accounts/actions.ts) (Accounts & inventory), [`src/app/api/accounts/connect/route.ts`](https://github.com/doubleghosty/resellos/blob/master/src/app/api/accounts/connect/route.ts) (Account APIs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Next.js web app"]
  node_marketing["Marketing site<br/>public UI<br/>[page.tsx]"]
  node_proxy{{"Auth proxy<br/>request boundary<br/>[proxy.ts]"}}
  node_dashboard["Dashboard shell<br/>control plane UI<br/>[page.tsx]"]
  node_dashboard_layout["Dashboard layout<br/>authenticated layout<br/>[layout.tsx]"]
  node_account_inventory["Accounts &amp; inventory<br/>dashboard routes/actions<br/>[actions.ts]"]
  node_operations_ui["Automation, AI &amp; messages<br/>dashboard routes<br/>[page.tsx]"]
  node_account_api{{"Account APIs<br/>route handlers<br/>[route.ts]"}}
  node_listing_ai_api{{"Listing generation API<br/>route handler<br/>[route.ts]"}}
  node_billing_api{{"Stripe billing APIs<br/>route handlers<br/>[route.ts]"}}
end

subgraph group_data["Supabase platform"]
  node_supabase[("Supabase<br/>Postgres, Auth &amp; RLS<br/>[0001_init.sql]")]
  node_session_crypto["Session encryption<br/>shared crypto<br/>[crypto.ts]"]
end

subgraph group_worker["Automation worker"]
  node_worker_runtime{{"Worker coordinator<br/>Node.js runtime<br/>[index.ts]"}}
  node_worker_store["Worker store<br/>persistence interface<br/>[store.ts]"]
  node_automation_engines["Relist, pricing &amp; negotiation<br/>automation engines<br/>[relist.ts]"]
  node_worker_crypto["Worker session crypto<br/>credential handling<br/>[crypto.ts]"]
  node_vinted_adapter{{"Vinted adapter<br/>marketplace boundary<br/>[vinted.ts]"}}
end

node_claude(("Anthropic Claude<br/>AI API"))
node_stripe(("Stripe<br/>billing platform"))
node_vinted(("Vinted<br/>marketplace"))

node_proxy -->|"authorizes"| node_dashboard_layout
node_dashboard_layout -->|"hosts"| node_dashboard
node_dashboard -->|"operates"| node_account_inventory
node_dashboard -->|"operates"| node_operations_ui
node_account_inventory -->|"connects / resyncs"| node_account_api
node_account_inventory -->|"user-scoped data"| node_supabase
node_operations_ui -->|"generates listings"| node_listing_ai_api
node_listing_ai_api -->|"prompts"| node_claude
node_listing_ai_api -->|"stores results"| node_supabase
node_account_api -->|"encrypts sessions"| node_session_crypto
node_session_crypto -->|"stores encrypted material"| node_supabase
node_billing_api -->|"checkout / webhooks"| node_stripe
node_billing_api -->|"persists subscriptions"| node_supabase
node_worker_runtime -->|"reads and writes"| node_worker_store
node_worker_store -->|"privileged persistence"| node_supabase
node_worker_runtime -->|"schedules"| node_automation_engines
node_automation_engines -->|"requires credentials"| node_worker_crypto
node_worker_crypto -->|"authenticated intents"| node_vinted_adapter
node_vinted_adapter -->|"HTTP operations"| node_vinted
node_account_api -.->|"sync work becomes available"| node_worker_runtime

click node_marketing "https://github.com/doubleghosty/resellos/blob/master/src/app/page.tsx"
click node_proxy "https://github.com/doubleghosty/resellos/blob/master/src/proxy.ts"
click node_dashboard "https://github.com/doubleghosty/resellos/blob/master/src/app/dashboard/page.tsx"
click node_dashboard_layout "https://github.com/doubleghosty/resellos/blob/master/src/app/dashboard/layout.tsx"
click node_account_inventory "https://github.com/doubleghosty/resellos/blob/master/src/app/dashboard/accounts/actions.ts"
click node_operations_ui "https://github.com/doubleghosty/resellos/blob/master/src/app/dashboard/automation/page.tsx"
click node_account_api "https://github.com/doubleghosty/resellos/blob/master/src/app/api/accounts/connect/route.ts"
click node_listing_ai_api "https://github.com/doubleghosty/resellos/blob/master/src/app/api/generate-listing/route.ts"
click node_billing_api "https://github.com/doubleghosty/resellos/blob/master/src/app/api/billing/webhook/route.ts"
click node_supabase "https://github.com/doubleghosty/resellos/blob/master/supabase/migrations/0001_init.sql"
click node_session_crypto "https://github.com/doubleghosty/resellos/blob/master/src/lib/crypto.ts"
click node_worker_runtime "https://github.com/doubleghosty/resellos/blob/master/worker/src/index.ts"
click node_worker_store "https://github.com/doubleghosty/resellos/blob/master/worker/src/store.ts"
click node_automation_engines "https://github.com/doubleghosty/resellos/blob/master/worker/src/engine/relist.ts"
click node_worker_crypto "https://github.com/doubleghosty/resellos/blob/master/worker/src/crypto.ts"
click node_vinted_adapter "https://github.com/doubleghosty/resellos/blob/master/worker/src/adapters/vinted.ts"

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_marketing,node_proxy,node_dashboard,node_dashboard_layout,node_account_inventory,node_operations_ui,node_account_api,node_listing_ai_api,node_billing_api toneBlue
class node_supabase,node_session_crypto toneAmber
class node_worker_runtime,node_worker_store,node_automation_engines,node_worker_crypto,node_vinted_adapter toneMint
class node_claude,node_stripe,node_vinted toneNeutral
```

## Components

### Next.js web app

Vercel-oriented public site and authenticated control plane.

- [Marketing site](https://github.com/doubleghosty/resellos/blob/master/src/app/page.tsx): public UI · `src/app/page.tsx`
- [Auth proxy](https://github.com/doubleghosty/resellos/blob/master/src/proxy.ts): request boundary · Maintains Supabase sessions and protects dashboard requests. · `src/proxy.ts`
- [Dashboard shell](https://github.com/doubleghosty/resellos/blob/master/src/app/dashboard/page.tsx): control plane UI · Human operations surface for accounts, inventory, automation, AI, and messages. · `src/app/dashboard/page.tsx`
- [Dashboard layout](https://github.com/doubleghosty/resellos/blob/master/src/app/dashboard/layout.tsx): authenticated layout · `src/app/dashboard/layout.tsx`
- [Accounts & inventory](https://github.com/doubleghosty/resellos/blob/master/src/app/dashboard/accounts/actions.ts): dashboard routes/actions · Connects accounts and manages inventory mutations. · `src/app/dashboard/accounts/actions.ts`
- [Automation, AI & messages](https://github.com/doubleghosty/resellos/blob/master/src/app/dashboard/automation/page.tsx): dashboard routes · `src/app/dashboard/automation/page.tsx`
- [Account APIs](https://github.com/doubleghosty/resellos/blob/master/src/app/api/accounts/connect/route.ts): route handlers · Connect and resync requests enter here. · `src/app/api/accounts/connect/route.ts`
- [Listing generation API](https://github.com/doubleghosty/resellos/blob/master/src/app/api/generate-listing/route.ts): route handler · `src/app/api/generate-listing/route.ts`
- [Stripe billing APIs](https://github.com/doubleghosty/resellos/blob/master/src/app/api/billing/webhook/route.ts): route handlers · Checkout, portal, and signed webhook intake. · `src/app/api/billing/webhook/route.ts`

### Supabase platform

Auth, Postgres, and RLS-backed tenant persistence.

- [Supabase](https://github.com/doubleghosty/resellos/blob/master/supabase/migrations/0001_init.sql): Postgres, Auth & RLS · Tenant-scoped persistence and subscription state. · `supabase/migrations/0001_init.sql`
- [Session encryption](https://github.com/doubleghosty/resellos/blob/master/src/lib/crypto.ts): shared crypto · Encrypts marketplace sessions at rest; deployments share one key. · `src/lib/crypto.ts`

### Automation worker

Persistent Node.js runtime for marketplace operations.

- [Worker coordinator](https://github.com/doubleghosty/resellos/blob/master/worker/src/index.ts): Node.js runtime · Polls Supabase and coordinates account automation. · `worker/src/index.ts`
- [Worker store](https://github.com/doubleghosty/resellos/blob/master/worker/src/store.ts): persistence interface · `worker/src/store.ts`
- [Relist, pricing & negotiation](https://github.com/doubleghosty/resellos/blob/master/worker/src/engine/relist.ts): automation engines · Runs relisting, scheduled pricing, and AI-supported negotiation. · `worker/src/engine/relist.ts`
- [Worker session crypto](https://github.com/doubleghosty/resellos/blob/master/worker/src/crypto.ts): credential handling · Decrypts account credentials only during operation. · `worker/src/crypto.ts`
- [Vinted adapter](https://github.com/doubleghosty/resellos/blob/master/worker/src/adapters/vinted.ts): marketplace boundary · Translates worker intents to authenticated marketplace HTTP calls. · `worker/src/adapters/vinted.ts`

### Other components

- **Anthropic Claude**: AI API
- **Stripe**: billing platform
- **Vinted**: marketplace · 403 and anti-bot failures are an expected operational risk.

## Connections

- Auth proxy → Dashboard layout: authorizes
- Dashboard layout → Dashboard shell: hosts
- Dashboard shell → Accounts & inventory: operates
- Dashboard shell → Automation, AI & messages: operates
- Accounts & inventory → Account APIs: connects / resyncs
- Accounts & inventory → Supabase: user-scoped data
- Automation, AI & messages → Listing generation API: generates listings
- Listing generation API → Anthropic Claude: prompts
- Listing generation API → Supabase: stores results
- Account APIs → Session encryption: encrypts sessions
- Session encryption → Supabase: stores encrypted material
- Stripe billing APIs → Stripe: checkout / webhooks
- Stripe billing APIs → Supabase: persists subscriptions
- Worker coordinator → Worker store: reads and writes
- Worker store → Supabase: privileged persistence
- Worker coordinator → Relist, pricing & negotiation: schedules
- Relist, pricing & negotiation → Worker session crypto: requires credentials
- Worker session crypto → Vinted adapter: authenticated intents
- Vinted adapter → Vinted: HTTP operations
- Account APIs → Worker coordinator: sync work becomes available
