# chanmeng666/automotive-repair-management-system architecture

> Architecture diagram of the GitHub repository chanmeng666/automotive-repair-management-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chanmeng666/automotive-repair-management-system
- Repository: https://github.com/chanmeng666/automotive-repair-management-system

## Overview

#### Purpose and entry points
RepairOS is a server-rendered, multi-tenant SaaS for automotive repair shops: work orders, customers, catalogs, inventory, team roles, and subscription billing. Flask uses an application-factory architecture. Development starts at `run.py`; production serves the WSGI application through `wsgi.py` and `Procfile`. Application setup, extension registration, blueprint wiring, and request lifecycle configuration center on `app/__init__.py` and `app/extensions.py`.

#### HTTP and presentation layer
Flask blueprints separate public, authentication, technician, administrator, billing, and onboarding HTTP workflows:
- `app/views/main.py`
- `app/views/auth.py`
- `app/views/technician.py`
- `app/views/administrator.py`
- `app/views/billing.py`
- `app/views/onboarding.py`

Views render Jinja templates and expose limited JSON endpoints. The UI is Bootstrap/vanilla JS, served directly by Flask; no frontend build runtime. Shared layouts and portal-specific screens are in `app/templates/base/layout.html`, `app/templates/technician/`, and `app/templates/administrator/`.

#### Tenant isolation and authorization boundary
Shared-schema tenancy is the central data boundary. Request middleware resolves the active organization from tenant-scoped URL forms, session state, or tenant context and places it in request-local state: `app/middleware/tenant.py`. Tenant-aware SQLAlchemy model behavior is defined in `app/models/base.py`; tenant ownership and per-tenant role membership reside in `app/models/tenant.py` and `app/models/tenant_membership.py`.

Authentication/session and RBAC guards constrain views before services execute, including login, tenant-required, and permission-required checks: `app/utils/decorators.py`, `app/services/auth_service.py`, `app/models/user.py`. A user can select or switch tenants; roles distinguish owner/admin/manager/technician/parts clerk/viewer.

#### Operational domain and business services
Views delegate business operations to service classes rather than embedding domain logic. Work-order lifecycle—creation, assignment, attached services/parts, totals, and completion—is handled through `app/services/job_service.py` over `app/models/job.py`. Customer operations are isolated in `app/services/customer_service.py` and `app/models/customer.py`.

Tenant onboarding, organization configuration, invitations, and catalog seeding flow through `app/services/tenant_service.py`. Parts, service catalog, stock levels, and adjustment histories are represented by `app/models/part.py`, `app/models/service.py`, and `app/models/inventory.py`.

#### Billing and external integrations
Subscription state is persisted per tenant in `app/models/subscription.py`. `app/services/stripe_service.py` creates Stripe Checkout and billing-portal interactions; `app/views/billing.py` receives Stripe webhooks to synchronize subscription state. Administrative billing/payment reporting is coordinated in `app/services/billing_service.py`.

Authentication supports local password/session authentication plus Google OAuth and optional Neon Auth JWT verification, concentrated in `app/services/auth_service.py` and `app/views/auth.py`. External dependencies are Stripe, Google OAuth, and Neon Auth/JWKS.

#### Persistence, migrations, and runtime infrastructure
SQLAlchemy 2.0 persists to Neon PostgreSQL in cloud deployments; SQLite supports local testing. Alembic establishes and evolves the shared-schema tenant design, including tenant backfill and constraints:
- `migrations/versions/001_create_multitenant_tables.py`
- `migrations/versions/003_enforce_tenant_constraints.py`
- `migrations/versions/004_neon_auth_migration.py`

Configuration selects development, production, and testing behavior in `config/base.py`. Production is Gunicorn on Heroku, connecting to Neon PostgreSQL over configured SSL.

#### Primary request flow
A browser request enters Flask, tenant middleware establishes tenant context, decorators validate session/role/tenant access, and a blueprint invokes the relevant service. Services query/update tenant-scoped ORM entities and commit through SQLAlchemy; the view returns a Jinja page, redirect, or JSON. Stripe webhook requests form a separate unauthenticated but signature-validated integration boundary, updating local subscription records. Security cross-cutting concerns—CSRF, input sanitization, password hashing, headers, and error translation—are centralized in `app/utils/security.py` and `app/utils/error_handler.py`.

