# tracks **Repository Path**: wfdaj/tracks ## Basic Information - **Project Name**: tracks - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-08-06 - **Last Updated**: 2025-09-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Tracks Framework A Ruby on Rails-like PHP framework that follows Rails principles and conventions. ## Architecture Diagram ![Tracks Framework Architecture](https://kroki.io/plantuml/svg/eNqlGl1z27jxXb8CtR_KxFHavmoymbN1ycU38cWV1ev0yQORkIQaIhgAlK1e89-7-CIBEJTl-sXyALuL_d7Fgj9JhYVqdwwtBS4fJPos8I48cvGALkW5pYqUqhVkMvlTRda0Jujy6m65uJwvEV5JBSiq27lbXi6v5wgIKlpOJg2QwxuCzuZckJ7sGTr_SjdbdcVagv6YIFQyLCW6bBpGS8DkNfrw4Y7WG0YUrz9-NDAITWkNhOuSzEJQuyV4q4iYoYX5tWslr9d0M0NYCHzwYFzdYrWdAYsCDrCrpN5TwesdqVW8MbU_9_dACtbbUhVvzNLFhqhrx03xZsjPhWhrvb7ntLI0KiobrMptYTh1TEUQjONqblguButGLBmtaxastHo5kNtuWDn1ViCQ3vrUC5vuWoUVD-Tg198hMCxumQLIHX0i-ugfkx-BZfXBAOhN-osgpA5savnyBjSyy8giNfgEaEYbNdR82QoBHN6VvCER_LQTpGgCQ75DwLwSnDHtBX6NN9oiMqPti4bL11JoX0vA-MOrSFQEQoS8joYgkreiBPfStngRyukYnZmLgcGBYczYChxqZv7DK0YiXKmdIJVxgHKcYYiHYqiXKM5wZcOs2BG15VV_1mu0q5PQnggTjEu-IBvyFEmSRODOuMQxBt6E0aBdaPuZi8QODYZMG3DTnRCH7s3vczRF804e6YP4X4Qx_miCtkv1NpzPLkstaY8zm11hSc5cgJ9HJ9ulPRZU2ydeZfgAuo6EP4eAr4ggIPiKc2bXXB6wx8bgW4IBPCarC08r57wCbdBaeboVFVDDlj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IkYBU4y-yjcMCMHFh9uan0NSBsV52HzPBuESZKfXaYYwGXAjlDNQOf5zQDmdDEGO-pR4yhddtWZkuGDRDZLTyY1VwT8okF8nXxR1H0Mpb8FAOwa0V3DzJXdg3wCXRxQw6FcoDXw_EhWSD-wEUiCsH2Da6iTEtlRQ2tdG-G6MqfrAg62RpoDx4fQpVRz0n1atPh0t1y3zCMMWbhrG10CQSD_SYmtmeZzD_hfn2Y-5tAM3TpBzCcPmpxm-h-Lr6CA4BsL2G6aDHcrrhTfafZyuUt352YV2eVxrd0KvqcV6OXb4gat29rkC-g3lW7PvwDD0KnpWwpeAV3kXzbqkoTihhM_I2TwAJEyrud4HduDwgZUlwR4xNoAZlFrhtQbWkcnumcyc5h7rTI6_XI71YxWSFkqseZ-gn_bHfsfnpzlkg==) ## Features - **MVC Architecture**: Clean separation of concerns with Models, Views, and Controllers - **ActiveRecord Pattern**: Elegant database interactions with an ORM that feels like Rails - **RESTful Routing**: Rails-style routing with resource-based conventions - **Database Migrations**: Version control for your database schema - **Scaffolding**: Quick generation of models, controllers, and views - **Interactive Console**: REPL environment for testing and debugging - **Convention over Configuration**: Sensible defaults that just work ## Requirements - PHP 8.0 or higher - Composer - SQLite, MySQL, or PostgreSQL ## Installation ```bash # Clone the repository git clone https://github.com/yourusername/tracks.git cd tracks # Install dependencies composer install # Copy environment file cp .env.example .env # Start the development server php tracks server ``` ## Quick Start ### Generate a Blog Application ```bash # Generate a Post scaffold with title and content php tracks generate:scaffold post title:string content:text # Run migrations to create the database tables php tracks db:migrate # Start the server php tracks server # Visit http://localhost:3000/posts ``` ## CLI Commands ### Server Commands ```bash # Start development server (default port 3000) php tracks server # Start on custom port php tracks server --port=8080 ``` ### Generator Commands ```bash # Generate a model php tracks generate:model user name:string email:string # Generate a controller php tracks generate:controller users # Generate a complete scaffold php tracks generate:scaffold product name:string price:decimal description:text ``` ### Database Commands ```bash # Run pending migrations php tracks db:migrate # Rollback last migration php tracks db:rollback # Rollback specific number of migrations php tracks db:rollback --steps=3 # Check migration status php tracks db:status ``` ### Other Commands ```bash # Start interactive console php tracks console # Display all routes php tracks routes ``` ## Project Structure ``` tracks/ ├── app/ │ ├── controllers/ # Application controllers │ ├── models/ # Application models │ └── views/ # View templates │ └── layouts/ # Layout templates ├── config/ │ ├── application.php # Application configuration │ ├── database.php # Database configuration │ └── routes.php # Route definitions ├── db/ │ ├── migrate/ # Database migrations │ └── seeds/ # Database seeds ├── lib/ │ └── tracks/ # Framework core ├── public/ # Web root │ ├── css/ # Stylesheets │ ├── js/ # JavaScript files │ └── images/ # Images ├── test/ # Test files ├── log/ # Application logs └── tmp/ # Temporary files ``` ## Routing Define routes in `config/routes.php`: ```php // Root route $router->root('HomeController#index'); // RESTful resources $router->resources('posts'); $router->resource('profile'); // Custom routes $router->get('/about', 'PagesController#about'); $router->post('/contact', 'ContactController#create'); // Nested routes $router->scope('/admin', function($router) { $router->resources('users'); $router->resources('posts'); }, ['module' => 'Admin']); ``` ## Models Models inherit from `Tracks\ActiveRecord\Base`: ```php ['presence' => true, 'length' => ['minimum' => 3]], 'content' => ['presence' => true], ]; protected static array $callbacks = [ 'beforeSave' => ['generateSlug'], ]; protected function generateSlug(): void { if (empty($this->slug) && !empty($this->title)) { $this->slug = strtolower(str_replace(' ', '-', $this->title)); } } } ``` ## Controllers Controllers inherit from `Tracks\ActionController\Base`: ```php authenticate(); } public function index(): void { $this->set('posts', Post::all()); } public function show(): void { $post = Post::find($this->param('id')); $this->set('post', $post); } public function create(): void { $post = new Post($this->requireParams('post', ['title', 'content'])); if ($post->save()) { $this->redirectTo('/posts/' . $post->id, ['notice' => 'Post created!']); } else { $this->set('post', $post); $this->render('new'); } } } ``` ## Views Views use PHP templates with helpers: ```php

