How chanmeng666/automotive-repair-management-system works
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: main.py Workflow blueprints · base.py Tenant-scoped ORM models · __init__.py Application factory · auth_service.py Authentication service
Components 18
Runtime
- Dev / production entry · Development uses run.py; production serves the WSGI app via Gunicorn.
run.py - Application factory · Registers extensions, blueprints, and request lifecycle behavior.
app/__init__.py - Extensions
app/extensions.py
Flask HTTP layer
- Tenant context middleware · Resolves the active organization into request-local state.
app/middleware/tenant.py - Auth and RBAC guards · Enforces login, tenant membership, and permissions before handlers run.
app/utils/decorators.py - Workflow blueprints · Public, auth, technician, administrator, billing, and onboarding routes.
app/views/main.py - Server-rendered UI · Shared layouts and technician/administrator portal screens.
app/templates/base/layout.html - Security and error handling · CSRF, sanitization, password hashing, headers, and error translation.
app/utils/security.py
Tenant domain
- Authentication service · Local sessions plus Google OAuth and optional Neon JWT verification.
app/services/auth_service.py - Tenant onboarding service · Organization setup, invitations, configuration, and catalog seeding.
app/services/tenant_service.py - Work-order service · Manages lifecycle, assignment, parts/services, totals, and completion.
app/services/job_service.py - Customer service
app/services/customer_service.py - Billing services · Creates Checkout and portal sessions and coordinates billing reports.
app/services/stripe_service.py
Persistence
- Tenant-scoped ORM models · Shared-schema entities cover organizations, memberships, jobs, customers, catalog, inventory, and subscriptions.
app/models/base.py - Neon PostgreSQL / SQLite · Neon PostgreSQL in cloud deployments; SQLite locally.
- Schema migrations · Creates shared-schema tenancy and enforces tenant constraints.
migrations/versions/003_enforce_tenant_constraints.py
External services
- Stripe
- Google OAuth and Neon Auth · OAuth login and optional JWKS-backed JWT verification.
Connections 24
- 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