How adhistark222/jobform-challenge works
1. This repo is a small, framework-free PHP MVC application built around a single form workflow: render a job submission form, validate input, persist a submission, then show a success page. The runtime is classic LAMP-style containerized PHP with Apache and MySQL, orchestrated by Docker Compose.
2. The web entry point is public/index.php, which acts as a front controller. All browser traffic enters through public/, and the controller layer decides whether the request is a GET render or a POST submission. public/assets/ holds the only client-side assets: form.css for presentation and form.js for progressive enhancement.
3. The central orchestration component is src/controllers/FormController.php. It ties together request handling, CSRF verification, validation, persistence, and view selection. This is the main boundary between HTTP concerns and the rest of the application.
4. Server-side validation is the source of truth and lives in src/helpers/validation/SubmissionValidator.php. It validates form fields, regional selection, and upload-related rules before any database write happens. The README indicates client-side validation exists too, but it is only a UX layer; the server still owns correctness.
5. Data persistence is intentionally thin: src/models/Submission.php performs the insert via PDO, using the DB connection bootstrap in src/helpers/db/connection.php. The architecture here is “controller validates, model writes,” with prepared statements and environment-driven credentials.
6. The database schema is handled outside the app code via flat SQL migration files in migrations/. The current bootstrap migration creates the submissions table, and the repo expects later schema changes to be applied manually or through the provided Makefile/Docker flow rather than through a migration framework.
7. The form’s view layer is server-rendered PHP templates in src/views/form.php and src/views/success.php. The app is designed to work without JavaScript, so the HTML response is the baseline; JavaScript only improves interaction and feedback. Output escaping is part of the rendering boundary.
8. Static reference data is stored in data/regions.json and is shared across server and client behavior. The server uses it for validating country/state selections, while the browser script uses the same data to drive dependent dropdown behavior. That makes the JSON file a shared domain boundary rather than a persistence layer.
9. File upload handling is part of the submission flow and is treated as a security boundary. The README describes server-side checks for extension allowlist, MIME verification, size limits, and randomized filenames, with uploads stored outside the web root. This keeps the public document root separate from user-provided files.
10. Email notification is deliberately not part of the completed architecture yet. src/helpers/mail/SubmissionMailer.php exists as a placeholder, but the README says email delivery is deferred. That means the current production flow ends at database persistence plus success confirmation, not outbound messaging.
11. The test suite in tests/ is a native PHP harness, not a PHPUnit-based stack. It covers the connection layer, validator, model, and controller flow, and the README notes one intentionally failing test for the deferred mailer. This makes the repo’s behavioral boundaries explicit and review-friendly.
12. Overall, the architecture is a single-submit workflow with clear separation between HTTP handling, validation, persistence, and presentation. The main data flow is: browser form → controller → validator/CSRF checks → model/DB insert → success view, with JavaScript and shared JSON only enhancing the user experience rather than defining core behavior.
Main entry points: FormController.php Form controller · index.php Front controller · Submission.php Submission model · SubmissionValidator.php Validator
Components 19
Web entry
Browser-facing entrypoint and static assets.
- Front controller · Routes browser requests into the app and chooses GET/POST handling.
public/index.php - Form CSS · Presentation styling for the submission form.
public/assets/css/form.css - Form JS · Progressive enhancement for dependent fields and UX feedback.
public/assets/js/form.js
Application
Controller, validation, model, views, and helpers.
- Form controller · Coordinates CSRF, validation, persistence, and view selection.
src/controllers/FormController.php - Validator · Authoritative rules for fields, regions, and upload constraints.
src/helpers/validation/SubmissionValidator.php - Submission model · Performs the database insert for a valid submission.
src/models/Submission.php - DB connection · Creates the PDO connection from environment-driven settings.
src/helpers/db/connection.php - Mailer stub · Placeholder for future notification delivery; not part of the completed flow.
src/helpers/mail/SubmissionMailer.php - Form view · Renders the submission form as the baseline HTML response.
src/views/form.php - Success view · Shows the post-submit confirmation page.
src/views/success.php
Shared data
Reference JSON consumed by server and client.
- Regions data · Country/state reference data used by both validation and browser behavior.
data/regions.json
Schema
Manual SQL migrations for database setup.
- Create table · Initial schema for the submissions table.
migrations/20260411-create-submissions.sql - Drop table · Reverse migration for removing the submissions table.
migrations/20260411-drop-submissions.sql
Tests
Native PHP test harness covering core boundaries.
- DB test · Exercises the connection layer against the configured database.
tests/DatabaseConnectionIntegrationTest.php - Flow test · Covers the controller-driven submission path.
tests/FormControllerFlowTest.php - Model test · Verifies submission persistence behavior.
tests/SubmissionModelTest.php - Validator test · Checks validation rules and rejection cases.
tests/SubmissionValidatorTest.php
Runtime
Container and PHP runtime configuration.
- Compose · Defines the PHP, Apache, and MySQL runtime stack.
docker-compose.yml - Dockerfile · Builds the application container image.
Dockerfile
Connections 23
- Front controller → Form controller: dispatches · All browser requests enter through the front controller.
- Front controller → Form view: renders · GET requests produce the form page.
- Front controller → Success view: renders · Successful submission ends on the confirmation page.
- Front controller → Form CSS: serves · Static styling is exposed from the public tree.
- Front controller → Form JS: serves · Client-side enhancement script is exposed from the public tree.
- Form controller → Validator: validates · Controller delegates authoritative input checks.
- Form controller → DB connection: uses · Controller/model flow relies on the configured database connection.
- Form controller → Submission model: persists · Valid submissions are written through the model.
- Form controller → Form view: selects · Invalid or initial requests are rendered as the form.
- Form controller → Success view: selects · Completed submissions move to the success template.
- Submission model → DB connection: pdo · The model inserts through the shared PDO bootstrap.
- Validator → Regions data: reads · Region and country rules are driven by shared reference data.
- Form JS → Regions data: consumes · Browser code uses the same region data for dependent dropdowns.
- Form view → Regions data: uses · The server template can render region options from shared data.
- Create table → Submission model: defines table for · The schema migration creates the table the model writes to.
- Drop table → Create table: reverses · Drop migration is the inverse of the create migration.
- Flow test → Form controller: covers · Flow test exercises controller behavior end to end.
- Validator test → Validator: covers · Validator rules are verified directly.
- Model test → Submission model: covers · Model persistence behavior is tested in isolation.
- DB test → DB connection: covers · Integration test checks database bootstrap.
- Mailer stub → Form controller: deferred from · Mailer exists but is not part of the current submission flow.
- Compose → Dockerfile: builds · Compose orchestrates the application image and services.
- Compose → Front controller: runs · The containerized runtime serves the public entrypoint.