# miguellfc/american_royalty_api architecture

> Architecture diagram of the GitHub repository miguellfc/american_royalty_api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/miguellfc/american_royalty_api
- Repository: https://github.com/miguellfc/american_royalty_api

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["AmericanRoyaltyFront (Client)"]:::client
    B["API Server (server.js)"]:::server
    C["Routes (routes/)"]:::routes
    D["Middleware (auth-mdw.js)"]:::middleware
    E["Controllers (controllers/)"]:::controller
    F["Models (models/)"]:::models
    G["Database (PostgreSQL)"]:::database
    H["Environment Config (.env)"]:::config
    I["Package & Utils (package.json, utils.js)"]:::config
    J1["DB Connection (pg_connection.js)"]:::config
    J2["DB Config (db-conf.json)"]:::config

    A -->|"HTTP_Request"| B
    B -->|"handles"| C
    C -->|"routes"| D
    D -->|"invokes"| E
    E -->|"operates on"| F
    F -->|"persists to"| G

    H -.->|"configures"| B
    I -.->|"supports"| B
    J1 -.->|"connects"| G
    J2 -.->|"configures"| G

    click B "https://github.com/miguellfc/american_royalty_api/blob/main/server.js"
    click C "https://github.com/miguellfc/american_royalty_api/tree/main/routes/"
    click D "https://github.com/miguellfc/american_royalty_api/blob/main/middleware/auth-mdw.js"
    click E "https://github.com/miguellfc/american_royalty_api/tree/main/controllers/"
    click F "https://github.com/miguellfc/american_royalty_api/tree/main/models/"
    click H "https://github.com/miguellfc/american_royalty_api/blob/main/.env"
    click I "https://github.com/miguellfc/american_royalty_api/blob/main/package.json"
    click J1 "https://github.com/miguellfc/american_royalty_api/blob/main/pg_connection.js"
    click J2 "https://github.com/miguellfc/american_royalty_api/blob/main/db-conf.json"

    classDef client fill:#B3E5FC,stroke:#0277BD,stroke-width:2px
    classDef server fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px
    classDef routes fill:#FFF9C4,stroke:#F57F17,stroke-width:2px
    classDef middleware fill:#FFE0B2,stroke:#E64A19,stroke-width:2px
    classDef controller fill:#D1C4E9,stroke:#5E35B1,stroke-width:2px
    classDef models fill:#BBDEFB,stroke:#1976D2,stroke-width:2px
    classDef database fill:#FFCDD2,stroke:#C62828,stroke-width:2px
    classDef config fill:#CFD8DC,stroke:#546E7A,stroke-width:2px
```
