Skip to content

alvianzf/tick-php-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tick PHP Framework

PHP Version License Status

Tick PHP is a lightweight, convention-over-configuration PHP framework designed for speed and simplicity. It brings the best of modern development practices—like Auto-Discovery, Dependency Injection, and JWT Authentication—to native PHP without the bloat.

✍️ Author

Created by Alvian Zachry Faturrahman.
🌐 Website: https://alvianzf.id


🚀 Features

  • Auto-Discovery Routing: No route files. Your Controller methods define your API.
  • Dependency Injection: Built-in Container auto-wires your Controllers, Services, and Repositories.
  • Database Agnostic:
    • SQL ORM: Fluent API using PDO (MySQL, SQLite, Postgres).
    • NoSQL ODM: File-based or MongoDB support via Document class.
  • Central Configuration: Simple config/ system.
  • Zero-Dependency JWT: Native, secure HS256 Token Authentication.
  • Auto Documentation: Generates swagger.json and Markdown docs automatically.
  • Powerful CLI: Generate resources, run server, and build docs with tick.

📦 Installation

  1. Clone the repository:

    git clone https://github.com/alvianzf/tick-php-framework.git
    cd tick-php-framework
  2. Install dependencies:

    composer install
    # OR
    composer dump-autoload
  3. Start the server:

    php tick serve

    Your API is now running at http://localhost:8080.

🛠 CLI Reference

The tick tool is your best friend.

Command Description
php tick Start the development server (default port 8080).
php tick --port 3000 Start server on a specific port.
php tick g <name> Generate a Resource (Controller, Service, Repo, Model).
php tick g jwt Scaffolds the complete Authentication module.
php tick g swagger Generates swagger.json (OpenAPI 3.0).
php tick g docs Generates API_DOCS.md (Markdown).

🏗 Core Concepts

1. Auto-Discovery Routing

You don't define routes manually. Tick scans your app/ folder.

Structure:

app/
  Users/
    UsersController.php
Method HTTP Verb Route
findAll GET /users
findOne GET /users/:id
create POST /users
update POST /users/:id
remove DELETE /users/:id

2. Dependency Injection

Use constructor injection to manage dependencies. The Container handles the rest.

use App\Users\UsersService;

class UsersController {
    protected $service;

    // Automatic Injection
    public function __construct(UsersService $service) {
        $this->service = $service;
    }
}

💾 Database (ORM & ODM)

Tick PHP supports multiple database connections out of the box.

Configuration

Edit config/database.php to configure your connections.

  • SQL: MySQL, PostgreSQL, SQLite (via PDODriver).
  • NoSQL: MongoDB (via MongoDriver), JSON Files (via JsonDriver).

To switch the default connection:

// config/database.php
'default' => 'mysql',

SQL ORM (Active Record)

For relational databases.

  1. Define a Model:

    namespace App\Users;
    use Tick\Database\Model;
    
    class Users extends Model {
        protected $table = 'users';
        // Optional: Override connection for this specific model
        // protected $connection = 'pgsql'; 
    }
  2. Use it:

    // Create
    Users::create(['name' => 'John', 'email' => 'john@doe.com']);

NoSQL ODM

For document storage.

  1. MongoDB Setup:

    composer require mongodb/mongodb

    Then configure the mongodb connection in config/database.php.

  2. Define a Document:

    use Tick\Database\Document;
    
    class Log extends Document {
        protected $collection = 'logs';
        // Optional: Use MongoDB instead of JSON
        protected $connection = 'mongodb'; 
    }

🔒 Authentication (JWT)

  1. Generate Auth Module:

    php tick g jwt
  2. Protect Routes: Use the AuthMiddleware in your controller.

    use Tick\Middleware\AuthMiddleware;
    
    public function secret($req, $res) {
        (new AuthMiddleware())->handle($req, $res);
        $res->json(['user' => $req->user]);
    }

📄 Documentation Generation

Never write docs manually again.

  • Swagger: php tick g swagger -> Imports into Postman/Swagger UI.
  • Markdown: php tick g docs -> Readable API_DOCS.md for GitHub.

License

This project is open-sourced software licensed under the MIT license.

About

A brand new PHP Framework. Because why not?

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages