# tuthth/odtutor_be architecture

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

- Interactive diagram: https://gitdiagram.com/tuthth/odtutor_be
- Repository: https://github.com/tuthth/odtutor_be

## Overview

##### Project Type and Purpose
- This is clearly a backend application for an online tutoring system. Its primary purpose is to manage tutor and student accounts, handle bookings and scheduling, process payments (via VNPay), send notifications (via Firebase and mail), and integrate with external services like Google Calendar.
- The project is built as an ASP.NET Web API, organized into API controllers, a service layer, data models (using Entity Framework with migrations), and configuration/settings for external integrations.

##### File Structure
- The API folder contains the core presentation layer:
– API.csproj, Program.cs, and numerous controllers (such as AccountController, BookingController, TutorRegisterController, etc.) that handle HTTP requests.
- The Models directory holds all the domain entities, enumerables, mappings, migrations, and helper classes, which represent the data layer and database structure.
- The Services folder is organized into Interfaces and Implementations. This is the Business Logic Layer where domain-specific operations (e.g., booking, notifications, tutoring management) are performed.
- The Settings directory contains configurations for external services like Google Calendar, JWT for authentication, Mail settings, subscription settings, and VNPay for payment processing.
- Additional artifacts such as Dockerfiles, CI/CD configs (GitHub and GitLab), and a SQLScript folder indicate deployment and database provisioning tools.

##### Main Components
- API/Presentation Layer:
– API Controllers (Account, Admin, Booking, etc.) that expose endpoints.
- Service Layer:
– A collection of domain services (AccountService, BookingService, CourseService, NotificationService, etc.) that handle the core business logic.
- Data Layer:
– Models/Entities representing the database structure along with migration scripts that evolve the schema.
- External Integrations:
– Payment gateway via VNPay (settings and VNPayExample)
– Cloud messaging and realtime updates (FirebaseMessagingService, FirebaseRealtimeDatabaseService)
– Google Calendar integration (GoogleCalendarService)
– Email sending (MailService)
- Configuration/Settings:
– Settings for JWT, Mail, Subscription, and other integration points.
- Infrastructure/Deployment:
– Docker configuration files and CI/CD pipelines indicating containerization and automated deployment.

##### Relationships and Interactions
- The Service Layer contains logic that interacts with the Data Layer:
– Services use repositories or direct DbContext (represented by the Models, especially in the Entities folder) to read/write data.
- Services also integrate with external providers:
– For scheduling, the GoogleCalendarService might be called.
– For payments, VNPay functions are executed.
– For sending notifications, Firebase/Mail services are used.
– Data flow from the client → API Controllers → Services → Models/Database.
– Outbound calls from Services to external systems (e.g., Firebase, Google Calendar, VNPay).

