https://github.com/sagnikrivud/free-frame-framework
PHP based MVC Framework
https://github.com/sagnikrivud/free-frame-framework
framework microservice php8
Last synced: 8 months ago
JSON representation
PHP based MVC Framework
- Host: GitHub
- URL: https://github.com/sagnikrivud/free-frame-framework
- Owner: sagnikrivud
- Created: 2025-05-12T11:18:36.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-06-02T11:31:00.000Z (10 months ago)
- Last Synced: 2025-06-02T15:34:22.060Z (10 months ago)
- Topics: framework, microservice, php8
- Language: PHP
- Homepage: https://packagist.org/packages/freeframe/freeframe
- Size: 380 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FreeFrame â A Lightweight PHP Framework

FreeFrame is a lightweight, modular PHP framework inspired by Laravel and CakePHP, built for rapid development with minimal setup. It comes with its own powerful CLI tool named `free`, allowing you to scaffold components, manage your project structure, and streamline development.
---
### ð Features
- Custom CLI tool â free lets you create controllers, models, and run other useful commands.
- Easy to use â Designed to be lightweight and modular, FreeFrame is perfect for building your own web applications.
- Automatic routing â Route your requests easily to the correct controllers and methods.
- Environment handling â Use .env files for configuration, making it easy to manage different environments.
---
### System Compatibility
- PHP 8.0
- Composer 2.0
- Apache (XAMPP, LAMP)
- PDO Driver
- MongoDB driver
### ð§ą Framework Structure
```text
my-app/
âââ App/
â âââ Controllers/
| |ââ Middlewares/
â âââ Models/
â âââ Services/
â âââ Helpers/
âââ config/
âââ core/
| âââ bootstrap.php
| |ââ Router.php
âââ public/
â âââ index.php
âââ resources/
â âââ pages/
â âââ assets/
âââ routes/
â âââ route.php
âââ storage/
â âââ Logs/
| âââ Public/
â âââ Cache/
|
âââ .env
âââ .env.example
âââ free
âââ Execute.sh
âââ composer.json
âââ README.md
```
### Implemented Features
```text
â CLI (php free)
â Routing system (routes/route.php)
â Controllers (make:controller)
â Services (make:service)
â Models (make:model)
â Middleware (make:middleware)
â Logging system (error.log)
â log:clear and storage:link commands
â Route listing (route:list)
â Auto exception logging
â Basic MySQL & MongoDB integration setup
â Custom command generator (make:command)
â Debugger placeholder
â CLI server (php free serve)
```
### ðïļ Namespace or Class not found issue resolved
```sh
$ composer dump-autoload
```
### Publish Framework
- Tag latest commit with a semantic version:
```sh
$ git tag v1.0.0
$ git push origin v1.0.0
```
- Submit Framework repo at Packagist
https://packagist.org/packages, then click on `Update`
- Create a blnak project `$ composer create-project freeframe/freeframe my-app ^2.5`
- Specify version `$ composer create-project freeframe/freeframe my-app "2.5"`
- Alter try `$ composer create-project freeframe/freeframe my-app --stability=dev`
### â
Install Symfony Console via Composer
1. Install
```sh
$ composer require symfony/console
```
2. Create CLI Entry File
```text
framework/
âââ ignite_file â this is CLI
âââ composer.json
âââ vendor/
```
### ðïļ Create a Project
```sh
$ composer create-project freeframe/freeframe my-app --stability=dev
```
### Start Server
```sh
$ php free serve
```
> Open `http://localhost:8000/`
### List of Commands
> Check version
```sh
$ php free --version
```
```sh
FreeFrame CLI v1.0.0
```
### Create Controller
```sh
$ php free make:controller HomeController
```
> `App\Controllers\New-Controller`
### Create Service Classes under App/Services
```sh
$ php free make:service UserService
```
### Create Model
```sh
$ php free make:model User
```
> Created at `App/Models` folder
### Clear Error logs
```sh
$ php free log:clear
```
### Create Storage link in public
```sh
$ php free storage:link
```
### See Available commands
```sh
$ php free help
```

