Development - Coding Standards

Created: 2022-02-24 14:14:43 || Updated: 2022-04-17 17:38:13

Variable Naming

  • Javascript - camelCase
  • PHP - under_score separator all lowercase

Formatting

  • Tab Spacing - 2 spaces for everything except post.php which is 4 spaces

SQL Table Structure

  • Table Naming: Using plural naming. Example users
  • Column Naming: Define by non-plural word of the table name separated with an underscore. Example table users has user_id user_first_name
  • Primary Keys: Defined first and are defined with the non-plural word of the table with id at the end example user_id
  • Foreign Keys: Defined by the linked table primary_key field name ex table name companies foreign key company_user_id links to table users primary key user_id
  • Field Ordering: Primary Key -> Data Fields -> created_at -> Foreign Keys

Code Structure

  • Procedural Code along with some object oriented ideas to make the code cleaner and simpler as well as being easier to contribute.
  • Less is more approach, but sometime more for better code explanation
  • Consider how others will use features. Generic features/code/concepts that can be useful to everyone are more helpful than a feature that solves your specific unique requirement.

File/Folder Structure

  • /api
  • /css
  • /js
  • /plugins
    • /bootstrap
    • /phpMailer
    • /Jquery
  • /uploads

Crucial PHP Files

  • ajax.php - Used to dynamically load/populate content
  • post.php - This file is used for all forms to POST to as well as GET. This acts as both the "model" and "controller" in a traditional MVC architecture.
  • check_config.php - Checks to see if a user is logged in otherwise send to login screen
  • header.php - Beginning of HTML data and added CSS libraries
  • footer.php - End of HTML Data and added js Libraries
  • nav.php - Main top navigation menu
  • config.php - DB Connection and other defined PHP vars
  • README - General info about the app: Install guide, Documentation, copyright etc
  • setup.php - Initial setup file (configures database, config.php, etc)

PHP File naming

  • section_element_action_function.php ex user_add_modal.php or client_contact_add_modal.php