##### Architectural Patterns and Design Principles
- Layered Architecture: Clear separation between presentation (API controllers), business logic (services), and data access (models).
- Dependency Inversion: Interfaces in the Services/Interfaces directory indicate that implementations can be swapped out or mocked.
- Micro-modularity: With numerous dedicated controllers and services, the system appears modular, which eases maintenance and scalability.
- Containerization: Dockerfile at both the API folder and project root signal that the deployment is containerized.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client("External Client"):::client

    %% API Layer
    subgraph "API Layer"
        AC("AccountController"):::apiLayer
        BC("BookingController"):::apiLayer
        TR("TutorRegisterController"):::apiLayer
    end

    %% Business Logic (Service Layer)
    subgraph "Business Logic (Service Layer)"
        AS("AccountService"):::serviceLayer
        BS("BookingService"):::serviceLayer
        NS("NotificationService"):::serviceLayer
        GS("GoogleCalendarService"):::serviceLayer
        FMS("FirebaseMessagingService"):::serviceLayer
        FRDS("FirebaseRealtimeDatabaseService"):::serviceLayer
        MS("MailService"):::serviceLayer
        VNP("VNPayService"):::serviceLayer
    end

    %% Data Layer
    subgraph "Data Layer"
        DM("Data Models (Entities)"):::dataLayer
        MIG("Database Migrations"):::dataLayer
    end

    %% External Integrations
    subgraph "External Integrations"
        VP("VNPay Payment"):::integration
        GC("Google Calendar"):::integration
        FN("Firebase Notifications"):::integration
        EM("Email Provider"):::integration
    end

    %% Configuration/Settings
    subgraph "Configuration & Settings"
        CONF("App Configurations & Settings"):::configLayer
    end

    %% Deployment & Infrastructure
    subgraph "Deployment & Infrastructure"
        DEP("Docker/CI/CD/SQL Scripts"):::deployment
    end

    %% Flow Connections
    Client -->|"HTTP Request"| AC
    Client -->|"HTTP Request"| BC
    Client -->|"HTTP Request"| TR

    AC -->|"calls"| AS
    BC -->|"calls"| BS
    TR -->|"calls"| AS

    AS -->|"data access"| DM
    BS -->|"data access"| DM
    NS -->|"data access"| DM

    DM -->|"schema changes"| MIG

    %% Service Layer to External Integrations
    BS -->|"triggers"| VP
    GS -->|"integrates"| GC
    NS -->|"sends"| FN
    NS -->|"sends"| EM

    %% Configuration influence on layers
    CONF --- AC
    CONF --- AS
    CONF --- BS
    CONF --- NS
    CONF --- GS
    CONF --- FMS
    CONF --- FRDS
    CONF --- MS
    CONF --- VNP

    %% Deployment connection to API layer
    DEP --- AC
    DEP --- AS
    DEP --- DM

    %% Click Events for API Layer
    click AC "https://github.com/tuthth/odtutor_be/blob/master/API/Controllers/AccountController.cs"
    click BC "https://github.com/tuthth/odtutor_be/blob/master/API/Controllers/BookingController.cs"
    click TR "https://github.com/tuthth/odtutor_be/blob/master/API/Controllers/TutorRegisterController.cs"

    %% Click Events for Service Layer
    click AS "https://github.com/tuthth/odtutor_be/blob/master/Services/Implementations/AccountService.cs"
    click BS "https://github.com/tuthth/odtutor_be/blob/master/Services/Implementations/BookingService.cs"
    click NS "https://github.com/tuthth/odtutor_be/blob/master/Services/Implementations/NotificationService.cs"
    click GS "https://github.com/tuthth/odtutor_be/blob/master/Services/Implementations/GoogleCalendarService.cs"
    click FMS "https://github.com/tuthth/odtutor_be/blob/master/Services/Implementations/FirebaseMessagingService.cs"
    click FRDS "https://github.com/tuthth/odtutor_be/blob/master/Services/Implementations/FirebaseRealtimeDatabaseService.cs"
    click MS "https://github.com/tuthth/odtutor_be/blob/master/Services/Implementations/MailService.cs"
    click VNP "https://github.com/tuthth/odtutor_be/blob/master/Services/Implementations/VNPayService.cs"

    %% Click Events for Data Layer
    click DM "https://github.com/tuthth/odtutor_be/tree/master/Models/Entities"
    click MIG "https://github.com/tuthth/odtutor_be/tree/master/Models/Migrations"

    %% Click Event for External Integrations
    click VP "https://github.com/tuthth/odtutor_be/tree/master/Settings/VNPay"
    click GC "https://github.com/tuthth/odtutor_be/tree/master/Settings/Google/Calendar"
    click FN "https://github.com/tuthth/odtutor_be/blob/master/Services/Implementations/FirebaseMessagingService.cs"
    click EM "https://github.com/tuthth/odtutor_be/tree/master/Settings/Mail"

    %% Click Event for Configuration/Settings
    click CONF "https://github.com/tuthth/odtutor_be/tree/master/API/Configurations"

    %% Click Event for Deployment & Infrastructure
    click DEP "https://github.com/tuthth/odtutor_be/tree/master/API/Dockerfile"

    %% Styles
    classDef client fill:#FFFAE6,stroke:#B8860B,stroke-width:2px
    classDef apiLayer fill:#E3F2FD,stroke:#1E88E5,stroke-width:2px
    classDef serviceLayer fill:#D1E7DD,stroke:#0F5132,stroke-width:2px
    classDef dataLayer fill:#FCE4EC,stroke:#C2185B,stroke-width:2px
    classDef integration fill:#FFF3E0,stroke:#FB8C00,stroke-width:2px
    classDef configLayer fill:#E2E3E5,stroke:#6C757D,stroke-width:2px
    classDef deployment fill:#D1D1E0,stroke:#5A5A8C,stroke-width:2px
```
