# khoasinno/homex-symfony architecture

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

- Interactive diagram: https://gitdiagram.com/khoasinno/homex-symfony
- Repository: https://github.com/khoasinno/homex-symfony

## Overview

This project is a Symfony-based online appointment booking system for a healthcare environment. It includes multiple user interfaces (for administrators, doctors, and patients) along with integrations for external services such as Google OAuth for login and Momo for payment processing. The project follows the typical MVC pattern enhanced by Symfony’s structure, using Doctrine for database interactions, Twig for templating, and a rich set of front-end assets (including CKEditor and theme assets for admin and customer interfaces).

##### Main Components
- Frontend Clients: Represent the three major interfaces:
- Admin Interface (located in public/admin with its own assets, HTML templates, and CSS)
- Customer/Patient Interface (in public/customer, with dedicated assets and templates)
- Public/General Interface (the main public index and home pages)
- Backend – Symfony Application:
- Core application kernel, routing (configured in config/routes* and services in config/services.yaml)
- Controllers organized under src/Controller (sub-folders for Admin, Doctor, Patient, and others such as Registration and Security)
- Business Logic & Services (under src/Service with components like MailService, MomoService, ScheduleService, and ImageUploader)
- Entities and Repositories (for Appointment, User, Specialty, ScheduleWork, etc. in src/Entity and src/Repository)
- DataFixtures and Migrations for database seeding and schema management
- External Integrations:
- Google OAuth (using the knpuniversity/oauth2-client-bundle and a custom GoogleAuthenticator in src/Security)
- Momo Payment Gateway (as seen in the MomoController and related service integration)
- Database:
- The Doctrine-managed database where all entities are persisted. This can be visualized as a central datastore interacting with the business logic layer.
- Assets & Static Files:
- JavaScript, CSS, and multimedia assets found in the assets and public directories (including CKEditor libraries and plugins).

##### Relationships and Data Flows
- User requests (from browsers or mobile devices) first hit the public folder and are routed into the Symfony kernel.
- The routing component dispatches requests to the appropriate controller based on URL (e.g., admin routes, patient routes, security routes).
- Controllers interact with services for business operations, such as scheduling appointments, sending mail notifications, or handling external API calls.
- The services layer processes logic and interacts with repositories to perform queries and persist data into the database.
- External services are invoked:
- For authentication, the Google OAuth process is handled via the GoogleAuthenticator and related client configuration.
- For financial transactions, the MomoService communicates with the Momo API, retrieving payment URLs or deeplink data.
- Responses are rendered using Twig templates and served back to the client.

##### Important Architectural Patterns and Design Principles
- MVC Pattern: Clearly distinguish between models (entities), views (Twig templates), and controllers (routing and business logic).
- Service-Oriented Architecture within Symfony: Business logic is delegated to individual services (e.g., MailService, ScheduleService, ImageUploader).
- Integration with External Systems: Use of OAuth2 and third-party payment gateways shows a modular approach for external dependencies.
- Layer separation: Frontend assets, backend logic, and configuration files are stored in distinct directories, ensuring maintainability and scalability.

##### Representing Technologies and Frameworks
- Symfony framework (routing, controllers, kernel, security)
- Doctrine ORM for database management
- Twig templating engine for views
- CKEditor for rich text editing integrated in the admin/customer interfaces
- External libraries such as knpuniversity/oauth2-client-bundle, league/oauth2-google, and Momo’s API integration.
- Composer for dependency management

- Clear labels for every component (e.g., “Admin Controller”, “DoctorController”, “Doctrine Repository”, “GoogleAuthenticator”, “MomoService”).
- How user requests traverse from the client (browser) to Symfony’s routing and into Controllers.
- How Controllers invoke Services, which in turn interact with the Database or external APIs.
- Annotations for configuration files (e.g., config/routes.yaml, config/services.yaml) where key integrations like the OAuth2 configurations are set.

- Entry point into the Symfony backend (public/index.php → Kernel).
- Expand the backend component to detail the controllers (grouped by function), the services layer, and data repositories.
- External integrations:
- The flow of Google OAuth login via GoogleAuthenticator and related configuration.
- The communication with the Momo Payment Gateway from the MomoService / MomoController.
- Finally, display the database and emphasize the communication to/from Doctrine ORM.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "User Interfaces"
        A["Admin Interface"]:::frontend
        C["Customer/Patient Interface"]:::frontend
        P["Public Interface"]:::frontend
    end

    subgraph "Symfony Backend"
        SKRT["Symfony Kernel & Routing"]:::backend
        Controllers["Controllers (Admin,Doctor,Patient,Momo)"]:::backend
        Services["Business Logic & Services"]:::backend
        Entities["Entities & Repositories"]:::backend
    end

    subgraph "External Integrations"
        GoogleOAuth["Google OAuth"]:::external
        MomoPayment["Momo Payment"]:::external
    end

    Database["Database (Doctrine ORM)"]:::database
    Assets["Assets & Static Files"]:::asset

    %% User requests flow
    A -->|"request"| SKRT
    C -->|"request"| SKRT
    P -->|"request"| SKRT

    SKRT -->|"dispatch"| Controllers
    Controllers -->|"invoke"| Services

    Services -->|"query/persist"| Entities
    Entities -->|"read/write"| Database

    Services -->|"auth_call"| GoogleOAuth
    Services -->|"payment_call"| MomoPayment

    Assets -->|"serve"| A
    Assets -->|"serve"| C
    Assets -->|"serve"| P

    %% Click Events
    click A "https://github.com/khoasinno/homex-symfony/tree/main/public/admin"
    click C "https://github.com/khoasinno/homex-symfony/tree/main/public/customer"
    click P "https://github.com/khoasinno/homex-symfony/blob/main/public/index.php"
    click SKRT "https://github.com/khoasinno/homex-symfony/blob/main/src/Kernel.php"
    click SKRT "https://github.com/khoasinno/homex-symfony/blob/main/config/routes.yaml"
    click Controllers "https://github.com/khoasinno/homex-symfony/tree/main/src/Controller"
    click Services "https://github.com/khoasinno/homex-symfony/tree/main/src/Service"
    click Entities "https://github.com/khoasinno/homex-symfony/tree/main/src/Entity"
    click Entities "https://github.com/khoasinno/homex-symfony/tree/main/src/Repository"
    click GoogleOAuth "https://github.com/khoasinno/homex-symfony/blob/main/src/Security/GoogleAuthenticator.php"
    click MomoPayment "https://github.com/khoasinno/homex-symfony/blob/main/src/Controller/MomoController.php"
    click MomoPayment "https://github.com/khoasinno/homex-symfony/blob/main/src/Service/MomoService.php"
    click Assets "https://github.com/khoasinno/homex-symfony/tree/main/assets"
    click Assets "https://github.com/khoasinno/homex-symfony/tree/main/public/ckeditor"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef external fill:#D5F5E3,stroke:#1E8449,stroke-width:2px;
    classDef database fill:#FADBD8,stroke:#922B21,stroke-width:2px;
    classDef asset fill:#FDEBD0,stroke:#7D6608,stroke-width:2px;
```
