2

I am developing REST API using Phalcon. The application will have multiple modules like Users, Company, Contacts and so on. Each of these modules have their own tables for storing data. Moreover each module have their own defination file which mentions what fields to show in API response. I am pretty new to Phalcon, i just started learning Phalcon, and I need help regarding how i should structure the application so that this code won't give me future problems, or if I'm missing something or if the code could be abstracted more then that would be great.

Directory Structure as planned:

app/
    MyAPI/
        MyAPIControler.php

library/
    controller.php //master controller where all controllers inherit from
    model.php //master model where all models inherit from
    utilities.php
    MyAPI/
        models/
            User.php 
            Contacts.php
            Company.php
            Myapi.php

/config
    config.php
    routes.php

index.php

I want all database related queries of each module to reside in their own models. API URL say for listing of records will be http://api.example.com/MyAPI/V2/contacts/list or /MyAPI/V2/users/list. Similarly API URL for creating records will be http://api.example.com/MyAPI/V2/contacts/add or /MyAPI/V2/users/list

Please advise how i should proceed

mary josh
  • 21
  • 4

1 Answers1

0

The project folder structure would be better if it's something like this,

app/
    config/
    controllers/
    forms/
    library/
    models/
    views/
cache/
public/
    css/
    img/
schemas/

The folder names are self explanatory. Since your trying to make a REST API, you can remove the public folder along with css and img in it. You can also set the default render to be json in the base controller and have the other controller's extend it.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
user1217974
  • 154
  • 3
  • 12