Mentra Technical Documentation

Overview

The Mentra is a comprehensive platform designed to streamline therapy sessions between therapists and clients. Built on Laravel 10.10, this application leverages the power of PHP 8.1 to provide a robust and scalable solution for managing therapy sessions, user profiles, and administrative tasks. The admin side, developed with Laravel's Blade templating engine, offers an intuitive interface for easy configuration and management.

Project Brief

The primary goal of the Mentra is to create a user-friendly and efficient system that facilitates therapy sessions. The application employs an AI-powered, API-based architecture to ensure seamless communication between therapists and clients, allowing for real-time interaction and data exchange.

Key Features

  • AI-powered, API-based Communication: The application leverages AI to interact with clients, gathering wellness information before sessions. APIs are used to establish communication between therapists and clients, ensuring a responsive and dynamic user experience.

  • Blade Templating Engine: The admin side utilizes Laravel's Blade templating engine to create a straightforward and customizable interface for administrators.

  • MySQL Database: A MySQL database stores essential data such as user profiles, session logs, and administrative information, ensuring data integrity and reliability.

  • Redis for Queues: Redis is employed for queue management, enhancing performance and handling asynchronous tasks efficiently, especially in scenarios like session scheduling and notifications.

Project Architecture

Laravel Structure

The Mentra is divided into two modules:

  1. API Module:
  2. Entry Point: The entry point for the API code is located at app/Http/Controllers/Api/V1.
  3. Endpoints/Routes: API endpoints/routes are defined in routes/api_v1.php.
  4. Versioning: The API is versioned, and the current version is v1.

  5. Admin Module:

  6. Entry Point: The entry point for the API code is located at app/Http/Controllers/Admin.
  7. Routes: Admin routes are defined in routes/admin.php.

Controller - Service Pattern

Mentra adopts a Controller - Service pattern to organize and separate concerns within the application. In this pattern:

  • Controller: Primarily responsible for handling HTTP requests, validating input, and responding with appropriate HTTP responses. The controller delegates the business logic to service classes.

  • Service: Contains the business logic of the application. It encapsulates the processing and handling of data, ensuring a clean and modular structure. Controllers call services to perform specific tasks.

This separation of concerns enhances maintainability, testability, and scalability of the application.

Route Organization

The routes/endpoints are mostly grouped based on the features they relate to. The major groups are:

  • User: User-related routes and controllers are grouped together for easy management and maintenance.

  • Therapist: Routes and controllers responsible for managing therapy sessions are organized under a dedicated section.

  • Authentication: Authentication and authorization routes are grouped for clarity and easy reference.

  • Admin: Admin-related routes, tightly guarded with middlewares.

Example Route Grouping for Therapists

Route::prefix("therapist")->as("therapist.")->middleware("therapist_auth")->group(function () {
    Route::post("/preferences", [TherapistController::class,  "preferences"])->name("preferences");
    Route::post("/documents", [TherapistController::class,  "documents"])->name("documents");
    Route::post("/request-approval", [TherapistController::class,  "requestApproval"])->name("request_approval");
});

In this example, all routes under the "therapist" prefix are specifically related to therapist-related functionalities. The prefix, middleware, and route names are configured to reflect this organization, providing clarity and making it easier for developers to understand and maintain the codebase.

Coding Standards

To maintain a clean and efficient codebase, adhere to the following coding standards:

  1. File Length:
  2. All custom files (controllers, services, etc.) should be no more than 200 lines to aid readability.

  3. Method/Function Length:

  4. Avoid long methods/functions. Break down complex logic into smaller, more manageable functions.

  5. Database Transactions:

  6. Use database transactions to ensure the atomicity of database records, especially when multiple database operations need to be executed together.

  7. Feature Tests:

  8. Writing feature tests for each endpoint is compulsory to ensure the stability of the API endpoints. Test thoroughly to validate the functionality of the application.

  9. File Naming and PSR Standard:

  10. File names must be relative to the function of their content and adhere to the PSR standard for autoload efficiency.

  11. Code Comments:

  12. Comment code as much as possible, especially in complex or critical sections, to enhance code readability and understanding.

API Architecture

Authentication

We use Laravel Sanctum, a lightweight authentication package for SPA applications and APIs. Released in 2020, it became available out of the box since Laravel 8. Unlike JWT self-contained tokens, Sanctum uses a reference token.

API Documentation

All API endpoints are documented using Postman and can be accessed via Postman Documentation.

Rate Limits

We have rate limits in place to ensure the stability of the API. Laravel uses a fixed decay rate limiter. With default settings of throttle:60,1, a client can make 60 requests with 1 minute of decay before hitting a 1 minute forced decay timeout.

REST API and JSON Responses

We follow REST API principles, returning JSON responses with standard HTTP codes to ensure consistency and compatibility.

Summary of ReadMe Documentation

For detailed information on setting up, configuring, and running the Mentra , please refer to the Readme file. Here's a brief summary:

System Requirements:
  • Compatible with Linux, macOS, or Windows.
  • Requires Apache or Nginx as the web server.
  • PHP 8.1 or later is mandatory.
  • Composer for package management.
  • MySQL database setup.
  • Redis for handling queues.
PHP Requirements:
  • Ensure necessary PHP extensions are installed for optimal performance and functionality.
Getting Started:
  • Clone the repository and install dependencies using Composer.
  • Configure the environment by copying and updating the .env file.
  • Generate the application key.
  • Run database migrations and seeders.
  • Start the queue worker for Redis.
  • Run tests using php artisan test.
  • Launch the application with php artisan serve.
Project Architecture:
  • The application is divided into API and Admin modules.
  • API entry point: app/Http/Controllers/Api/V1.
  • API routes: routes/api_v1.php (Version: v1).
  • Admin routes: routes/admin.php.
  • Controller - Service pattern for clean separation of concerns.
Coding Standards:
  • Follow file length and method/function length guidelines.
  • Use database transactions for atomicity.
  • Write feature tests for each endpoint.
  • Adhere to PSR standards for file naming.
  • Comment code for enhanced readability.
API Architecture:
  • Authentication with Laravel Sanctum.
  • API endpoints documented with Postman: Postman Documentation.
  • Rate limits in place for API stability.
  • REST API principles followed with JSON responses.
Additional Information:
  • Configure your web server for production deployments.
  • Explore Laravel documentation for more in-depth understanding.
  • Utilize Laravel Artisan commands for various tasks.

Feel free to explore the Readme file for a comprehensive guide on setting up and running the Mentra. For any inquiries or issues, please don't hesitate to reach out. Happy coding!