### List of Routes
```sh
$ php free route:list
```
### Create Middleware
```sh
$ php free make:middleware AuthMiddleware
```
### Connect database (Default Support `Mysql` & `MongoDB`)
> At Controller or Service Layer
```php
use Core\Database;
$db = (new Database())->getConnection();
// Example RDB query
if ($db instanceof PDO) {
$stmt = $db->query("SELECT * FROM users");
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
// Example MongoDB query:
if ($db instanceof \MongoDB\Database) {
$collection = $db->users;
$users = $collection->find()->toArray();
}
```
### Install Mongodb extension for PHP
> Download extension for Windows from here according to PHP version: [Click](https://pecl.php.net/package/mongodb/2.0.0/windows)
> Check thread safety or not
```sh
$ php -i > phpinfo.txt
```
> Search `Thread Safety`, ðĄ If Thread Safety is enabled, you need the TS version of the MongoDB DLL.
If it's disabled, download the NTS version.
> Place the downloaded .dll into: `C:\xampp\php\ext`
> Open your php.ini file `(in C:\xampp\php)` and add: `extension=mongodb`
> Restart Apache using the XAMPP control panel.
```sh
extension=php_mongodb.dll
```
### Install Cassandra DB for PHP
> Download and install cassndra dll (windows) file from here: [Click](https://pecl.php.net/package/cassandra/1.3.2/windows)
> Unzip the Zip and take `php_cassandra.dll` file and then place it on `C:\xampp\php\ext`, after that
Open Open your php.ini file `(in C:\xampp\php)` and add: `extension=php_cassandra.dll`
- For linux
```sh
$ sudo pecl install cassandra
```
Add this extension at php.ini file `(in C:\xampp\php)`
```php
extension=cassandra.so
```
### Migrate Tables from RDB
```sh
$ php free migrate
```
### Create Custom Request
```sh
$ php free make:request CommonRequest
```
```php
use Core\Http\Request;
use Core\Http\Response;
use App\Requests\CommonRequest;
public function store()
{
$request = new Request();
$userRequest = new CommonRequest();
if (!$userRequest->validate($request->all())) {
return Response::json(['errors' => $userRequest->errors()], 422)->send();
}
// Proceed with storing user...
return Response::json(['message' => 'User created successfully']);
}
```
### ðĪ Auth Scaffolding feature (JWT Authentication)
```sh
$ php free auth:install
```
> `AuthController`, `AuthMiddleware` will created `JWT secret` will append in `.env`
### ðĄ ORM Relationships
```php
use App\Models\Profile;
use App\Models\Post;
use App\Models\User;
public function profileDetails()
{
return $this->hasOnlyOne(Profile::class, 'user_id');
}
public function posts()
{
return $this->hasManyMore(Post::class, 'user_id');
}
public function author()
{
return $this->belongsToOnly(User::class, 'user_id');
}
```
### âŊ Create Routes
> At routes/route.php
```php
use App\Controllers\HomeController;
$router->get('/', 'HomeController@index');
```
> Define Routes with Prefixes
```php
$router->group(['prefix' => '/api'], function ($router) {
$router->get('/users', 'UserController@index');
$router->post('/login', 'AuthController@login');
});
$router->group(['prefix' => '/admin'], function ($router) {
$router->get('/dashboard', 'AdminController@dashboard');
$router->post('/settings', 'AdminController@saveSettings');
});
```
This will shown as
```text
/api/users
/api/login
/admin/dashboard
/admin/settings
```
### ð Session Manage
```php
use Core\Facades\Session;
//Set a Key
Session::set($key, $value);
// Get a Key Value
Session::get($key);
//Remove Key
Session::forget($key);
//Check session has a particular key
Session::has($key);
//Clear all Session
Session::flush();
```
### ðĨïļ PHP Curl Operation
```php
use Core\Http\HttpRemote;
(array) $headers;
(array) $data;
$http = new HttpRemote();
//Fetch a remote URL
$http->get($url, $headers);
// Post data to Remote URL
$http->post($url, $data, $headers);
// Update to Remote URL
$http->put($url, $data, $headers);
//Delete request
$http->delete($url, $data, $headers);
```
### ðĪš Global Middlewares
> `App/Middleware/RateLimitMiddleware`
```php
// Maximum requests allowed per time window
protected int $maxRequests = 10;
// Time window duration in seconds (e.g., 60 seconds = 1 minute)
protected int $timeWindow = 60;
```
> `App/Middleware/AuthMiddleware`
```php
public function handle($request, Closure $next)
{
// Add your logic here
return $next($request);
}
```
### ðïļ Json Resource Class
> Create a Custom Json Resource file Ex: `UserResource` under `App\Resources`
```php
namespace App\Resources;
use App\Resources\JsonResource;
class UserResource extends JsonResource
{
public function toArray(): array
{
return [
'user_id' => $this->resource['id'],
'full_name' => $this->resource['name'],
'email' => $this->resource['email'],
// Add more formatted fields here
];
}
}
// Use in Controller
$userResource = new UserResource($user);
$userResource->send();
```
### ðïļ Maintain Migration file
> Create a `users` table
```sh
$ php free make:migration create_users_table
```
> Migrate the db
```sh
$ php free migrate
```
> Drop a table
```sh
$ php free make:migration drop_orders_table
```
### Language manage
> Add language files at `lang` directory in array format, and then set the desired lang code at `config/app.php`
```php
lang('lang_key_name');
```
### ð§ Mailing system
```php
use Core\Mail\Mail;
$mailer = new Mail();
$mailer->to('recipient@example.com', 'John Doe')
->subject('Welcome to FreeFrame!')
->body('
Hello from FreeFrame
This is your welcome email.
')
->send();
```
### ðŪ IMAP (Incoming Mail Access Protocol) Feature
[Docuemntation:](https://github.com/Webklex/php-imap)
> Package used
```sh
$ composer require webklex/php-imap
```
Fill the `.env`
```env
IMAP_HOST=imap.gmail.com
IMAP_PORT=993
IMAP_ENCRYPTION=ssl
IMAP_VALIDATE_CERT=true
IMAP_USERNAME=your_email@gmail.com
IMAP_PASSWORD=your_password
```
Usage
```php
use Core\Mail\ImapClient;
$client = new ImapClient();
$mailbox = $client->getFolders();
$mails = $client->getInboxMessages();
$spambox = $client->getSpamMessages();
```
### ð° Payments supported
1. [Stripe](https://docs.stripe.com/api)
2. [Paypal](https://developer.paypal.com/api/rest/)
3. [Razorpay](https://razorpay.com/docs/api/)
4. [Square payment](https://developer.squareup.com/docs)
- Use
```php
use Payments\PaymentManager;
use Payments\Gateways\StripeGateway;
use Payments\Gateways\PaypalGateway;
use Payments\Gateways\RazorpayGateway;
use Payments\Gateways\SquareGateway;
```
- Define Payment gateway name at `.env`
```env
DEFAULT_PAYMENT_GATEWAY=stripe #razorpay #paypal #square
```
- Fill the details according to Payment Gateway
```env
# Stripe
STRIPE_KEY=''
STRIPE_SECRET=''
# Razorpay
RAZORPAY_KEY=''
RAZORPAY_SECRET=''
# PayPal
PAYPAL_CLIENT_ID=''
PAYPAL_SECRET=''
# Square
SQUARE_ACCESS_TOKEN=''
SQUARE_ENV='sandbox'
```
ð Queue Worker & Queue Job
```sh
$ php free make:job JobClassName
```
- Run Queue Job
```sh
$ php free queue:work
```
- Base Queue class
```php
\core\Jobs\BaseJob.php
```
### AWS Services supported
- SQS (Simple Queue Service)
- `\core\AWS\SQSService.php`
```php
use Core\AWS\SQSService;
$awsService = new SQSService();
$awsService->sendMessage($message);
```
- SES (Simple Email Service)
- `\core\AWS\SESService.php`
```php
use Core\AWS\SESService;
$awsService = new SESService();
$awsService->sendEmail($to, $subject, $htmlBody);
```
- S3 (Simple Storage Service)
- `\core\AWS\S3Service.php`
```php
use Core\AWS\S3Service;
$awsService = new S3Service();
$awsService->upload($key, $body, $contentType);
$awsService->fetch($key, $type); //$type = 'application/octet-stream'
```
- SNS (Simple notification system)
- `\core\AWS\SNSService.php`
```php
use Core\AWS\SNSService;
$awsService = new SNSService();
$awsService->publish($message);
$awsService->event($eventName, $data);
```
- EFS (Elastic File System)
- `\core\AWS\EFSService.php`
```php
use Core\AWS\EFSService;
$awsService = new EFSService();
$awsService->createFileSystem($creationToken);
$awsService->describeFileSystems($fileSystemId);
$awsService->deleteFileSystem($fileSystemId);
```
> Fill the details at `.env`
```env
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_DEFAULT_REGION=ap-south-1
AWS_S3_BUCKET=your-bucket-name
AWS_SQS_QUEUE_URL=https://sqs.ap-south-1.amazonaws.com/xxxx/your-queue
AWS_SNS_TOPIC_ARN=arn:aws:sns:ap-south-1:xxxx:your-topic
AWS_SES_EMAIL=verified@yourdomain.com
```
### ð Credit
Built with âĪïļ by **[Sagnik Dey](https://github.com/sagnikrivud)**
I'm a self-taught programmer and I'm open to any kind of feedback/suggestions. This framework is a hobby project and I'm doing it in my free time. If you find any bug or something that you think should be improved please open an issue or make a pull request.
I'm also a big fan of the Laravel framework, and I've been inspired by it, so if you see something that looks like Laravel, is because I like how they do things. But, I'm not trying to copy them, I'm just trying to do something similar but with my own style.
ðŧ Tech Stack
                     
           