How stepsisstuck/sp-y2-bed-ca works
Project type and purpose
• This is a full-stack web application built with Node.js, Express and MySQL.
• The public/ folder holds static HTML/CSS/JS views (login, register, battle, review, etc.).
• The src/ folder implements an MVC-style REST API: routes → middleware → controllers → models → database.
• Purpose: provide a quiz/battle interface, user authentication, class & question management, customization, and reviews.
File structure
• public/: Client-side UI assets (HTML pages + JS that calls back-end endpoints).
• src/config/db.js: MySQL connection configuration.
• src/routes/*.js: Express route definitions for each resource (auth, battle, class, customization, question, review, spells, user).
• src/middleware/auth.js: JWT verification middleware protecting private routes.
• src/controllers/*.js: Business logic for each resource; calls models to interact with the database.
• src/models/user.js (and any others if expanded): Data-access layer, SQL queries or ORM logic.
• initTable.js / init.sql: Database schema creation/reset scripts.
• src/server.js: Express app setup, static file serving, route mounting, middleware, listening port.
README for additional insights
• Tech stack: bcrypt (password hashing), dotenv (env vars), express, jsonwebtoken (JWT auth), mysql2 (DB), nodemon (dev), supertest (testing), readline-sync.
• Scripts: npm run init_tables to reset schema, npm run run to start server.
• Features: Home, login, register, quiz/question page, battle, user/scoreboard, spell, class, customization, review.
Main components and interactions (to be reflected
a. Client Browser
b. Web Server (Express App)
• Route Layer: authRoutes, questionRoutes, battleRoutes, etc.
• Middleware: JWT Authentication.
• Controller Layer: authController, questionController, battleController, etc.
• Model/Data Layer: user model, question model, class model, etc.
c. Database
• MySQL instance with schema initialized by init.sql.
d. External/Supporting Services
• JWT service (jsonwebtoken library), bcrypt service, dotenv.
1. Client → (HTTP requests for pages/assets) → Express static-file handler → serves HTML/JS/CSS.
2. Client JS → (AJAX/Fetch) → Express API endpoints (routes).
3. Route → Middleware (auth.js) → Controller.
4. Controller → Model → MySQL.
5. Model → Controller → Route → Client (JSON responses).
Architectural patterns and design principles
• MVC-style layering (Routes → Controllers → Models).
• RESTful endpoints grouped by resource.
• Stateless authentication via JWT.
• Single Express monolith (no microservices).
Technologies & frameworks to annotate
• Node.js, Express, mysql2, jsonwebtoken, bcrypt, dotenv.
• Front-end: Vanilla HTML/CSS/JS served from public/.