# renan-bsf/crmsegredo architecture

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

- Interactive diagram: https://gitdiagram.com/renan-bsf/crmsegredo
- Repository: https://github.com/renan-bsf/crmsegredo

## Overview

Gestão Íntima is a private back office for a lingerie and intimate-wellness business. Its main workflow is for an authorized staff member to review the operation, record purchases and receive goods into batch-tracked stock, then register direct sales whose prices, costs, and stock effects are calculated server-side. The system also supports customer records, pricing simulations, partner-only financial reporting, and access/audit administration. The README documents capabilities beyond the sampled excerpts; those are included, but uncertain implementation-level wiring is omitted.

Main entry points: [`src/app/actions.ts`](https://github.com/renan-bsf/crmsegredo/blob/main/src/app/actions.ts) (Business actions), [`src/lib/server/auth.ts`](https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/server/auth.ts) (Session authorization), [`src/lib/server/db.ts`](https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/server/db.ts) (Application database), [`src/lib/server/queries.ts`](https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/server/queries.ts) (Operational queries)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and security"]
  node_login["Sign in<br/>[page.tsx]"]
  node_authactions["Auth and MFA<br/>[auth-actions.ts]"]
  node_auth["Session authorization<br/>[auth.ts]"]
  node_middleware["Session refresh<br/>[middleware.ts]"]
end

subgraph group_operations["Business operations"]
  node_sales["Sales<br/>[page.tsx]"]
  node_saleform["Sale composer<br/>[sale-composer.tsx]"]
  node_actions["Business actions<br/>[actions.ts]"]
  node_customers["Customer records<br/>[page.tsx]"]
  node_purchases["Purchases and receipts<br/>[page.tsx]"]
  node_purchaseform["Purchase entry<br/>[purchase-form.tsx]"]
  node_purchaseactions["Purchase actions"]
  node_inventory["Inventory<br/>[page.tsx]"]
  node_stockrules["Stock rules<br/>[stock.ts]"]
end

subgraph group_pricing["Pricing"]
  node_pricingpage["Pricing calculator<br/>[page.tsx]"]
  node_pricingui["Pricing interface"]
  node_pricingactions["Pricing actions<br/>[pricing-actions.ts]"]
  node_pricingrules["Pricing rules<br/>[pricing.ts]"]
end

subgraph group_management["Management and oversight"]
  node_overview["Overview<br/>[page.tsx]"]
  node_finance["Partner finances<br/>[page.tsx]"]
  node_settings["Access and audit<br/>[page.tsx]"]
end

subgraph group_persistence["Server and persistence"]
  node_purchasequeries["Purchase queries"]
  node_queries["Operational queries<br/>[queries.ts]"]
  node_mutations["Mutation support<br/>[mutate.ts]"]
  node_db[("Application database<br/>[db.ts]")]
end

node_staff(("Staff member"))
node_supabase{{"Supabase Auth"}}

node_staff -->|"signs in"| node_login
node_login -->|"submits credentials"| node_authactions
node_authactions -->|"authenticates"| node_supabase
node_authactions -->|"checks membership"| node_db
node_staff -->|"sets up MFA"| node_authactions
node_authactions -->|"enrolls or verifies"| node_supabase
node_middleware -->|"refreshes claims"| node_supabase
node_overview -->|"requires session"| node_auth
node_overview -->|"loads metrics"| node_queries
node_staff -->|"opens sales"| node_sales
node_sales -->|"requires session"| node_auth
node_sales -->|"loads sales"| node_queries
node_saleform -->|"submits sale"| node_actions
node_actions -->|"checks permission"| node_auth
node_actions -->|"performs changes"| node_mutations
node_actions -->|"calculates amounts"| node_pricingrules
node_actions -->|"applies stock rules"| node_stockrules
node_actions -->|"persists sale"| node_db
node_customers -->|"loads customers"| node_queries
node_customers -->|"submits changes"| node_actions
node_staff -->|"records purchases"| node_purchases
node_purchases -->|"loads records"| node_purchasequeries
node_purchaseform -->|"submits receipt"| node_purchaseactions
node_purchaseactions -->|"checks permission"| node_auth
node_purchaseactions -->|"receives stock"| node_stockrules
node_purchaseactions -->|"writes purchase"| node_db
node_inventory -->|"loads inventory"| node_queries
node_inventory -->|"submits stock changes"| node_actions
node_staff -->|"opens calculator"| node_pricingpage
node_pricingpage -->|"renders calculator"| node_pricingui
node_pricingui -->|"simulates pricing"| node_pricingrules
node_pricingui -->|"saves or searches"| node_pricingactions
node_pricingactions -->|"checks permission"| node_auth
node_pricingactions -->|"stores calculation"| node_db
node_finance -->|"requires partner role"| node_auth
node_finance -->|"loads financials"| node_queries
node_finance -->|"records expenses"| node_actions
node_settings -->|"requires admin role"| node_auth
node_settings -->|"reads members and audit"| node_db
node_settings -->|"updates access"| node_actions
node_queries -->|"reads records"| node_db
node_purchasequeries -->|"reads records"| node_db
node_mutations -->|"writes records"| node_db
node_auth -->|"validates identity"| node_supabase
node_auth -->|"checks session and member"| node_db

click node_login "https://github.com/renan-bsf/crmsegredo/blob/main/src/app/login/page.tsx"
click node_authactions "https://github.com/renan-bsf/crmsegredo/blob/main/src/app/auth-actions.ts"
click node_auth "https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/server/auth.ts"
click node_middleware "https://github.com/renan-bsf/crmsegredo/blob/main/src/middleware.ts"
click node_overview "https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/page.tsx"
click node_sales "https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/vendas/page.tsx"
click node_saleform "https://github.com/renan-bsf/crmsegredo/blob/main/src/components/sale-composer.tsx"
click node_actions "https://github.com/renan-bsf/crmsegredo/blob/main/src/app/actions.ts"
click node_customers "https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/clientes/page.tsx"
click node_purchases "https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/compras/page.tsx"
click node_purchaseform "https://github.com/renan-bsf/crmsegredo/blob/main/src/components/purchase-form.tsx"
click node_purchaseactions "https://github.com/renan-bsf/crmsegredo/blob/main/src/app/purchase-actions.ts"
click node_inventory "https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/estoque/page.tsx"
click node_purchasequeries "https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/server/purchase-queries.ts"
click node_stockrules "https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/stock.ts"
click node_pricingpage "https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/calculadora/page.tsx"
click node_pricingui "https://github.com/renan-bsf/crmsegredo/blob/main/src/components/pricing-calculator.tsx"
click node_pricingactions "https://github.com/renan-bsf/crmsegredo/blob/main/src/app/pricing-actions.ts"
click node_pricingrules "https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/pricing.ts"
click node_finance "https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/financeiro/page.tsx"
click node_settings "https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/configuracoes/page.tsx"
click node_queries "https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/server/queries.ts"
click node_mutations "https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/server/mutate.ts"
click node_db "https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/server/db.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_login,node_authactions,node_auth,node_middleware toneBlue
class node_sales,node_saleform,node_actions,node_customers,node_purchases,node_purchaseform,node_purchaseactions,node_inventory,node_stockrules toneAmber
class node_pricingpage,node_pricingui,node_pricingactions,node_pricingrules toneMint
class node_overview,node_finance,node_settings toneRose
class node_purchasequeries,node_queries,node_mutations,node_db,node_staff,node_supabase toneIndigo
```

## Components

### Access and security

- [Sign in](https://github.com/renan-bsf/crmsegredo/blob/main/src/app/login/page.tsx): `src/app/login/page.tsx`
- [Auth and MFA](https://github.com/renan-bsf/crmsegredo/blob/main/src/app/auth-actions.ts): `src/app/auth-actions.ts`
- [Session authorization](https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/server/auth.ts): `src/lib/server/auth.ts`
- [Session refresh](https://github.com/renan-bsf/crmsegredo/blob/main/src/middleware.ts): `src/middleware.ts`

### Business operations

- [Sales](https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/vendas/page.tsx): `src/app/(private)/vendas/page.tsx`
- [Sale composer](https://github.com/renan-bsf/crmsegredo/blob/main/src/components/sale-composer.tsx): `src/components/sale-composer.tsx`
- [Business actions](https://github.com/renan-bsf/crmsegredo/blob/main/src/app/actions.ts): `src/app/actions.ts`
- [Customer records](https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/clientes/page.tsx): `src/app/(private)/clientes/page.tsx`
- [Purchases and receipts](https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/compras/page.tsx): `src/app/(private)/compras/page.tsx`
- [Purchase entry](https://github.com/renan-bsf/crmsegredo/blob/main/src/components/purchase-form.tsx): `src/components/purchase-form.tsx`
- [Purchase actions](https://github.com/renan-bsf/crmsegredo/blob/main/src/app/purchase-actions.ts): `src/app/purchase-actions.ts`
- [Inventory](https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/estoque/page.tsx): `src/app/(private)/estoque/page.tsx`
- [Stock rules](https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/stock.ts): `src/lib/stock.ts`

### Pricing

- [Pricing calculator](https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/calculadora/page.tsx): `src/app/(private)/calculadora/page.tsx`
- [Pricing interface](https://github.com/renan-bsf/crmsegredo/blob/main/src/components/pricing-calculator.tsx): `src/components/pricing-calculator.tsx`
- [Pricing actions](https://github.com/renan-bsf/crmsegredo/blob/main/src/app/pricing-actions.ts): `src/app/pricing-actions.ts`
- [Pricing rules](https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/pricing.ts): `src/lib/pricing.ts`

### Management and oversight

- [Overview](https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/page.tsx): `src/app/(private)/page.tsx`
- [Partner finances](https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/financeiro/page.tsx): `src/app/(private)/financeiro/page.tsx`
- [Access and audit](https://github.com/renan-bsf/crmsegredo/blob/main/src/app/(private)/configuracoes/page.tsx): `src/app/(private)/configuracoes/page.tsx`

### Server and persistence

- [Purchase queries](https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/server/purchase-queries.ts): `src/lib/server/purchase-queries.ts`
- [Operational queries](https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/server/queries.ts): `src/lib/server/queries.ts`
- [Mutation support](https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/server/mutate.ts): `src/lib/server/mutate.ts`
- [Application database](https://github.com/renan-bsf/crmsegredo/blob/main/src/lib/server/db.ts): `src/lib/server/db.ts`

### Other components

- **Staff member**
- **Supabase Auth**

## Connections

- Staff member → Sign in: signs in
- Sign in → Auth and MFA: submits credentials
- Auth and MFA → Supabase Auth: authenticates
- Auth and MFA → Application database: checks membership
- Staff member → Auth and MFA: sets up MFA
- Auth and MFA → Supabase Auth: enrolls or verifies
- Session refresh → Supabase Auth: refreshes claims
- Overview → Session authorization: requires session
- Overview → Operational queries: loads metrics
- Staff member → Sales: opens sales
- Sales → Session authorization: requires session
- Sales → Operational queries: loads sales
- Sale composer → Business actions: submits sale
- Business actions → Session authorization: checks permission
- Business actions → Mutation support: performs changes
- Business actions → Pricing rules: calculates amounts
- Business actions → Stock rules: applies stock rules
- Business actions → Application database: persists sale
- Customer records → Operational queries: loads customers
- Customer records → Business actions: submits changes
- Staff member → Purchases and receipts: records purchases
- Purchases and receipts → Purchase queries: loads records
- Purchase entry → Purchase actions: submits receipt
- Purchase actions → Session authorization: checks permission
- Purchase actions → Stock rules: receives stock
- Purchase actions → Application database: writes purchase
- Inventory → Operational queries: loads inventory
- Inventory → Business actions: submits stock changes
- Staff member → Pricing calculator: opens calculator
- Pricing calculator → Pricing interface: renders calculator
- Pricing interface → Pricing rules: simulates pricing
- Pricing interface → Pricing actions: saves or searches
- Pricing actions → Session authorization: checks permission
- Pricing actions → Application database: stores calculation
- Partner finances → Session authorization: requires partner role
- Partner finances → Operational queries: loads financials
- Partner finances → Business actions: records expenses
- Access and audit → Session authorization: requires admin role
- Access and audit → Application database: reads members and audit
- Access and audit → Business actions: updates access
- Operational queries → Application database: reads records
- Purchase queries → Application database: reads records
- Mutation support → Application database: writes records
- Session authorization → Supabase Auth: validates identity
- Session authorization → Application database: checks session and member
