# driveflow-crm/driveflow-crm-api architecture

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

- Interactive diagram: https://gitdiagram.com/driveflow-crm/driveflow-crm-api
- Repository: https://github.com/driveflow-crm/driveflow-crm-api

## Overview

##### Project type and purpose
- DriveFlow-CRM-API is a .NET 8.0 web application exposing a REST-style API (via Controllers) and a minimal UI (via Razor Identity pages). It serves as the backend for a Customer Relationship Management system, handling user authentication/authorization, CRUD operations on domain entities (AutoSchool, Instructor, Student, Vehicle, etc.), and integrates with external services (e.g., InvoiceService).

##### File structure
- Top-level folders:
- Areas/Identity + Pages/Shared + wwwroot → built-in ASP.NET Identity UI and static assets
- Controllers/ → REST controllers
- Models/ → EF Core entity definitions & DbContext
- Migrations/ → EF Core migrations
- Json/ → JSON serialization contexts
- Auth/, ITokenGenerator, JwtAccessTokenGenerator, RefreshTokenService, TokenGeneratorFactory → authentication & JWT workflow
- DriveFlow.Tests/ → integration/unit tests for models and token generators
- Dockerfile, heroku.yml → containerization and Heroku deployment
- Build & configuration: DriveFlow-CRM-API.csproj, appsettings.json, launchSettings.json

##### Key insights from README
- Clean, maintainable layering with EF Core for data access
- Swagger/OpenAPI for documentation
- JawsDB MySQL (cloud) as persistent store
- Environment variables for secrets, invoice service endpoint

##### Diagramming recommendations
- From Clients to API Host (HTTP request)
- From API Host to Identity/Authentication subsystem
- From Controllers to Services to DbContext to Database
- From Controllers to External InvoiceService
- In-host components (API + Identity + Services)
- External components (MySQL, InvoiceService)
- Protocols (HTTP, HTTPS, JWT tokens) and data formats (JSON)

