PHPackages                             iam-lab/phalcon-stub - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. iam-lab/phalcon-stub

Active[Framework](/categories/framework)

iam-lab/phalcon-stub
====================

00PHPCI failing

Pushed 3w agoCompare

[ Source](https://github.com/TheSkyNet/iam_stub)[ Packagist](https://packagist.org/packages/iam-lab/phalcon-stub)[ RSS](/packages/iam-lab-phalcon-stub/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersionsUsed By (0)

Phalcon Project Stub
====================

[](#phalcon-project-stub)

A clean, minimal Phalcon PHP framework stub project designed to serve as a foundation for generating new Phalcon and Mithril.js projects. This stub includes essential components for user authentication, site settings management, and file handling.

Purpose
-------

[](#purpose)

This project serves as a template/stub for creating new Phalcon-based applications. It provides:

- **Clean Foundation**: Minimal, well-structured codebase without application-specific logic
- **Essential Components**: Core functionality that most web applications need
- **Easy Customization**: Ready to be extended for specific project requirements
- **Best Practices**: Follows Phalcon framework conventions and PHP best practices

Included Components
-------------------

[](#included-components)

### 🔐 User Authentication System

[](#-user-authentication-system)

- **User Model** (`IamLab\Model\User`): Complete user management with email/password authentication
- **Auth Service** (`IamLab\Service\Auth`): Authentication, login, logout, and session management
- **Auth API** (`IamLab\Service\Auth\AuthService`): RESTful authentication endpoints

### ⚙️ Site Settings Management

[](#️-site-settings-management)

- **SiteSetting Model** (`IamLab\Model\SiteSetting`): Flexible key-value configuration system
- **Settings Service** (`IamLab\Service\SettingsService`): Comprehensive settings management with support for:
    - Meta tags and SEO settings
    - Social media integration (Open Graph, Twitter)
    - Theme configuration
    - Analytics configuration
    - Maintenance mode
    - Structured data for schema.org

### 📁 File Upload System (FilePond)

[](#-file-upload-system-filepond)

- **Filepond Model** (`IamLab\Model\Filepond`): File metadata and temporary storage management
- **Filepond Services**: Complete file upload handling with FilePond integration
    - `FilepondApi.php`: API endpoints for file operations
    - `FilepondFile.php`: File handling utilities
    - `FilepondService.php`: Core file processing logic

### ⚡ Real-time Communication &amp; SSE

[](#-real-time-communication--sse)

- **Pusher Service** (`IamLab\Core\Pusher\PusherService`): WebSocket real-time communication
- **Pusher API** (`IamLab\Service\PusherApi`): Backend API for Pusher integration
- **Frontend Client** (`assets/js/components/PusherClient.js`): JavaScript client for real-time features
- **Server-Sent Events (SSE)**: Efficient one-way streaming from server to client
    - `IamLab\Service\SseApi`: API endpoints for SSE streams
    - `IamLab\Core\SSE`: Core SSE implementation
- **Test Pages**: Interactive testing interfaces at `/demo`

### 🔄 Job Queue &amp; Worker System

[](#-job-queue--worker-system)

- **Job Model** (`IamLab\Model\Job`): Database-backed job queue with status tracking
- **JobQueue Service** (`IamLab\Service\JobQueue`): Job creation, scheduling, and management
- **Jobs API** (`IamLab\Service\JobsApi`): RESTful API for job management
- **Worker Command** (`IamLab\Core\Command\WorkerCommand`): CLI worker for processing jobs
- **Example Jobs**: SendEmailJob, ProcessDataJob, CleanupJob for demonstration

### 📧 Email System

[](#-email-system)

- **Email Service** (`IamLab\Core\Email\EmailService`): Configurable email service
- **Multiple Providers**: MailHog (development) and Resend (production) support
- **Email Helper** (`email()` function): Simple email sending utility
- **Password Reset**: Complete forgot password workflow with email tokens

### 🎓 LMS Integration System

[](#-lms-integration-system)

- **LMS Service** (`IamLab\Service\LMS\LMSService`): Core service for LMS and AI integrations
- **Multi-Provider Support**: Factory pattern for Ollama, Google Gemini, and Tencent EDU
- **Registry &amp; Health**: Integrated health checks and fallback mechanisms
- **Setup Commands**:
    - Enable Ollama: `./phalcons command ollama enable`
    - Disable Ollama: `./phalcons command ollama disable`
    - Check Status: `./phalcons command ollama status`
    - See **[LMS Integration Setup](_docs/lms-integration-setup.md)** for more details.

### 💰 Payment &amp; Subscription System

[](#-payment--subscription-system)

- **Payment Service** (`IamLab\Service\Payment\PaymentService`): Unified interface for transactions
- **Supported Providers**: Stripe, PayPal, and Square integrations
- **Subscription Management**: Complete lifecycle for recurring payments
- **Factory Pattern**: Easily extendable architecture for new providers
- See **[Payment Integrations Guide](_docs/PAYMENT_INTEGRATIONS.md)** for configuration details.

### 🏗️ Core Framework Components

[](#️-core-framework-components)

- **API Framework** (`IamLab\Core\API`): RESTful API foundation
- **Collections** (`IamLab\Core\Collection`): Data collection utilities
- **Enumerations** (`IamLab\Core\Enum`): Type-safe enumerations
- **Environment Handling** (`IamLab\Core\Env`): Configuration management
- **Helpers** (`IamLab\Core\Helpers`): Common utility functions

Technology Stack
----------------

[](#technology-stack)

- **Backend**:

    - PHP 8.0+
    - Phalcon Framework 5.x
    - PostgreSQL
    - RESTful API Architecture
- **Frontend Ready**:

    - Asset pipeline configured
    - SASS/SCSS support
    - Modern JavaScript build tools
    - FilePond integration ready

Quick Start
-----------

[](#quick-start)

### 🚀 Generating a New Project

[](#-generating-a-new-project)

The easiest way to start a new project from this stub is to use the `project:init` command. This will automatically rename the default `IamLab` namespace and project names throughout the codebase to your chosen project name.

1. **Clone or download this stub project**:

    ```
    git clone  your-new-project
    cd your-new-project
    ```
2. **Initialize your project**:

    ```
    # Make sure you have the environment running
    ./phalcons up -d

    # Run the initialization command
    ./phalcons project:init my-new-project MyNewProject
    ```

This command will:

- Rename the `IamLab` namespace to `MyNewProject` in all files.
- Update `composer.json` and `package.json`.
- Rename the `IamLab/` directory to `MyNewProject/`.
- Create a `.env` file from `.env.example`.

---

### Prerequisites

[](#prerequisites)

- Docker &amp; Docker Compose
- PHP 8.0+
- Composer
- Node.js &amp; NPM

### Installation

[](#installation)

1. **Clone or download this stub project**:

    ```
    git clone  your-new-project
    cd your-new-project
    ```
2. **Start Docker containers**:

    ```
    ./phalcons up -d
    ```
3. **Install dependencies**:

    ```
    ./phalcons composer install
    ./phalcons npm install
    ```
4. **Run database migrations**:

    ```
    ./phalcons migrate
    ```
5. **Seed the database with initial data**:

    ```
    ./phalcons migrate:seed --email="admin@example.com" --password="YourSecurePassword123!"
    ```
6. **Build frontend assets**:

    ```
    ./phalcons npm run dev
    ```

### Development

[](#development)

- **Start development server**: `./phalcons up`
- **Run migrations**: `./phalcons migrate`
- **Access application**: `http://localhost:8080`
- **Database**: PostgreSQL on `localhost:5432`

Project Structure
-----------------

[](#project-structure)

```
├── IamLab/                     # Main application directory
│   ├── Core/                   # Framework core components
│   │   ├── API/               # API framework
│   │   ├── Collection/        # Data collections
│   │   ├── Enum/             # Enumerations
│   │   ├── Env/              # Environment handling
│   │   └── Helpers/          # Utility functions
│   ├── Model/                 # Data models
│   │   ├── User.php          # User authentication model
│   │   ├── SiteSetting.php   # Site configuration model
│   │   └── Filepond.php      # File upload model
│   ├── Service/              # Business logic services
│   │   ├── Auth/             # Authentication services
│   │   ├── Auth.php          # Main auth service
│   │   ├── SettingsService.php # Settings management
│   │   └── Filepond/         # File upload services
│   ├── Migrations/           # Database migrations
│   ├── config/               # Configuration files
│   ├── views/                # View templates
│   └── app.php               # Application bootstrap
├── public/                   # Web root
├── assets/                   # Frontend assets
├── docker/                   # Docker configuration
├── bin/                      # CLI scripts
└── composer.json             # PHP dependencies

```

Customization Guide
-------------------

[](#customization-guide)

### Adding New Models

[](#adding-new-models)

1. Create model in `IamLab/Model/`
2. Add corresponding migration in `IamLab/Migrations/`
3. Create service in `IamLab/Service/` if needed

### Extending Authentication

[](#extending-authentication)

The authentication system is fully functional but can be extended:

- Add user roles and permissions
- Implement OAuth providers
- Add two-factor authentication
- Customize user profile fields

### Configuring Site Settings

[](#configuring-site-settings)

Add new settings by:

1. Creating entries in the `site_settings` table
2. Extending `SettingsService.php` to handle new setting types
3. Using settings in your views and controllers

### File Upload Customization

[](#file-upload-customization)

FilePond integration supports:

- Multiple file types
- File validation
- Temporary storage
- Permanent file management

Database Schema
---------------

[](#database-schema)

The stub includes migrations for:

- `users` - User authentication and profiles
- `site_settings` - Application configuration
- `filepond` - File upload metadata
- `password_reset_tokens` - Password reset functionality

API Endpoints
-------------

[](#api-endpoints)

### Authentication

[](#authentication)

- `POST /auth` - User login
- `POST /auth/register` - User registration
- `POST /auth/forgot-password` - Request password reset
- `POST /auth/logout` - User logout
- `GET /auth/user` - Get current user

### Real-time Communication

[](#real-time-communication)

- `GET /api/pusher/config` - Get Pusher configuration
- `POST /api/pusher/auth` - Authenticate private/presence channels
- `POST /api/pusher/trigger` - Trigger events (testing)
- `GET /api/pusher/channel-info` - Get channel information
- `GET /api/pusher/channels` - List active channels

### File Upload

[](#file-upload)

- `POST /filepond/upload` - Upload file
- `DELETE /filepond/{id}` - Delete file
- `GET /filepond/{id}` - Get file info

### Job Queue Management

[](#job-queue-management)

- `GET /api/jobs` - List jobs with pagination and filtering
- `POST /api/jobs` - Create a new job
- `GET /api/jobs/{id}` - Get job details
- `DELETE /api/jobs/{id}` - Cancel a job
- `POST /api/jobs/{id}/retry` - Retry a failed job
- `GET /api/jobs/stats` - Get job queue statistics
- `GET /api/jobs/types` - Get available job types
- `POST /api/jobs/cleanup` - Clean up old completed jobs
- `POST /api/jobs/bulk` - Bulk operations on jobs

🧪 Testing &amp; Demos
---------------------

[](#-testing--demos)

### 🚀 Demo Dashboard

[](#-demo-dashboard)

Visit the **[Demo Dashboard](/demo)** to test all core integrations in one place:

- **Real-time**: Test Pusher WebSockets and SSE streams
- **Payments**: Multi-provider demo (Stripe, PayPal, Square) and a dedicated **[PayPal v6 SDK Demo](/demo/paypal)**
- **LMS**: Monitor AI service status and capabilities
- **Jobs**: Trigger and monitor background job processing
- **Auth**: Test role-based access and profile management

### 📧 Email Testing

[](#-email-testing)

The project includes MailHog for email testing in development:

- Access MailHog dashboard at `http://localhost:8026` (check `.env` for `FORWARD_MAILHOG_DASHBOARD_PORT`)
- Test password reset emails and system notifications

### 🛠️ Setup &amp; Integration Guides

[](#️-setup--integration-guides)

For detailed setup instructions, refer to the following documentation:

- **[LMS Integration Setup](_docs/lms-integration-setup.md)**: Configuring AI and LMS providers
- **[Payment Integrations](_docs/PAYMENT_INTEGRATIONS.md)**: Setting up Stripe, PayPal, and Square
- **[JWT Authentication](_docs/JWT_AUTHENTICATION.md)**: Security and token configuration
- **[OAuth Setup](_docs/OAUTH_INTEGRATION.md)**: Integrating Google, GitHub, and Facebook login
- **[Role Guards](_docs/ROLE_GUARDS_DOCUMENTATION.md)**: Managing permissions and RBAC
- **[Route Groups](_docs/ROUTE_GROUPS_DOCUMENTATION.md)**: Understanding application routing
- **[Error Service](_docs/ERROR_SERVICE.md)**: Monitoring and centralized logging

### Job Queue &amp; Worker System Testing

[](#job-queue--worker-system-testing)

Test the worker system functionality:

- Create jobs via API endpoints
- Process jobs using the worker command
- Monitor job status and statistics

Using the Job Queue &amp; Worker System
---------------------------------------

[](#using-the-job-queue--worker-system)

The framework includes a comprehensive job queue and worker system for processing background tasks.

### Setup

[](#setup)

1. **Run the migration** to create the jobs table:

    ```
    ./phalcons migrate
    ```
2. **Start a worker** to process jobs:

    ```
    php bin/console worker:run
    ```

### Creating Jobs via API

[](#creating-jobs-via-api)

Create a new job by sending a POST request to `/api/jobs`:

```
{
  "type": "SendEmailJob",
  "payload": {
    "to": "user@example.com",
    "subject": "Hello",
    "message": "Hello from the job queue!"
  },
  "priority": 5,
  "max_attempts": 3
}
```

### Creating Custom Job Classes

[](#creating-custom-job-classes)

1. Create a new job class in `IamLab/Jobs/`:

```
