# mahaut1/verrier-pro architecture

> Architecture diagram of the GitHub repository mahaut1/verrier-pro, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mahaut1/verrier-pro
- Repository: https://github.com/mahaut1/verrier-pro

## Overview

##### Project Type and Purpose
- VerrierPro is a full-stack web application designed for professional glass artisans to manage creations, galleries, orders, stock and events.
- Frontend: React 18 + TypeScript + Vite
- Backend: Express.js + TypeScript + Drizzle ORM
- Database: PostgreSQL (Docker locally, Neon in cloud)
- File uploads: Local “uploads/” plus R2 (cloud object storage)

##### File Structure Analysis
- Top-level directories:
- client/ – React single-page application
- server/ – Express API, routing, middleware, data-access
- shared/ – DTOs & schema definitions shared by client & server
- migrations/ – Drizzle SQL migrations and metadata
- uploads/ – Persisted image assets
- Infrastructure/config:
- docker-compose.yml, drizzle.config.ts, postgres.conf, pg_hba.conf
- Scripts for DB dumps and migrations (scripts/*.ts, init-from-env.sh)
- Build/config files:
- tsconfig.json, tsconfig.build.json, vite.config.ts, postcss.config.cjs, tailwind.config.ts

##### README Insights
- Describes domain: pieces, galleries, orders, stock, events, dashboard.
- Highlights architectural patterns:
- Domain-Driven Design
- Repository pattern via server/storage/*.storage.ts
- Command-Query Separation
- Express middleware for audit, rate limiting, error handling
- Deployment targets: Docker local, Railway/Neon production

##### Main Components
a. Frontend
- React SPA served by Vite dev server (localhost:5173) or static bundle under Express in production
- Components: pages/, forms/, UI primitives (shadcn/ui + Radix), React Query for state
- Authentication via HTTP-only cookies, TanStack Query for data fetching
b. Backend
- Express app with modular routes (server/routes/*.ts)
- Middlewares: session management (express-session + bcrypt), CSRF, rateLimiter, audit, errorHandler
- Data-access layer (server/storage/*.storage.ts) implementing repository pattern with Drizzle ORM
- R2 proxy route for direct object storage read/write
- Shared schema definitions imported from shared/schema.ts
c. Database
- PostgreSQL with tables: users, sessions, pieces, piece_types, galleries, orders, order_items, stock_items, stock_movements, events, event_pieces
- Migrations tracked under migrations/
- Connection logic in server/db.ts
d. External Services
- Neon (Postgres cloud) or local Docker Postgres
- R2 (S3-compatible object storage via server/lib/r2.ts)
- Mailer service (server/utils/mailer.ts)

##### Relationships and Data Flows
- User → Frontend (React) ↔ Backend (Express API) ↔ PostgreSQL
- Frontend uses React Query to call /api/* endpoints, sending session cookie
- Backend middleware authenticates request, routes → storage layer → DB
- File upload flows: Frontend POST to /api/r2-proxy or direct R2 endpoint, metadata in DB
- Events: separate route and storage for event-piece associations
- Dashboard aggregates multiple services: events, pieces, orders, stock movements

##### Architectural Patterns & Design Principles
- Separation of concerns: UI, API, data-access, migrations
- Repository pattern in storage modules for testability & decoupling
- CQRS: read models served by queries, writes via commands in routes
- Domain-Driven Design: clear modules per domain (events, galleries, orders, stock)
- Middleware chain enforces cross-cutting concerns (security, logging, rate limiting)

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interaction
    User["User"]:::external
    User -->|"HTTP Requests"| FE_REACT

    %% Frontend Layer
    subgraph "Frontend" 
        direction TB
        FE_REACT["React SPA"]:::frontend
        FE_PAGES["Pages"]:::frontend
        FE_FORMS["Forms"]:::frontend
        FE_UI["UI Primitives"]:::frontend
        FE_QUERY["React Query"]:::frontend
        FE_QUERY_SETUP["Query Client Setup"]:::frontend
        FE_AUTH_HOOKS["Auth Hooks"]:::frontend

        FE_REACT --> FE_PAGES
        FE_REACT --> FE_FORMS
        FE_REACT --> FE_UI
        FE_REACT --> FE_QUERY
        FE_QUERY --> FE_QUERY_SETUP
        FE_REACT --> FE_AUTH_HOOKS
    end

    %% Backend Layer
    subgraph "Backend" 
        direction TB
        BE_EXPRESS["Express App"]:::backend
        BE_MW["Middleware"]:::backend
        BE_ROUTES["Routes"]:::backend
        BE_STORAGE["Data-Access (Drizzle ORM)"]:::backend
        BE_DB_CONN["DB Connection Logic"]:::backend
        BE_R2_LIB["R2 Library"]:::backend
        BE_R2_PROXY["R2 Proxy Route"]:::backend
        BE_MAILER["Mailer Utility"]:::backend
        BE_SHARED["Shared Schema/DTOs"]:::backend

        BE_EXPRESS --> BE_MW
        BE_MW --> BE_ROUTES
        BE_ROUTES --> BE_STORAGE
        BE_STORAGE --> BE_DB_CONN
        BE_ROUTES --> BE_R2_PROXY
        BE_R2_PROXY --> BE_R2_LIB
        BE_ROUTES --> BE_MAILER
        BE_ROUTES --> BE_SHARED
    end

    %% Database Layer
    subgraph "Database" 
        direction TB
        DB["PostgreSQL"]:::database
        MIGR["Migrations"]:::database
        DB --> MIGR
    end

    %% Storage & Config
    subgraph "Storage & Config"
        direction TB
        EXT_UPLOADS["Local File Storage"]:::database
        EXT_INFRA["Infrastructure & Docker Config"]:::external
        EXT_BUILD["Build & Tooling Config"]:::external

        FE_REACT -->|"Upload Images"| EXT_UPLOADS
    end

    %% External Services
    subgraph "External Services"
        direction TB
        EXT_R2["R2 Object Storage"]:::external
        EXT_DB["Neon Postgres (Cloud)"]:::external
        EXT_MAIL["Mailer Service"]:::external

        EXT_R2 -->|s3 API| BE_R2_LIB
        BE_MAILER --> EXT_MAIL
        BE_DB_CONN --> EXT_DB
    end

    %% Interactions
    FE_REACT -->|"API calls"| BE_EXPRESS
    BE_STORAGE -->|"SQL Queries"| DB

    %% Click Events
    click FE_REACT "https://github.com/mahaut1/verrier-pro/tree/main/client/"
    click FE_PAGES "https://github.com/mahaut1/verrier-pro/tree/main/client/src/pages/"
    click FE_FORMS "https://github.com/mahaut1/verrier-pro/tree/main/client/src/components/forms/"
    click FE_UI "https://github.com/mahaut1/verrier-pro/tree/main/client/src/components/ui/"
    click FE_QUERY_SETUP "https://github.com/mahaut1/verrier-pro/blob/main/client/src/lib/queryClient.ts"
    click FE_AUTH_HOOKS "https://github.com/mahaut1/verrier-pro/blob/main/client/src/hooks/useAuth.ts"
    click BE_EXPRESS "https://github.com/mahaut1/verrier-pro/blob/main/server/index.ts"
    click BE_MW "https://github.com/mahaut1/verrier-pro/tree/main/server/middleware/"
    click BE_ROUTES "https://github.com/mahaut1/verrier-pro/tree/main/server/routes/"
    click BE_STORAGE "https://github.com/mahaut1/verrier-pro/tree/main/server/storage/"
    click BE_R2_LIB "https://github.com/mahaut1/verrier-pro/blob/main/server/lib/r2.ts"
    click BE_R2_PROXY "https://github.com/mahaut1/verrier-pro/blob/main/server/routes/routes-r2-proxy.ts"
    click BE_DB_CONN "https://github.com/mahaut1/verrier-pro/blob/main/server/db.ts"
    click BE_MAILER "https://github.com/mahaut1/verrier-pro/blob/main/server/utils/mailer.ts"
    click BE_SHARED "https://github.com/mahaut1/verrier-pro/blob/main/shared/schema.ts"
    click MIGR "https://github.com/mahaut1/verrier-pro/tree/main/migrations/"
    click EXT_UPLOADS "https://github.com/mahaut1/verrier-pro/tree/main/uploads/"
    click EXT_INFRA "https://github.com/mahaut1/verrier-pro/blob/main/docker-compose.yml"
    click EXT_BUILD "https://github.com/mahaut1/verrier-pro/blob/main/tsconfig.json"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#00ACC1,color:#006064
    classDef backend fill:#E8F5E9,stroke:#43A047,color:#1B5E20
    classDef database fill:#FFF3E0,stroke:#FB8C00,color:#E65100
    classDef external fill:#ECEFF1,stroke:#90A4AE,color:#37474F
```
