A well-organized project structure makes it easier to maintain and scale your FastRoute application. This guide explains the recommended directory layout and the purpose of each component.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/MonishAMPT/fastroute-code/llms.txt
Use this file to discover all available pages before exploring further.
Directory Structure
Here’s the recommended structure for a FastRoute application:Core Files
index.php - Main Entry Point
Theindex.php file is the main entry point of your application. It handles:
- Autoloading dependencies
- Request parsing
- Route dispatching
- Response handling
index.php
routes/ Directory
Theroutes/ directory contains your route definitions, organized by type:
- api.php - API endpoints that return JSON responses
- web.php - Web routes that return HTML views
- Apply different middleware or headers
- Manage API versioning
- Keep related routes together
Handler Classes
Handler classes (likev1/test.php) contain reusable logic for processing requests. This keeps your route definitions clean and promotes code reuse.
views/ Directory
Theviews/ directory stores your HTML templates and view files that are rendered for web routes.
Benefits of This Structure
Separation of Concerns
Routes, handlers, and views are separated into logical directories
Scalability
Easy to add new route files as your application grows
Maintainability
Clear organization makes code easier to find and update
Team Collaboration
Multiple developers can work on different route files simultaneously
Next Steps
API Routes
Learn how to define API routes
Web Routes
Learn how to define web routes
Route Handlers
Understand different handler types
Organizing Routes
Best practices for organizing routes