# adhistark222/jobform-challenge architecture

> Architecture diagram of the GitHub repository adhistark222/jobform-challenge, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adhistark222/jobform-challenge
- Repository: https://github.com/adhistark222/jobform-challenge

## Overview

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: [`src/controllers/FormController.php`](https://github.com/adhistark222/jobform-challenge/blob/main/src/controllers/FormController.php) (Form controller), [`public/index.php`](https://github.com/adhistark222/jobform-challenge/blob/main/public/index.php) (Front controller), [`src/models/Submission.php`](https://github.com/adhistark222/jobform-challenge/blob/main/src/models/Submission.php) (Submission model), [`src/helpers/validation/SubmissionValidator.php`](https://github.com/adhistark222/jobform-challenge/blob/main/src/helpers/validation/SubmissionValidator.php) (Validator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Web entry"]
  node_public_index["Front controller<br/>HTTP entry<br/>[index.php]"]
  node_form_css["Form CSS<br/>static style<br/>[form.css]"]
  node_form_js["Form JS<br/>client enhancement<br/>[form.js]"]
end

subgraph group_src["Application"]
  node_form_controller["Form controller<br/>request orchestration<br/>[FormController.php]"]
  node_submission_validator["Validator<br/>server validation"]
  node_submission_model[("Submission model<br/>persistence<br/>[Submission.php]")]
  node_db_connection["DB connection<br/>pdo bootstrap<br/>[connection.php]"]
  node_submission_mailer["Mailer stub<br/>deferred email"]
  node_form_view["Form view<br/>server template<br/>[form.php]"]
  node_success_view["Success view<br/>server template<br/>[success.php]"]
end

subgraph group_data["Shared data"]
  node_regions_json["Regions data<br/>shared reference<br/>[regions.json]"]
end

subgraph group_migrations["Schema"]
  node_create_migration["Create table<br/>sql migration"]
  node_drop_migration["Drop table<br/>sql migration"]
end

subgraph group_tests["Tests"]
  node_db_test["DB test<br/>integration test"]
  node_controller_test["Flow test<br/>integration test"]
  node_model_test["Model test<br/>unit test"]
  node_validator_test["Validator test<br/>unit test"]
end

subgraph group_infra["Runtime"]
  node_docker_compose["Compose<br/>container orchestration<br/>[docker-compose.yml]"]
  node_dockerfile["Dockerfile<br/>php runtime"]
end

node_public_index -->|"dispatches"| node_form_controller
node_public_index -->|"renders"| node_form_view
node_public_index -->|"renders"| node_success_view
node_public_index -->|"serves"| node_form_css
node_public_index -->|"serves"| node_form_js
node_form_controller -->|"validates"| node_submission_validator
node_form_controller -->|"uses"| node_db_connection
node_form_controller -->|"persists"| node_submission_model
node_form_controller -->|"selects"| node_form_view
node_form_controller -->|"selects"| node_success_view
node_submission_model -->|"pdo"| node_db_connection
node_submission_validator -->|"reads"| node_regions_json
node_form_js -->|"consumes"| node_regions_json
node_form_view -->|"uses"| node_regions_json
node_create_migration -->|"defines table for"| node_submission_model
node_drop_migration -.->|"reverses"| node_create_migration
node_controller_test -->|"covers"| node_form_controller
node_validator_test -->|"covers"| node_submission_validator
node_model_test -->|"covers"| node_submission_model
node_db_test -->|"covers"| node_db_connection
node_submission_mailer -.->|"deferred from"| node_form_controller
node_docker_compose -->|"builds"| node_dockerfile
node_docker_compose -->|"runs"| node_public_index

click node_public_index "https://github.com/adhistark222/jobform-challenge/blob/main/public/index.php"
click node_form_css "https://github.com/adhistark222/jobform-challenge/blob/main/public/assets/css/form.css"
click node_form_js "https://github.com/adhistark222/jobform-challenge/blob/main/public/assets/js/form.js"
click node_form_controller "https://github.com/adhistark222/jobform-challenge/blob/main/src/controllers/FormController.php"
click node_submission_validator "https://github.com/adhistark222/jobform-challenge/blob/main/src/helpers/validation/SubmissionValidator.php"
click node_submission_model "https://github.com/adhistark222/jobform-challenge/blob/main/src/models/Submission.php"
click node_db_connection "https://github.com/adhistark222/jobform-challenge/blob/main/src/helpers/db/connection.php"
click node_submission_mailer "https://github.com/adhistark222/jobform-challenge/blob/main/src/helpers/mail/SubmissionMailer.php"
click node_form_view "https://github.com/adhistark222/jobform-challenge/blob/main/src/views/form.php"
click node_success_view "https://github.com/adhistark222/jobform-challenge/blob/main/src/views/success.php"
click node_regions_json "https://github.com/adhistark222/jobform-challenge/blob/main/data/regions.json"
click node_create_migration "https://github.com/adhistark222/jobform-challenge/blob/main/migrations/20260411-create-submissions.sql"
click node_drop_migration "https://github.com/adhistark222/jobform-challenge/blob/main/migrations/20260411-drop-submissions.sql"
click node_db_test "https://github.com/adhistark222/jobform-challenge/blob/main/tests/DatabaseConnectionIntegrationTest.php"
click node_controller_test "https://github.com/adhistark222/jobform-challenge/blob/main/tests/FormControllerFlowTest.php"
click node_model_test "https://github.com/adhistark222/jobform-challenge/blob/main/tests/SubmissionModelTest.php"
click node_validator_test "https://github.com/adhistark222/jobform-challenge/blob/main/tests/SubmissionValidatorTest.php"
click node_docker_compose "https://github.com/adhistark222/jobform-challenge/blob/main/docker-compose.yml"
click node_dockerfile "https://github.com/adhistark222/jobform-challenge/tree/main/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_public_index,node_form_css,node_form_js toneBlue
class node_form_controller,node_submission_validator,node_submission_model,node_db_connection,node_submission_mailer,node_form_view,node_success_view toneAmber
class node_regions_json toneMint
class node_create_migration,node_drop_migration toneRose
class node_db_test,node_controller_test,node_model_test,node_validator_test toneIndigo
class node_docker_compose,node_dockerfile toneTeal
```

## Components

### Web entry

Browser-facing entrypoint and static assets.

- [Front controller](https://github.com/adhistark222/jobform-challenge/blob/main/public/index.php): HTTP entry · Routes browser requests into the app and chooses GET/POST handling. · `public/index.php`
- [Form CSS](https://github.com/adhistark222/jobform-challenge/blob/main/public/assets/css/form.css): static style · Presentation styling for the submission form. · `public/assets/css/form.css`
- [Form JS](https://github.com/adhistark222/jobform-challenge/blob/main/public/assets/js/form.js): client enhancement · Progressive enhancement for dependent fields and UX feedback. · `public/assets/js/form.js`

### Application

Controller, validation, model, views, and helpers.

- [Form controller](https://github.com/adhistark222/jobform-challenge/blob/main/src/controllers/FormController.php): request orchestration · Coordinates CSRF, validation, persistence, and view selection. · `src/controllers/FormController.php`
- [Validator](https://github.com/adhistark222/jobform-challenge/blob/main/src/helpers/validation/SubmissionValidator.php): server validation · Authoritative rules for fields, regions, and upload constraints. · `src/helpers/validation/SubmissionValidator.php`
- [Submission model](https://github.com/adhistark222/jobform-challenge/blob/main/src/models/Submission.php): persistence · Performs the database insert for a valid submission. · `src/models/Submission.php`
- [DB connection](https://github.com/adhistark222/jobform-challenge/blob/main/src/helpers/db/connection.php): pdo bootstrap · Creates the PDO connection from environment-driven settings. · `src/helpers/db/connection.php`
- [Mailer stub](https://github.com/adhistark222/jobform-challenge/blob/main/src/helpers/mail/SubmissionMailer.php): deferred email · Placeholder for future notification delivery; not part of the completed flow. · `src/helpers/mail/SubmissionMailer.php`
- [Form view](https://github.com/adhistark222/jobform-challenge/blob/main/src/views/form.php): server template · Renders the submission form as the baseline HTML response. · `src/views/form.php`
- [Success view](https://github.com/adhistark222/jobform-challenge/blob/main/src/views/success.php): server template · Shows the post-submit confirmation page. · `src/views/success.php`

### Shared data

Reference JSON consumed by server and client.

- [Regions data](https://github.com/adhistark222/jobform-challenge/blob/main/data/regions.json): shared reference · Country/state reference data used by both validation and browser behavior. · `data/regions.json`

### Schema

Manual SQL migrations for database setup.

- [Create table](https://github.com/adhistark222/jobform-challenge/blob/main/migrations/20260411-create-submissions.sql): sql migration · Initial schema for the submissions table. · `migrations/20260411-create-submissions.sql`
- [Drop table](https://github.com/adhistark222/jobform-challenge/blob/main/migrations/20260411-drop-submissions.sql): sql migration · Reverse migration for removing the submissions table. · `migrations/20260411-drop-submissions.sql`

### Tests

Native PHP test harness covering core boundaries.

- [DB test](https://github.com/adhistark222/jobform-challenge/blob/main/tests/DatabaseConnectionIntegrationTest.php): integration test · Exercises the connection layer against the configured database. · `tests/DatabaseConnectionIntegrationTest.php`
- [Flow test](https://github.com/adhistark222/jobform-challenge/blob/main/tests/FormControllerFlowTest.php): integration test · Covers the controller-driven submission path. · `tests/FormControllerFlowTest.php`
- [Model test](https://github.com/adhistark222/jobform-challenge/blob/main/tests/SubmissionModelTest.php): unit test · Verifies submission persistence behavior. · `tests/SubmissionModelTest.php`
- [Validator test](https://github.com/adhistark222/jobform-challenge/blob/main/tests/SubmissionValidatorTest.php): unit test · Checks validation rules and rejection cases. · `tests/SubmissionValidatorTest.php`

### Runtime

Container and PHP runtime configuration.

- [Compose](https://github.com/adhistark222/jobform-challenge/blob/main/docker-compose.yml): container orchestration · Defines the PHP, Apache, and MySQL runtime stack. · `docker-compose.yml`
- [Dockerfile](https://github.com/adhistark222/jobform-challenge/tree/main/Dockerfile): php runtime · Builds the application container image. · `Dockerfile`

## Connections

- 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.