Main entry points: [`app/views/main.py`](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/views/main.py) (Workflow blueprints), [`app/models/base.py`](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/models/base.py) (Tenant-scoped ORM models), [`app/__init__.py`](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/__init__.py) (Application factory), [`app/services/auth_service.py`](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/services/auth_service.py) (Authentication service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_entrypoints["Dev / production entry<br/>Python runtime<br/>[run.py]"]
  node_app_factory["Application factory<br/>Flask setup<br/>[__init__.py]"]
  node_extensions["Extensions<br/>[extensions.py]"]
end

subgraph group_http["Flask HTTP layer"]
  node_tenant_middleware{{"Tenant context middleware<br/>request boundary<br/>[tenant.py]"}}
  node_auth_guards{{"Auth and RBAC guards<br/>decorators and auth<br/>[decorators.py]"}}
  node_blueprints["Workflow blueprints<br/>Flask views<br/>[main.py]"]
  node_templates["Server-rendered UI<br/>Jinja and static UI<br/>[layout.html]"]
  node_security{{"Security and error handling<br/>cross-cutting utilities<br/>[security.py]"}}
end

subgraph group_domain["Tenant domain"]
  node_auth_service["Authentication service<br/>identity service<br/>[auth_service.py]"]
  node_tenant_service["Tenant onboarding service<br/>tenant service<br/>[tenant_service.py]"]
  node_job_service["Work-order service<br/>job service<br/>[job_service.py]"]
  node_customer_service["Customer service"]
  node_billing_services["Billing services<br/>Stripe and reporting services<br/>[stripe_service.py]"]
end

subgraph group_data["Persistence"]
  node_tenant_models[("Tenant-scoped ORM models<br/>SQLAlchemy models<br/>[base.py]")]
  node_database[("Neon PostgreSQL / SQLite<br/>relational database")]
  node_migrations["Schema migrations<br/>Alembic migrations"]
end

subgraph group_external["External services"]
  node_stripe(("Stripe<br/>payment platform"))
  node_identity_providers(("Google OAuth and Neon Auth<br/>external identity"))
end

node_entrypoints -->|"starts"| node_app_factory
node_app_factory -->|"registers"| node_extensions
node_app_factory -->|"wires"| node_blueprints
node_app_factory -->|"configures"| node_tenant_middleware
node_app_factory -->|"configures"| node_security
node_blueprints -->|"request context"| node_tenant_middleware
node_tenant_middleware -->|"tenant context"| node_auth_guards
node_auth_guards -->|"allows handlers"| node_blueprints
node_blueprints -->|"renders pages"| node_templates
node_blueprints -->|"auth workflows"| node_auth_service
node_blueprints -->|"onboarding workflows"| node_tenant_service
node_blueprints -->|"work-order workflows"| node_job_service
node_blueprints -->|"customer workflows"| node_customer_service
node_blueprints -->|"billing and webhooks"| node_billing_services
node_auth_service -->|"users and memberships"| node_tenant_models
node_auth_service -->|"OAuth / JWT verification"| node_identity_providers
node_tenant_service -->|"creates and configures"| node_tenant_models
node_job_service -->|"queries and updates"| node_tenant_models
node_customer_service -->|"queries and updates"| node_tenant_models
node_billing_services -->|"syncs subscriptions"| node_tenant_models
node_billing_services -->|"Checkout, portal, webhooks"| node_stripe
node_tenant_models -->|"persists through SQLAlchemy"| node_database
node_migrations -->|"evolves schema"| node_database
node_security -.->|"protects responses"| node_blueprints

click node_entrypoints "https://github.com/chanmeng666/automotive-repair-management-system/blob/main/run.py"
click node_app_factory "https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/__init__.py"
click node_extensions "https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/extensions.py"
click node_tenant_middleware "https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/middleware/tenant.py"
click node_auth_guards "https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/utils/decorators.py"
click node_blueprints "https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/views/main.py"
click node_templates "https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/templates/base/layout.html"
click node_security "https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/utils/security.py"
click node_auth_service "https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/services/auth_service.py"
click node_tenant_service "https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/services/tenant_service.py"
click node_job_service "https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/services/job_service.py"
click node_customer_service "https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/services/customer_service.py"
click node_billing_services "https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/services/stripe_service.py"
click node_tenant_models "https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/models/base.py"
click node_migrations "https://github.com/chanmeng666/automotive-repair-management-system/blob/main/migrations/versions/003_enforce_tenant_constraints.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entrypoints,node_app_factory,node_extensions toneBlue
class node_tenant_middleware,node_auth_guards,node_blueprints,node_templates,node_security toneAmber
class node_auth_service,node_tenant_service,node_job_service,node_customer_service,node_billing_services toneMint
class node_tenant_models,node_database,node_migrations toneRose
class node_stripe,node_identity_providers toneIndigo
```

## Components

### Runtime

- [Dev / production entry](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/run.py): Python runtime · Development uses run.py; production serves the WSGI app via Gunicorn. · `run.py`
- [Application factory](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/__init__.py): Flask setup · Registers extensions, blueprints, and request lifecycle behavior. · `app/__init__.py`
- [Extensions](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/extensions.py): SQLAlchemy and Flask extensions · `app/extensions.py`

### Flask HTTP layer

- [Tenant context middleware](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/middleware/tenant.py): request boundary · Resolves the active organization into request-local state. · `app/middleware/tenant.py`
- [Auth and RBAC guards](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/utils/decorators.py): decorators and auth · Enforces login, tenant membership, and permissions before handlers run. · `app/utils/decorators.py`
- [Workflow blueprints](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/views/main.py): Flask views · Public, auth, technician, administrator, billing, and onboarding routes. · `app/views/main.py`
- [Server-rendered UI](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/templates/base/layout.html): Jinja and static UI · Shared layouts and technician/administrator portal screens. · `app/templates/base/layout.html`
- [Security and error handling](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/utils/security.py): cross-cutting utilities · CSRF, sanitization, password hashing, headers, and error translation. · `app/utils/security.py`

### Tenant domain

- [Authentication service](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/services/auth_service.py): identity service · Local sessions plus Google OAuth and optional Neon JWT verification. · `app/services/auth_service.py`
- [Tenant onboarding service](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/services/tenant_service.py): tenant service · Organization setup, invitations, configuration, and catalog seeding. · `app/services/tenant_service.py`
- [Work-order service](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/services/job_service.py): job service · Manages lifecycle, assignment, parts/services, totals, and completion. · `app/services/job_service.py`
- [Customer service](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/services/customer_service.py): customer service · `app/services/customer_service.py`
- [Billing services](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/services/stripe_service.py): Stripe and reporting services · Creates Checkout and portal sessions and coordinates billing reports. · `app/services/stripe_service.py`

### Persistence

- [Tenant-scoped ORM models](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/app/models/base.py): SQLAlchemy models · Shared-schema entities cover organizations, memberships, jobs, customers, catalog, inventory, and subscriptions. · `app/models/base.py`
- **Neon PostgreSQL / SQLite**: relational database · Neon PostgreSQL in cloud deployments; SQLite locally.
- [Schema migrations](https://github.com/chanmeng666/automotive-repair-management-system/blob/main/migrations/versions/003_enforce_tenant_constraints.py): Alembic migrations · Creates shared-schema tenancy and enforces tenant constraints. · `migrations/versions/003_enforce_tenant_constraints.py`

### External services

- **Stripe**: payment platform
- **Google OAuth and Neon Auth**: external identity · OAuth login and optional JWKS-backed JWT verification.

## Connections

- Dev / production entry → Application factory: starts
- Application factory → Extensions: registers
- Application factory → Workflow blueprints: wires
- Application factory → Tenant context middleware: configures
- Application factory → Security and error handling: configures
- Workflow blueprints → Tenant context middleware: request context
- Tenant context middleware → Auth and RBAC guards: tenant context
- Auth and RBAC guards → Workflow blueprints: allows handlers
- Workflow blueprints → Server-rendered UI: renders pages
- Workflow blueprints → Authentication service: auth workflows
- Workflow blueprints → Tenant onboarding service: onboarding workflows
- Workflow blueprints → Work-order service: work-order workflows
- Workflow blueprints → Customer service: customer workflows
- Workflow blueprints → Billing services: billing and webhooks · Webhook handlers validate Stripe signatures before synchronization.
- Authentication service → Tenant-scoped ORM models: users and memberships
- Authentication service → Google OAuth and Neon Auth: OAuth / JWT verification
- Tenant onboarding service → Tenant-scoped ORM models: creates and configures
- Work-order service → Tenant-scoped ORM models: queries and updates
- Customer service → Tenant-scoped ORM models: queries and updates
- Billing services → Tenant-scoped ORM models: syncs subscriptions
- Billing services → Stripe: Checkout, portal, webhooks
- Tenant-scoped ORM models → Neon PostgreSQL / SQLite: persists through SQLAlchemy
- Schema migrations → Neon PostgreSQL / SQLite: evolves schema
- Security and error handling → Workflow blueprints: protects responses
