How miguellfc/american_royalty_api works
Main components
• API Server: Represented by server.js, which is the entry point.
• Controllers: These handle the business logic (files in the controllers folder: auth-controller.js, request-controller.js, etc.).
• Routes: These files (in the routes folder) map the HTTP endpoints to their corresponding controllers.
• Middleware: Contains functions (like auth-mdw.js) to process requests (authentication, authorization, etc.) before reaching controllers.
• Models: These are the data abstractions representing entities such as Request, Role, Service, TypeService, and User.
• Database: The API connects to a PostgreSQL database (indicated by pg_connection.js and db-conf.json).
• Utilities and Configuration: Files such as utils.js, .env, and package.json which provide configuration, environmental variables, and helper functions.
Interactions and relationships
• Incoming HTTP requests hit the API server via defined routes.
• Routes layer directs requests to the appropriate controllers.
• Controllers use middleware (for authentication/authorization) to process the request.
• The controllers interact with the models to read or write data.
• Models communicate with the PostgreSQL database for data persistence.
• Any configuration data (like credentials in .env, db configurations in db-conf.json) should be clearly noted as part of the setup.
Architectural patterns and design principles
• MVC-like separation: Controllers for business logic, routes for request handling, models for data.
• Layered architecture: Each folder (routes, controllers, middleware, models) represents a distinct layer of the application.
• Modular organization: Each controller and route addresses a specific resource (auth, request, role, service, typeservice, user), making it easier to manage and extend functionality.
Relevant technologies and frameworks
• Node.js and Express framework for setting up server and routing.
• PostgreSQL database (given the presence of pg_connection.js and related configuration).
• Environment configuration through .env for secure settings.
• Possibly JSON for data interchange and REST principles for API design.