# Perf

> Audit et optimisation des performances SaaS. Bottlenecks DB, bundle, Server Components, background jobs. Next.js + Supabase.

- **Type:** Skill
- **Install:** `agentstack add skill-glamgarondiscord-claude-saas-blueprint-perf`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [GlamgarOnDiscord](https://agentstack.voostack.com/s/glamgarondiscord)
- **Installs:** 0
- **Category:** [Databases](https://agentstack.voostack.com/c/databases)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [GlamgarOnDiscord](https://github.com/GlamgarOnDiscord)
- **Source:** https://github.com/GlamgarOnDiscord/claude-saas-blueprint/tree/main/.claude/skills/perf

## Install

```sh
agentstack add skill-glamgarondiscord-claude-saas-blueprint-perf
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

## Phase 1 — Identifier les bottlenecks

**Lancer d'abord :**
```bash
python scripts/project_health.py   # vue globale
```

**Web App (Next.js) :**
- Server Components vs Client Components inutiles (`"use client"` abusif ?)
- Re-renders inutiles (props instables, Context trop large)
- N+1 queries (boucle avec query DB à chaque itération)
- Images non optimisées (pas de `next/image`)
- Composants lourds non lazy-loadés (`dynamic(() => import(...))`)
- Bundle size : analyser `next build` output — alerter si JS client > 500KB
- Pas de `cache()` sur les Server Components qui refetch les mêmes données

**API + DB :**
- Index manquants sur FK et champs de recherche fréquents
- Endpoints sans pagination (retournent tout)
- Opérations lentes dans le handler (email, PDF, webhook) → doivent être async
- Connection pooling Supabase : utiliser le pooler (port 6543), pas direct

**Background jobs :**
- Emails, webhooks, exports PDF, traitements IA → ne JAMAIS bloquer le handler
- Solutions recommandées : **Trigger.dev v4** ou **Inngest** (voir `docs/integrations/ai-tools-2026.md`)
- Pattern : `POST /api/invoice` → créer job → return 202 → Trigger.dev exécute en fond

**Edge :**
- Endpoints légers (auth check, redirects) → Edge Runtime (`export const runtime = 'edge'`)
- DB géo-distribuée pour faible latence globale : **Turso** (SQLite edge) ou **Neon** (serverless Postgres)

## Phase 2 — Quick wins (par ordre d'impact)

1. **Index DB manquants** — impact immédiat, 0 code à changer
   ```sql
   CREATE INDEX ON public.invoices (organization_id, created_at DESC);
   ```
2. **Pagination** sur tous les endpoints de liste (`limit` + `cursor`)
3. **Lazy load** composants lourds (éditeurs, charts, maps)
4. **Cache React Query** : `staleTime: 5 * 60 * 1000` sur les queries stables
5. **next/image** pour toutes les images + formats WebP/AVIF
6. **Debounce** les inputs de recherche (300ms)
7. **Passer en async** les opérations lentes (email → Resend en background)

## Phase 3 — Optimisations avancées

- **Streaming + Suspense** : perceived performance sur les pages lentes
- **ISR** : contenu semi-statique avec `revalidate`
- **PgBouncer / Supabase pooler** : connection pooling DB (déjà intégré Supabase)
- **Trigger.dev** : background jobs pour tâches IA longues (génération, analyse)

## Output

Rapport avec :
- Bottlenecks identifiés par sévérité (CRITICAL / WARNING / INFO)
- Quick wins appliqués immédiatement
- Recommandations pour les optimisations avancées + estimation d'impact

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [GlamgarOnDiscord](https://github.com/GlamgarOnDiscord)
- **Source:** [GlamgarOnDiscord/claude-saas-blueprint](https://github.com/GlamgarOnDiscord/claude-saas-blueprint)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-glamgarondiscord-claude-saas-blueprint-perf
- Seller: https://agentstack.voostack.com/s/glamgarondiscord
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
