How ju-lio/porteiro-game-erp works
Purpose and Runtime
Porteiro is a Next.js ERP for authoring game content. Editors manage draft content in Supabase Postgres/Storage; the game consumes only an immutable published JSON bundle via a public API. The application shell and route structure start at src/app/layout.tsx, src/app/page.tsx, and Next middleware in src/middleware.ts.
Access Boundary
Authentication is email/password through Supabase, with no self-registration. Middleware protects ERP routes; the game-content endpoint is deliberately public. Server-side Supabase access and auth actions are centralized in src/lib/supabase.ts, src/lib/auth.ts, and src/lib/acoes-auth.ts. RLS has no client policies, making the server/service-key boundary material.
Content Authoring Surface
Each src/app/* route is an editorial domain: world data, characters, gameplay definitions, and publishing. Simple entities use the reusable CRUD/form system in src/componentes/Crud.tsx and src/componentes/campos.tsx; richer domains provide dedicated screens, such as src/app/personagens/pecas/Tela.tsx, src/app/mundo/regioes/Tela.tsx, and src/app/gameplay/regras/Tela.tsx.
Character Art Pipeline
Character assembly is configured through palettes, ordered layers, and uploaded pieces. Uploads are validated against configured canvas dimensions, content-addressed by SHA-256, and stored immutably so historical bundles retain exact art references. Core boundaries are src/componentes/Upload.tsx, src/componentes/PreviewPersonagem.tsx, and src/lib/imagem.ts; authoring routes include src/app/personagens/paletas/Tela.tsx and src/app/personagens/camadas/Tela.tsx.
Game-Definition Model
The ERP expresses game behavior as data rather than game-side code: regions select required documents; documents define visible fields and authentic seal color; professions, items, marks, rules, posters, profiles, and missions define generation and difficulty. Important specialized editors include src/app/gameplay/documentos/Tela.tsx, src/app/gameplay/profissoes/Tela.tsx, and src/app/gameplay/regras/Tela.tsx.
Validation and Publication
Draft content is not directly exposed to the game. Publication builds a snapshot, runs domain validation, and creates versioned immutable bundles; errors block publication while warnings remain advisory. This stage is centered on src/lib/validacao.ts, src/lib/bundle.ts, and src/lib/publicacao.ts, with operator UI at src/app/publicar/Tela.tsx and version management at src/app/publicar/versoes/Tela.tsx.
Delivery API and Persistence
src/app/api/conteudo/route.ts is the game’s single read boundary: it returns the current published bundle or a requested version, isolating the game from database schema and drafts. Supporting server APIs are src/app/api/upload/route.ts, src/app/api/versoes/route.ts, and src/app/api/config/route.ts. The durable data model, constraints, RLS setup, and storage-oriented schema live in supabase/schema.sql.
Main entry points: schema.sql Draft data and art storage · layout.tsx Next.js shell and routes · Tela.tsx Character assembly · publicacao.ts Publication service
Components 16
Application shell
- Next.js shell and routes · ERP entry points and route structure.
src/app/layout.tsx - Route protection · Protects ERP routes while leaving content delivery public.
src/middleware.ts - Server auth boundary · Centralizes server Supabase access and auth actions.
src/lib/supabase.ts
Editorial authoring
- Reusable CRUD forms · Shared forms for simple editorial entities.
src/componentes/Crud.tsx - World and regions · Authors world data and region requirements.
src/app/mundo/regioes/Tela.tsx - Character assembly · Authors palettes, layers, and character pieces.
src/app/personagens/paletas/Tela.tsx - Immutable art upload · Validates dimensions and content-addresses uploaded pieces.
src/componentes/Upload.tsx - Character preview
src/componentes/PreviewPersonagem.tsx - Game-definition editors · Defines documents, professions, rules, and game data.
src/app/gameplay/documentos/Tela.tsx - Draft data and art storage · Holds editable content, immutable assets, constraints, and RLS.
supabase/schema.sql
Publication pipeline
- Publish and versions UI · Operators publish drafts and manage bundle versions.
src/app/publicar/Tela.tsx - Domain validation · Blocks publication errors and reports advisory warnings.
src/lib/validacao.ts - Snapshot bundle builder · Creates versioned immutable JSON snapshots.
src/lib/bundle.ts - Publication service · Orchestrates validation and current-version publication.
src/lib/publicacao.ts
Game delivery
- Published content API · Returns the current or requested immutable bundle only.
src/app/api/conteudo/route.ts - Game client · Consumes published JSON without access to drafts or schema.
Connections 19
- Next.js shell and routes → Route protection: routes pass through
- Route protection → Server auth boundary: checks session
- Next.js shell and routes → Reusable CRUD forms: renders simple editors
- Next.js shell and routes → World and regions: serves route
- Next.js shell and routes → Character assembly: serves route
- Next.js shell and routes → Game-definition editors: serves route
- Reusable CRUD forms → Draft data and art storage: reads and writes drafts
- World and regions → Draft data and art storage: writes draft world data
- Character assembly → Immutable art upload: uploads pieces
- Immutable art upload → Draft data and art storage: stores immutable assets
- Character assembly → Character preview: previews layer assembly
- Game-definition editors → Draft data and art storage: writes game definitions
- Publish and versions UI → Publication service: requests publication
- Publication service → Domain validation: validates snapshot
- Domain validation → Snapshot bundle builder: valid drafts proceed
- Snapshot bundle builder → Draft data and art storage: reads drafts and stores versions
- Publication service → Draft data and art storage: marks current version
- Published content API → Draft data and art storage: reads published bundles
- Game client → Published content API: fetches current or versioned bundle