title ?>

content)) ?>
id}/edit", ['class' => 'btn']) ?> 'post']) ?>
``` ## Migrations Create migrations to manage database schema: ```php createTable('posts', function($t) { $t->string('title'); $t->text('content'); $t->string('slug')->index(); $t->references('user'); $t->timestamps(); }); } public function down(): void { $this->dropTable('posts'); } } ``` ## ActiveRecord Usage ```php // Find records $post = Post::find(1); $post = Post::findBy(['slug' => 'hello-world']); $posts = Post::all(); $posts = Post::where(['published' => true])->orderBy('created_at', 'DESC')->limit(10)->get(); // Create records $post = Post::create(['title' => 'New Post', 'content' => 'Content here']); // Update records $post->title = 'Updated Title'; $post->save(); // Delete records $post->destroy(); Post::destroy(1); // Query builder $posts = Post::where(['status' => 'published']) ->orderBy('created_at', 'DESC') ->limit(10) ->get(); // Associations (coming soon) $user->posts(); $post->comments()->where(['approved' => true])->get(); ``` ## Configuration Configure the application in `config/application.php`: ```php return [ 'app_name' => 'My Tracks App', 'timezone' => 'America/New_York', 'session' => [ 'lifetime' => 120, 'cookie' => 'tracks_session', ], ]; ``` Configure the database in `config/database.php`: ```php return [ 'development' => [ 'adapter' => 'mysql', 'host' => 'localhost', 'database' => 'tracks_dev', 'username' => 'root', 'password' => '', ], ]; ``` ## Testing Run tests with PHPUnit: ```bash # Run all tests vendor/bin/phpunit # Run specific test file vendor/bin/phpunit tests/PostTest.php ``` ## Contributing Contributions are welcome! Please feel free to submit a Pull Request. ## License This project is open-sourced software licensed under the MIT license.