How valenbaldo/pregunlam---proyecto-web-ii works
Project Type and Purpose
• This is a monolithic, server-rendered full-stack web application written in PHP (PHP 7+) with a simple MVC-style folder structure.
• Its purpose is a basic “Pokédex” CRUD system used for teaching/refactoring exercises: user registration, login, listing entries, detailed views, and image uploads.
File Structure Analysis
• Top-level directories:
• config/ – stores database and application configuration (config.ini).
• controller/ – HTTP request handlers (AdminController, LoginController, JuegoController, etc.).
• model/ – data-access classes matching each controller (AdminModel, LoginModel, etc.), using mysqli.
• helper/ – utility classes for routing (NewRouter), DB connection (MyConexion), template rendering (MustacheRenderer, IncludeFileRenderer), config instantiation (ConfigFactory).
• vista/ – Mustache template files for view rendering (header, footer, various pages).
• public/ – publicly exposed assets (CSS, JavaScript).
• imagenes/ – image storage (placeholders and uploads).
• index.php – front controller / entry point for non-MVC legacy routes.
• database.sql – initial database schema.
Key Insights from README
• The system connects directly to MySQL without prepared statements; has repetitive connection code and plain-text passwords.
• Typical CRUD pages: index.php (list/search), ver.php (view), nuevo.php (create), editar.php (update), borrar.php (delete).
• Uses Mustache for templating, but no advanced layering.
Main Components
a. Client Browser
• Requests pages, submits forms, loads CSS/JS from public/.
b. Web Server
• Apache or built-in PHP server receives HTTP requests, directs to index.php or MVC router (NewRouter).
c. Routing Layer (helper/NewRouter.php)
• Maps URLs to controller methods.
d. Controller Layer (controller/*.php)
• Receives input, invokes helper classes, coordinates data fetch via models, selects templates.
e. Service/Helper Layer (helper/*.php)
• ConfigFactory: loads config.ini
• MyConexion: establishes mysqli connection
• MustacheRenderer/IncludeFileRenderer: renders .mustache templates
f. Model Layer (model/*.php)
• Executes SQL queries via mysqli, returns raw data arrays.
g. View Layer (vista/*.mustache)
• Templates for page layout, includes header.mustache and footer.mustache
h. File System Storage
• imagenes/ folder: stores uploaded images; file I/O by controllers/models.
i. Database
• MySQL/MariaDB instance storing tables created by database.sql
Relationships and Data Flow
• Browser → HTTP request → Web Server
• Web Server → NewRouter → Controller
• Controller ↔ MyConexion (via helper) ↔ MySQL Database
• Controller ↔ Model (fetch/save data)
• Controller → MustacheRenderer → View HTML
• Controller ↔ File System (image upload/delete in imagenes/)
• Browser ← HTML + CSS/JS ← Server
Architectural Patterns and Design Principles
• Layered (MVC-like) architecture separating Controllers, Models, Views.
• Single codebase monolith—no microservices.
• Helpers as thin service layer for cross-cutting concerns (config, DB, templating).
Technologies, Frameworks, Libraries
• PHP 7+ with mysqli extension
• MySQL/MariaDB database
• Mustache templating engine (helper/MustacheRenderer)
• Plain-text config in config/config.ini
• Static assets served from public/