# mdung0807/busticketbookingapi architecture

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

- Interactive diagram: https://gitdiagram.com/mdung0807/busticketbookingapi
- Repository: https://github.com/mdung0807/busticketbookingapi

## Overview

##### Project Type and Purpose
- This is a multi-module RESTful API project built using .NET (C#). It supports various business domains of a bus booking system such as authentication, address management, billing, bus and bus station management, company and customer management, payment via PayPal, and more.
- The README indicates that it’s designed to work with SQL Server (migrations, update-database) and has a step-by-step build process. It also references an external dataset (Vietnamese provinces), so integration with external data sources is part of its functionality.

##### Analyzing the File Structure
- The solution is spread over multiple projects, each handling a specific domain:
- Address management (BusBookTicket.AddressManagement)
- Application and shared services (BusBookTicket.Application, e.g., CloudImage, MailKet, Notification, OTP, PayPalPayment)
- Authentication (BusBookTicket.Auth)
- Billing (BusBookTicket.BillManage)
- Bus Station management (BusBookTicket.BusStationManage)
- Bus details including buses, bus types, seats, etc. (BusBookTicket.Buses)
- Company, Customer, Discount, Price, Ranks, Reviews, and Routes management
- Ticketing (BusBookTicket.Ticket)
- A common/core project (BusBookTicket.Core) encapsulates cross-cutting concerns: data models (entities), repositories, specifications, migrations, utilities, and infrastructure (e.g., Dapper context, unit of work).
- Each module contains directories for Controllers (web API endpoints), DTOs (data transfer objects), Services (business logic), Specifications (for filtering and validation), Validators, and sometimes repositories. This clearly follows an architectural separation (API layer, business logic, data access).

##### Key Architectural Components to Capture
a. Main Components:
- API Gateway/Controllers: Each module (Auth, Address, Bill, Bus, etc.) includes one or more controllers that expose RESTful endpoints.
- Service Layer: Business logic is encapsulated in separate service classes within each module (e.g., AuthService, BusService, TicketService).
- Domain/Core Layer: BusBookTicket.Core holds centralized domain models, repository interfaces, unit-of-work implementation, entity configurations, and migrations. This serves as the backbone for data persistence and business definitions.
- External Services: Integration components such as Cloud Image processing, Mail services (MailKet), Notification hub, OTP, and PayPal Payment.
- Database: The system uses SQL Server (as indicated by the migrations, update-database command, and SQL templates contained in SrcTemplate).

b. Relationships and Interactions:
- Controllers receive HTTP requests and call the respective service layer methods.
- Each service interacts with its domain repositories and uses the common specifications (from the Core) for data querying.
- Shared utilities and configurations (like JWT authentication in Auth, Mapping Profiles, Middleware, and exception handling) are applied across projects.
- The Core module is the central dependency that many modules use, ensuring consistency in model definitions and repository patterns.
- External API integrations (for example, PayPal Payment service and Cloud Image service) act as third-party integrations that are called from within application services.

c. Architectural Patterns:
- Separation of Concerns: Clear division into Controllers, Services, Repositories, and Domain models.
- Domain-Driven Design elements: Each domain (Auth, Bus, Ticket, etc.) is self-contained with its DTOs, validators, specifications, and business logic.
- Repository and Unit of Work patterns: These are implemented under BusBookTicket.Core.
- Use of External Middleware for cross-cutting concerns (exception handling, JWT authentication).

d. Relevant Technologies, Frameworks, and Libraries:
- .NET / C# for backend API development.
- Entity Framework (migrations and DbContext in BusBookTicket.Core) along with Dapper (given the presence of DapperContext) for data access.
- ASP.NET Core for building RESTful endpoints (Controllers, Middleware).
- Third-party integrations for Payment (PayPal), Mail services, and Cloud Image processing.
- Possibly SignalR (NotificationHub) for real-time notifications.

##### Putting It All Together
- Separate technical blocks for “External Services” (Cloud Image, Mail, Notification, OTP, PayPal) that are invoked by the respective modules.
- Incorporate middleware components like Authentication (JWT utilities) and Exception Middleware (global error handling) as cross-cutting concerns touching the API layer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Gateway / Controllers
    subgraph "API Gateway / Controllers"
        addressCtrl["Address Management Controller"]:::api
        authCtrl["Authentication Controllers"]:::api
        billCtrl["Billing Controller"]:::api
        busCtrl["Bus Management Controllers"]:::api
        busStationCtrl["Bus Station Management Controller"]:::api
        companyCtrl["Company Management Controller"]:::api
        customerCtrl["Customer Management Controller"]:::api
        discountCtrl["Discount Management Controller"]:::api
        priceCtrl["Price Management Controllers"]:::api
        ticketCtrl["Ticketing Controllers"]:::api
        rankCtrl["Ranks Management Controller"]:::api
        reviewCtrl["Review Management Controller"]:::api
        routeCtrl["Routes Management Controllers"]:::api
    end

    %% Service Layer
    subgraph "Service Layer"
        addressSrv["Address Management Services"]:::service
        authSrv["Authentication Services"]:::service
        billSrv["Billing Services"]:::service
        busSrv["Bus Services"]:::service
        busStationSrv["Bus Station Services"]:::service
        companySrv["Company Services"]:::service
        customerSrv["Customer Services"]:::service
        discountSrv["Discount Services"]:::service
        priceSrv["Price Management Services"]:::service
        rankSrv["Ranks Services"]:::service
        reviewSrv["Review Services"]:::service
        routeSrv["Routes Services"]:::service
        ticketSrv["Ticketing Services"]:::service
    end

    %% Core / Domain Layer
    subgraph "Core/Domain Layer"
        coreEntity["Domain Models"]:::domain
        coreRepo["Repository & UoW"]:::domain
        coreMigr["Migrations"]:::domain
        coreSpec["Specifications"]:::domain
    end

    %% External Services
    subgraph "External Services"
        cloudImg["Cloud Image Processing"]:::external
        mailService["Mail Service (MailKet)"]:::external
        notifSrv["Notification Service"]:::external
        otpSrv["OTP Service"]:::external
        payPalSrv["PayPal Payment Service"]:::external
    end

    %% Middleware & Cross-Cutting Concerns
    subgraph "Middleware & Cross-Cutting"
        exMiddleware["Exception Handling Middleware"]:::middleware
        jwtUtil["JWT Utilities & Middleware"]:::middleware
        mappingProfile["Mapping Profiles"]:::middleware
    end

    %% Database
    db["SQL Server (Database)"]:::database

    %% API Controllers --> Service Layer
    addressCtrl -->|"calls"| addressSrv
    authCtrl -->|"calls"| authSrv
    billCtrl -->|"calls"| billSrv
    busCtrl -->|"calls"| busSrv
    busStationCtrl -->|"calls"| busStationSrv
    companyCtrl -->|"calls"| companySrv
    customerCtrl -->|"calls"| customerSrv
    discountCtrl -->|"calls"| discountSrv
    priceCtrl -->|"calls"| priceSrv
    ticketCtrl -->|"calls"| ticketSrv
    rankCtrl -->|"calls"| rankSrv
    reviewCtrl -->|"calls"| reviewSrv
    routeCtrl -->|"calls"| routeSrv

    %% Service Layer --> Core/Domain Layer
    addressSrv -->|"uses"| coreRepo
    authSrv -->|"uses"| coreRepo
    billSrv -->|"uses"| coreRepo
    busSrv -->|"uses"| coreRepo
    busStationSrv -->|"uses"| coreRepo
    companySrv -->|"uses"| coreRepo
    customerSrv -->|"uses"| coreRepo
    discountSrv -->|"uses"| coreRepo
    priceSrv -->|"uses"| coreRepo
    ticketSrv -->|"uses"| coreRepo
    rankSrv -->|"uses"| coreRepo
    reviewSrv -->|"uses"| coreRepo
    routeSrv -->|"uses"| coreRepo

    %% Internal detailing within Core/Domain Layer
    coreEntity --> coreRepo
    coreMigr --> coreRepo
    coreSpec --> coreRepo

    %% Core Repository --> Database
    coreRepo -->|"persists to"| db

    %% Middleware connections (cross-cutting applied to API Controllers)
    authCtrl ---|"secured_by"| jwtUtil
    billCtrl ---|"monitored_by"| exMiddleware
    ticketCtrl ---|"mapped_by"| mappingProfile

    %% External Services Integrations from Service Layer
    busSrv -->|"integrates"| cloudImg
    billSrv -->|"triggers"| mailService
    ticketSrv -->|"processes_payment"| payPalSrv
    ticketSrv -->|"notifies"| notifSrv
    authSrv -->|"verifies_otp"| otpSrv

    %% Click Events for API Controllers
    click addressCtrl "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.AddressManagement/Controllers/AddressController.cs"
    click authCtrl "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.Auth/Controllers/AuthControllers.cs"
    click billCtrl "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.BillManage/Controllers/BillController.cs"
    click busCtrl "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.Buses/Controllers/BusController.cs"
    click busStationCtrl "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.BusStationManage/Controllers/BusStationControllers.cs"
    click companyCtrl "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.Company/Controllers/CompanyController.cs"
    click customerCtrl "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.Customer/Controller/CustomerController.cs"
    click discountCtrl "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.DiscountManage/Controllers/DiscountController.cs"
    click priceCtrl "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.PriceManage/Controller/PriceController.cs"
    click ticketCtrl "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.Ticket/Controllers/TicketController.cs"
    click rankCtrl "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.Ranks/Controllers/RankController.cs"
    click reviewCtrl "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.ReviewManage/Controllers/ReviewController.cs"
    click routeCtrl "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.RoutesManage/Controllers/RoutesController.cs"

    %% Click Events for Service Layer
    click addressSrv "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.AddressManagement/Services"
    click authSrv "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.Auth/Services/AuthService"
    click billSrv "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.BillManage/Services"
    click busSrv "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.Buses/Services"
    click busStationSrv "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.BusStationManage/Services/BusStationService.cs"
    click companySrv "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.Company/Services/CompanyService.cs"
    click customerSrv "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.Customer/Services/CustomerService.cs"
    click discountSrv "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.DiscountManage/Services/DiscountService.cs"
    click priceSrv "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.PriceManage/Services"
    click rankSrv "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.Ranks/Services/RankService.cs"
    click reviewSrv "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.ReviewManage/Services/ReviewService.cs"
    click routeSrv "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.RoutesManage/Service"
    click ticketSrv "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.Ticket/Services"

    %% Click Events for Core/Domain Layer
    click coreEntity "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.Core/Models/Entity/"
    click coreRepo "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.Core/Infrastructure/GenericRepository.cs"
    click coreMigr "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.Core/Migrations/"
    click coreSpec "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.Core/Application/Specification/"

    %% Click Events for External Services
    click cloudImg "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.Application/CloudImage"
    click mailService "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.Application/MailKet"
    click notifSrv "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.Application/Notification"
    click otpSrv "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.Application/OTP"
    click payPalSrv "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.Application/PayPalPayment/Services"

    %% Click Events for Middleware
    click exMiddleware "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket/Exceptions/ExceptionMiddleware.cs"
    click jwtUtil "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket.Auth/Security/JwtUtils.cs"
    click mappingProfile "https://github.com/mdung0807/busticketbookingapi/blob/ver2/BusBookTicket/Configs/MappingProfile.cs"

    %% Click Event for Database
    click db "https://github.com/mdung0807/busticketbookingapi/tree/ver2/BusBookTicket.Core/Migrations/"

    %% Styles
    classDef api fill:#f9e79f,stroke:#7d6608,stroke-width:2px;
    classDef service fill:#aed6f1,stroke:#21618c,stroke-width:2px;
    classDef domain fill:#abebc6,stroke:#1e8449,stroke-width:2px;
    classDef external fill:#f5cba7,stroke:#b9770e,stroke-width:2px;
    classDef middleware fill:#d2b4de,stroke:#6c3483,stroke-width:2px;
    classDef database fill:#fadbd8,stroke:#943126,stroke-width:2px;
```
