php-framework

PHP Full-Stack MVC Framework - Doctrine, Vite, ...

MIT License

Stars
0
Committers
2

PHP Full-Stack Framework offering both front and back - end options to run simultaneously! Includes a RESTful API and Model-View-Controller (MVC) system with integrated Doctrine and Vite.

Controllers for Client and Api to render views and routes as needed. Usage of blade.php templating engine with live HMR Vite server for asset bundling (includes asset mapper for production builds).

Back-end Api with Model & Entity Controller that handles routing of Model/Action and Entity CRUD operations based on Request Method. Doctrine Console, Entities and Migrations to create flawless ORM Schemas. Custom useful Utils like Token that manages JSON Web Tokens (JWT). Pre-done Auth Model, User Entity connected with Media Entity by OneToMany Relation to keep track of Author of uploaded media files (optimize, resize and image format/type change included).

Easy configuration and safe .env variables.

โšก๏ธ Features

Overview

  • MVC System
    • Config, Bootstrap, Router
    • Preferred mode (api/client)
  • Front-end
    • Vite (js, ts, css, scss, tailwind)
    • Blade (Views, Components, Layouts)
  • Back-end API
    • RESTful Entities (EntityController)
      • CRUD
      • Media
        • Upload
        • Optimize
        • Resize
        • Quality
        • Format
    • Models (ModelController)
      • Auth
    • Doctrine (DBAL, ORM)
      • Entities
      • Migrations
    • Custom Utils
      • Helpers
        • Helper
        • Page Helper
      • Database
      • Doctrine
      • JSON Web Tokens (JWT)
    • Nette
      • Database Explorer
      • Tracy
  • Environment (.env)
  • Prettier & ESLint
  • .htaccess

๐Ÿงฌ Structure

app/ - App's Main Code (Controller, Entity, Model, View) bin/ - Console for Doctrine config/ - Main config of app log/ - All types of Error logs migrations/ - Doctrine DB Migrations public/ - Publicly accessible (Dist assets, Routing, Media) src/ - Developer Source Files (Assets, Utils) temp/ - Storage for Temporary Files and Caches

๐Ÿง  Technologies

  • PHP
  • Vite
  • Blade
  • Doctrine
  • Nette DB
  • JSON Web Tokens (JWT)
  • (TS, SCSS, Tailwind, Prettier, ESLint, ...)

๐Ÿ› ๏ธ Installation Instructions

To start a project with this framework you can either clone this repository or download its source code from latest release

Requirements

  • ๐Ÿ‘จโ€๐Ÿ’ป Composer
  • ๐Ÿ“ฆ Node Package Manager (pnpm - recommended)

Install dependencies

# php back-end part
composer install

# vite front-end part
pnpm install

Assets

With usage of PageHelper you can add assets that will be rendered automatically on page load NOTE: Ensure that all your assets are defined in vite.config!

If everything is set up correctly, assets are automatically mapped, resolved and added to the page. In development mode, live Vite server versions are loaded. (if that fails, it attempts to load the production assets from public/dist directory)

# Add assets to the Page/View
PageHelper::setAssets(['ts/app.ts']);

# Preview assets in real time (Vite + HMR)
pnpm run dev

# Build assets (src/assets -> public/dist)
pnpm build

Setup .env

  • Database Credentials
  • JWT Secret and Algorithm
  • Vite Server Destination
  • Preferred mode (client / api)
# to dupe example.env as .env
cp example.env .env

๐Ÿ“ Entity Guide

Entity CRUD operations depends on Request Methods Entity Schema returns tables / table with columns

Routes

Operations: /[entity]/[id]

  • GET - Read
  • POST - Create
  • PUT - Replace
  • PATCH - Update
  • DELETE - Delete
  • OPTIONS - Preflight (always return 200)

Schema: /schema/[entity]

๐Ÿ“œ Model Guide

Model routes are automatically generated by "action..." methods commonly written in camel case (e.g. actionGet() accessed by /[model]/get)

Models default action can be made by setting only action method -> /[model]/

Models can be nested as much as you want by namespaces Model\Users\Admin -> /Users/Admin/[action]

Routes Summary

Default Method: /[model]/ Model Methods: /[model]/[action] Nested Models: /[namespace]/[model]/[action]

๐Ÿ“š Doctrine Guide

The Doctrine console is in "bin/console" EntityManager config location "src/Utils/Doctrine.php" Base migrations config, which is in root "migrations.php" And migration files are stored in "migrations/"

Console

# To run doctrine console
php bin/console ...

# if you need commands list
php bin/console list

๐Ÿงน Linting

This project utilizes Prettier and ESLint for code formatting and style consistency

# Check for linting errors and warnings
pnpm lint
pnpm prettier

# Automatically fix linting errors and warnings
pnpm lint:fix
pnpm prettier:fix

Related Projects