Chat plugin help


I have created a chat service with PHP and AJAX, and I want to make it as elgg plugin,I have 4 or 5 scripts in relation with each other,  but I don't know how make relation with them in elgg, Could you help me please to create a plugin?