How landercor/willpig_studio works
1. Overall shape
Willpig Studio is a server-rendered Node.js application built with Express and modern ESM imports. It follows a classic MVC split: HTTP routes in src/routes, request handling in src/controllers, persistence models in src/models, and EJS views in src/views.
2. Application entry and composition
The startup path is split between server.js and src/app.js. This usually means server.js boots the process, while src/app.js assembles middleware, session/auth setup, routes, and static assets into one Express app.
3. Presentation layer
The UI is rendered on the server with EJS templates, not a SPA. Reusable layout pieces live under src/views/layouts and src/views/partials. The main user-facing pages cover landing, login/register, library/search, story reading, chapter editing, profiles, and story management.
4. Static frontend assets
All browser-delivered assets sit under public/: modular CSS, page-specific styles, JavaScript, fonts, and images. The CSS structure suggests a componentized design system with shared base/layout/utilities plus view-specific styles for auth, editor, home, profile, and story pages.
5. Route boundaries
The route layer is separated by feature area: auth, home, story, chapter, and user. This indicates domain-based request routing rather than a single monolithic router, which helps keep flows isolated by subsystem.
6. Controller layer and business flow
Controllers implement the application logic for each domain: authentication, story browsing/management, chapter editing, home/library views, and user profile actions. The controllers are the main bridge between form submissions/page requests and the underlying data models.
7. Data model and persistence
The model layer contains entities named Cuento, Capitulo, CuentaUsuario, Categoria, Etiqueta, and Notificacion. src/models/index.js likely wires model associations. The domain is clearly relational: users own or interact with stories, stories contain chapters, and stories can be organized by categories/tags and surfaced through notifications.
8. Database and backend services
src/config/db.js plus the README indicate Supabase as the backend platform, with PostgreSQL as the primary database. There is also a separate test DB config, so the app supports at least one non-production environment. The architecture depends on a hosted relational database rather than local file storage for core content.
9. Authentication and session management
Auth is a mixed system: local password handling uses bcrypt, sessions are managed server-side with express-session, and Google login is configured through Passport.js in src/config/passport.js. This creates two auth entry paths: traditional email/password and Google OAuth2.
10. Media upload and storage
Story cover images are handled through multer in src/middlewares/upload.js, then stored outside the app runtime in Supabase Storage. There are also bucket-creation scripts in scripts/ and src/scripts/, which suggests storage setup is part of the project lifecycle.
11. Content editing flow
The chapter editor is a notable subsystem: server-side pages for editor, chapter_editor, and related story edit screens are paired with Quill JS on the client. The flow is likely create/edit chapter content in the browser, submit it to Express, then persist it to the database.
12. Operational utilities
Environment configuration is managed with dotenv, and the presence of config/test.js plus config/testDB.js suggests environment-specific settings. The repository also contains a node_modules-driven Node toolchain and likely uses Nodemon for local development, but the architectural center remains a server-rendered Express app backed by Supabase/Postgres.
Main entry points: app.js App setup · db.js DB config · index.js Model index · views Pages
Components 24
Runtime
Process bootstrap and Express composition
Web layer
Routes, controllers, and rendered pages
- Auth routes · Login, registration, password recovery, OAuth
src/routes/auth.routes.js - Home routes · Landing and library/search pages
src/routes/home.routes.js - Story routes · Story browsing and management
src/routes/story.routes.js - Chapter routes · Chapter editing and reading flows
src/routes/chapter.routes.js - User routes · Profile and account actions
src/routes/user.routes.js - Auth controller · Authentication and session logic
src/controllers/auth.controller.js - Content controllers · Home, story, and chapter business flow
- User controller · Profile and account management
src/controllers/user.controller.js - Pages · Server-rendered screens for landing, auth, reading, and editing
src/views - Layouts · Shared header, footer, and utilities
src/views/layouts
Data layer
Persistence models and database/auth configuration
- Model index · Associations and model composition
src/models/index.js - Stories · Story records
src/models/Cuento.js - Chapters · Chapter records
src/models/Capitulo.js - Accounts · User accounts
src/models/CuentaUsuario.js - Tags · Categories, labels, and notifications
src/models/Categoria.js - DB config · Supabase/PostgreSQL connection settings
src/config/db.js - Passport config · Google login strategy setup
src/config/passport.js - Test config · Test environment settings
src/config/test.js
Static assets
Browser-delivered styles, scripts, fonts, and images
Operations
Setup and maintenance scripts
- Bucket setup · Supabase storage bucket creation
scripts/create-bucket.js
Connections 34
- server.js → App setup: boots · Server starts the Express application
- App setup → Auth routes: mounts · Registers auth routing
- App setup → Home routes: mounts · Registers home and library routing
- App setup → Story routes: mounts · Registers story routing
- App setup → Chapter routes: mounts · Registers chapter routing
- App setup → User routes: mounts · Registers user routing
- Auth routes → Auth controller: delegates · Routes hand off to auth logic
- Home routes → Content controllers: delegates · Routes hand off to page logic
- Story routes → Content controllers: delegates · Routes hand off to story logic
- Chapter routes → Content controllers: delegates · Routes hand off to chapter logic
- User routes → User controller: delegates · Routes hand off to profile logic
- Auth controller → Passport config: uses · OAuth and session strategy
- Auth controller → Accounts: reads/writes · Authenticates and updates user accounts
- Content controllers → Stories: reads/writes · Story browsing and management
- Content controllers → Chapters: reads/writes · Chapter editing and reading
- Content controllers → Tags: reads/writes · Categorization and notifications
- User controller → Accounts: reads/writes · Profile and account actions
- Model index → Stories: wires · Defines model relations
- Model index → Chapters: wires · Defines model relations
- Model index → Accounts: wires · Defines model relations
- Model index → Tags: wires · Defines model relations
- Stories → DB config: persists to · Stored in PostgreSQL via Supabase
- Chapters → DB config: persists to · Stored in PostgreSQL via Supabase
- Accounts → DB config: persists to · Stored in PostgreSQL via Supabase
- Tags → DB config: persists to · Stored in PostgreSQL via Supabase
- Pages → Styles: styled by · Rendered pages consume shared and page CSS
- Pages → Client JS: enhanced by · Client-side interactions and editor behavior
- Layouts → Pages: composed into · Shared header/footer pieces wrap pages
- App setup → DB config: configures · Loads database connection and environment settings
- App setup → Pages: renders · Express serves EJS pages
- App setup → Styles: serves · Static CSS delivery
- App setup → Client JS: serves · Static JS delivery
- App setup → Media: serves · Static fonts and images
- Bucket setup → DB config: provisions · Creates storage bucket for uploads