##### Detail and component count
- Don’t skip low-level building blocks: include JSON serialization contexts, TokenGeneratorFactory, RefreshTokenService, DbContextFactory
- EF Core migrations as part of the data-persistence lifecycle
- Test suite as a separate artifact verifying model and token logic (optional)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    subgraph "Clients"
        Web["Web UI"]:::client
        Mobile["Mobile App"]:::client
        Third["Third-party Clients"]:::client
    end

    Web -->|HTTPS/JSON| APIHost
    Mobile -->|HTTPS/JSON| APIHost
    Third -->|HTTPS/JSON| APIHost

    %% API Host
    subgraph "API Host (Kestrel)" 
        direction TB
        HTTP["HTTP(S) Request Handler"]:::inhost

        subgraph "Presentation Layer"
            direction TB
            IdentityUI["ASP.NET Identity UI"]:::auth
            Layout["_Layout.cshtml"]:::auth
            Validation["_ValidationScriptsPartial.cshtml"]:::auth
            Swagger["Swagger/OpenAPI UI"]:::doc
        end

        subgraph "Authentication & Authorization"
            direction TB
            AuthMiddleware["Auth Middleware"]:::auth
            SameReq["SameSchoolRequirement/Handler"]:::auth
            ClaimsHandlers["Claim Handlers"]:::auth
        end

        subgraph "API Layer"
            direction TB
            Controllers["REST API Controllers"]:::api
        end

        subgraph "Service Layer"
            direction TB
            TokenFactory["TokenGeneratorFactory"]:::service
            ITokenGen["ITokenGenerator & Claim Interfaces"]:::service
            JwtGen["JwtAccessTokenGenerator"]:::service
            RefreshService["RefreshTokenService"]:::service
        end

        subgraph "Data Access Layer"
            direction TB
            DbContext["ApplicationDbContext"]:::data
            JsonCtx["JSON Serialization Context"]:::data
            Migrations["EF Core Migrations"]:::data
        end

        HTTP -->|routes to| IdentityUI
        HTTP -->|routes to| Layout
        HTTP -->|routes to| Validation
        HTTP -->|routes to| Swagger
        HTTP -->|invokes| AuthMiddleware
        AuthMiddleware -->|validates| Controllers
        Controllers -->|uses| TokenFactory
        Controllers -->|uses| ITokenGen
        Controllers -->|uses| JwtGen
        Controllers -->|uses| RefreshService
        Controllers -->|CRUD ops| DbContext
        DbContext -->|applies migrations| Migrations
        Controllers -->|serializes JSON| JsonCtx
        Controllers -->|calls| Invoice
    end

    %% External Components
    subgraph "External Components"
        direction TB
        MySQLDB["MySQL Database (JawsDB)"]:::external
        Invoice["InvoiceService API"]:::external
    end

    DbContext -->|SQL| MySQLDB
    Controllers -->|HTTPS| Invoice

    %% Click Events
    click IdentityUI "https://github.com/driveflow-crm/driveflow-crm-api/tree/main/DriveFlow-CRM-API/Areas/Identity/Pages"
    click Layout "https://github.com/driveflow-crm/driveflow-crm-api/blob/main/DriveFlow-CRM-API/Pages/Shared/_Layout.cshtml"
    click Validation "https://github.com/driveflow-crm/driveflow-crm-api/blob/main/DriveFlow-CRM-API/Pages/Shared/_ValidationScriptsPartial.cshtml"
    click Controllers "https://github.com/driveflow-crm/driveflow-crm-api/blob/main/DriveFlow-CRM-API/Controllers/AutoSchoolController.cs"
    click DbContext "https://github.com/driveflow-crm/driveflow-crm-api/blob/main/DriveFlow-CRM-API/Models/ApplicationDbContext.cs"
    click Migrations "https://github.com/driveflow-crm/driveflow-crm-api/blob/main/DriveFlow-CRM-API/Migrations/20250426212707_InitializareBazaDeDate.cs"
    click JsonCtx "https://github.com/driveflow-crm/driveflow-crm-api/blob/main/DriveFlow-CRM-API/Json/AppJsonContext.cs"
    click SameReq "https://github.com/driveflow-crm/driveflow-crm-api/blob/main/DriveFlow-CRM-API/Auth/SameSchoolRequirement.cs"
    click ClaimsHandlers "https://github.com/driveflow-crm/driveflow-crm-api/blob/main/DriveFlow-CRM-API/SchoolClaimHandler.cs"
    click ITokenGen "https://github.com/driveflow-crm/driveflow-crm-api/blob/main/DriveFlow-CRM-API/ITokenGenerator.cs"
    click JwtGen "https://github.com/driveflow-crm/driveflow-crm-api/blob/main/DriveFlow-CRM-API/JwtAccessTokenGenerator.cs"
    click RefreshService "https://github.com/driveflow-crm/driveflow-crm-api/blob/main/DriveFlow-CRM-API/RefreshTokenService.cs"
    click TokenFactory "https://github.com/driveflow-crm/driveflow-crm-api/blob/main/DriveFlow-CRM-API/TokenGeneratorFactory.cs"

    %% Styles
    classDef client fill:#E3F2FD,stroke:#90CAF9,color:#0D47A1;
    classDef inhost fill:#BBDEFB,stroke:#64B5F6,color:#0D47A1;
    classDef auth fill:#FFF3E0,stroke:#FFB74D,color:#E65100;
    classDef api fill:#E1F5FE,stroke:#4FC3F7,color:#01579B;
    classDef service fill:#F3E5F5,stroke:#CE93D8,color:#6A1B9A;
    classDef data fill:#E8F5E9,stroke:#A5D6A7,color:#1B5E20;
    classDef external fill:#F5F5F5,stroke:#BDBDBD,color:#424242;
    classDef doc fill:#FFFDE7,stroke:#FFF176,color:#F57F17;
```
