How do I integrate custom PHP application with Drupal? I am a PHP programmer but I have never developed anything yet for drupal. I have used Drupal as a CMS before but I didn't do any custom code since everything I needed at before can be accomplished with existing modules.

Now, with my new project, I have an existing single-page app using a PHP RESTful API and AngularJS on the frontend. I want it to be integrated with a Drupal CMS.

I am aware of the following possible ways to do this:


Rewrite my existing code into a Drupal module - There is very little possibility that this app will be re-used. Furthermore, it is more likely that this app will be used stand-alone without Drupal. I also don't think I have the time to learn how to write a Drupal module.
Keep the backend API as it is now and write the frontend as a Drupal page. - This will put my frontend code inside the Drupal database and NOT in the filesytem anymore so I can't version control the frontend code.


I am not happy with the above two choices and I believe that there is a better way to do achieve what I want.

Additional background of my custom app:

I created this app as a way for me to learn more about single-page applications. It is already currently functioning well as a standalone app. The app basically collects information from several users and collates all those information to be displayed on an HTML table. 

I am sure there is also a Drupal way of doing the things that my Angular app does (something like a custom node type with fields coming from the input of different users) but I would like to use my existing code if that makes it easier.
If your application can be displayed inside a Drupal page, writing a small custom module is the easiest clean solution. You don't need to rewrite your application, but only to provide some integration code. Your application should avoid output the complete HTML for the page, only its own content. It should also not initialize the PHP session as Drupal will take care of that. Otherwise it is as simple as:

/**
 * Implements hook_menu().
 */
function your_application_menu() {
  return array(
    'title' =&gt; 'Your Application',
    'page callback' =&gt; 'your_application_page',
    'access callback' =&gt; TRUE,
    'type' =&gt; MENU_CALLBACK,
  );
}

/**
 * Page callback: Displays Your Application on the page.
 *
 * @see your_application_menu()
 */
function your_application_page() {
   module_load_include('php', 'your application', 'your_application');
   $path = drupal_get_path('module', 'your application');
   drupal_add_js($path . '/js/angular.js');
   drupal_add_js($path . '/js/your_application.js');
   drupal_add_css($path . '/css/your_application.css');
   return your_application_output();
}


You may also be interested by the Angular JS module, which likely provide a much nicer way to embed Angular JS applications in Drupal.