# meetmendapara09/gearlink-crm architecture

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

- Interactive diagram: https://gitdiagram.com/meetmendapara09/gearlink-crm
- Repository: https://github.com/meetmendapara09/gearlink-crm

## Overview

#### Purpose and runtime
GearLink CRM is a Next.js App Router business-management application for auto-parts stores. It combines CRM, POS/sales, inventory, invoicing, planning, reporting, and AI-assisted workflows. The primary runtime is the Next.js server/client application; AI flows run through a separate Genkit development/runtime process. Firebase provides authentication and likely application backend integration. Deployment configuration is present in `apphosting.yaml`.

#### Application entry and route partitioning
The public root and account/legal pages enter through `src/app/page.tsx`, `src/app/login/page.tsx`, and `src/app/signup/page.tsx`. The root application shell is defined in `src/app/layout.tsx`; authenticated/operational routes are grouped under `src/app/(app)/layout.tsx`. Request-level access control is a distinct boundary at `src/middleware.ts`, while client auth state is supplied by `src/components/auth-provider.tsx` and consumed through `src/hooks/use-auth.ts`.

#### Auth and Firebase boundary
Firebase integration is centralized in `src/lib/firebase.ts`, with authentication-oriented logic in `src/lib/auth.ts`. Login and signup forms at `src/app/login/login-form.tsx` and `src/app/signup/signup-form.tsx` are the user-facing ingress for Firebase Authentication. This separates identity/session concerns from the business pages and middleware route protection.

#### Operational CRM modules
The authenticated route group organizes major workflows as independently routed screens: dashboard (`src/app/(app)/dashboard/page.tsx`), POS sales (`src/app/(app)/sales/page.tsx`), customers (`src/app/(app)/customers/page.tsx`), products (`src/app/(app)/products/page.tsx`), invoices (`src/app/(app)/invoices/page.tsx`), tasks, calendar, and support. Shared business entities are represented through data modules such as `src/lib/data/products.ts`, `src/lib/data/customers.ts`, and `src/lib/data/invoices.ts`, with common domain typing in `src/lib/types.ts`.

#### Sales pipeline, scheduling, and analytics
Deal progression is modeled as a visual pipeline: `src/app/(app)/sales-pipeline/page.tsx` composes `src/components/sales-pipeline-board.tsx`, `src/components/pipeline-column.tsx`, and `src/components/deal-card.tsx`; deal data is isolated in `src/lib/data/deals.ts`. Tasks and invoice timing converge in `src/app/(app)/calendar/page.tsx` via `src/components/calendar-view.tsx`. Reporting is routed through `src/app/(app)/reports/page.tsx` and rendered with chart components including `src/components/sales-chart.tsx` and `src/components/top-products-chart.tsx`.

#### AI workflow boundary
Genkit initialization is isolated at `src/ai/genkit.ts`; its development entry point is `src/ai/dev.ts`. AI capabilities are explicit flow modules: part recommendations in `src/ai/flows/smart-part-finder.ts`, campaign generation in `src/ai/flows/email-marketer.ts`, and report summarization in `src/ai/flows/sales-report-summarizer.ts`. UI entry points for these capabilities include `src/app/(app)/smart-finder/smart-finder-form.tsx` and `src/app/(app)/marketing/marketing-campaign-form.tsx`. The application invokes server-side behavior through `src/lib/actions.ts`, keeping UI forms distinct from AI/service execution.

#### Interface and infrastructure
The app-level navigation/container appears to be centralized in `src/components/app-sidebar.tsx`, with reusable ShadCN-derived primitives under `src/components/ui`. Tailwind and TypeScript form the frontend implementation stack. Key external boundaries are Firebase Authentication/backend services, Google Gemini accessed through Genkit, and Firebase App Hosting configuration in `apphosting.yaml`.

Main entry points: [`src/app/(app)/layout.tsx`](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/(app)/layout.tsx) (Authenticated shell), [`src/lib/data/products.ts`](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/lib/data/products.ts) (Business data modules), [`src/app/layout.tsx`](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/layout.tsx) (Root shell), [`src/lib/firebase.ts`](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/lib/firebase.ts) (Firebase integration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public &amp; Identity"]
  node_root_shell["Root shell<br/>Next.js layout<br/>[layout.tsx]"]
  node_public_pages["Public account pages<br/>Next.js routes<br/>[page.tsx]"]
  node_login_forms["Login &amp; signup forms<br/>client forms<br/>[login-form.tsx]"]
  node_middleware{{"Route protection<br/>Next.js middleware<br/>[middleware.ts]"}}
  node_auth_state["Client auth state<br/>auth provider hook<br/>[auth-provider.tsx]"]
end

subgraph group_app["Operational App"]
  node_app_shell["Authenticated shell<br/>route-group layout<br/>[layout.tsx]"]
  node_navigation["App navigation<br/>sidebar<br/>[app-sidebar.tsx]"]
  node_crm_routes["CRM operations<br/>routed screens<br/>[page.tsx]"]
  node_sales_pipeline["Sales pipeline<br/>pipeline screen<br/>[page.tsx]"]
  node_calendar["Calendar<br/>scheduling screen<br/>[page.tsx]"]
  node_reports["Reports<br/>analytics screen<br/>[page.tsx]"]
  node_ai_forms["AI workflow forms<br/>app forms"]
end

subgraph group_domain["Domain &amp; Backend"]
  node_domain_data[("Business data modules<br/>domain data<br/>[products.ts]")]
  node_firebase_adapter{{"Firebase integration<br/>backend adapter<br/>[firebase.ts]"}}
  node_firebase[("Firebase services<br/>external backend")]
end

subgraph group_ai["AI Workflows"]
  node_server_actions{{"Server actions<br/>service boundary<br/>[actions.ts]"}}
  node_genkit{{"Genkit runtime<br/>AI runtime<br/>[genkit.ts]"}}
  node_ai_flows["AI flows<br/>Genkit flows"]
  node_gemini(("Google Gemini<br/>external AI model"))
end

node_hosting{{"Firebase App Hosting<br/>deployment<br/>[apphosting.yaml]"}}

node_root_shell -->|"renders"| node_public_pages
node_root_shell -->|"hosts"| node_app_shell
node_middleware -->|"guards"| node_app_shell
node_public_pages -->|"contains"| node_login_forms
node_login_forms -->|"signs in/up"| node_firebase_adapter
node_auth_state -->|"uses"| node_firebase_adapter
node_firebase_adapter -->|"connects to"| node_firebase
node_app_shell -->|"includes"| node_navigation
node_app_shell -->|"routes to"| node_crm_routes
node_app_shell -->|"routes to"| node_sales_pipeline
node_app_shell -->|"routes to"| node_calendar
node_app_shell -->|"routes to"| node_reports
node_app_shell -->|"routes to"| node_ai_forms
node_crm_routes -->|"uses"| node_domain_data
node_sales_pipeline -->|"reads deals"| node_domain_data
node_calendar -->|"uses timing data"| node_domain_data
node_reports -->|"analyzes"| node_domain_data
node_ai_forms -->|"invokes"| node_server_actions
node_server_actions -->|"executes"| node_ai_flows
node_genkit -->|"runs"| node_ai_flows
node_ai_flows -->|"uses"| node_gemini
node_hosting -.->|"deploys"| node_root_shell

click node_root_shell "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/layout.tsx"
click node_public_pages "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/page.tsx"
click node_login_forms "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/login/login-form.tsx"
click node_middleware "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/middleware.ts"
click node_auth_state "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/components/auth-provider.tsx"
click node_app_shell "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/(app)/layout.tsx"
click node_navigation "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/components/app-sidebar.tsx"
click node_crm_routes "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/(app)/dashboard/page.tsx"
click node_sales_pipeline "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/(app)/sales-pipeline/page.tsx"
click node_calendar "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/(app)/calendar/page.tsx"
click node_reports "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/(app)/reports/page.tsx"
click node_ai_forms "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/(app)/smart-finder/smart-finder-form.tsx"
click node_domain_data "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/lib/data/products.ts"
click node_firebase_adapter "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/lib/firebase.ts"
click node_server_actions "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/lib/actions.ts"
click node_genkit "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/ai/genkit.ts"
click node_ai_flows "https://github.com/meetmendapara09/gearlink-crm/blob/main/src/ai/flows/smart-part-finder.ts"
click node_hosting "https://github.com/meetmendapara09/gearlink-crm/blob/main/apphosting.yaml"

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_root_shell,node_public_pages,node_login_forms,node_middleware,node_auth_state toneBlue
class node_app_shell,node_navigation,node_crm_routes,node_sales_pipeline,node_calendar,node_reports,node_ai_forms toneAmber
class node_domain_data,node_firebase_adapter,node_firebase toneMint
class node_server_actions,node_genkit,node_ai_flows,node_gemini toneRose
class node_hosting toneNeutral
```

## Components

### Public & Identity

- [Root shell](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/layout.tsx): Next.js layout · `src/app/layout.tsx`
- [Public account pages](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/page.tsx): Next.js routes · Landing, login, and signup entry routes. · `src/app/page.tsx`
- [Login & signup forms](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/login/login-form.tsx): client forms · `src/app/login/login-form.tsx`
- [Route protection](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/middleware.ts): Next.js middleware · `src/middleware.ts`
- [Client auth state](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/components/auth-provider.tsx): auth provider hook · `src/components/auth-provider.tsx`

### Operational App

- [Authenticated shell](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/(app)/layout.tsx): route-group layout · `src/app/(app)/layout.tsx`
- [App navigation](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/components/app-sidebar.tsx): sidebar · `src/components/app-sidebar.tsx`
- [CRM operations](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/(app)/dashboard/page.tsx): routed screens · Dashboard, sales, customers, products, invoices, tasks, calendar, and support. · `src/app/(app)/dashboard/page.tsx`
- [Sales pipeline](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/(app)/sales-pipeline/page.tsx): pipeline screen · Board, columns, and deal cards visualize deal progression. · `src/app/(app)/sales-pipeline/page.tsx`
- [Calendar](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/(app)/calendar/page.tsx): scheduling screen · Combines task and invoice timing. · `src/app/(app)/calendar/page.tsx`
- [Reports](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/(app)/reports/page.tsx): analytics screen · Renders sales and top-product charts. · `src/app/(app)/reports/page.tsx`
- [AI workflow forms](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/app/(app)/smart-finder/smart-finder-form.tsx): app forms · Smart Finder and marketing campaign UI entry points. · `src/app/(app)/smart-finder/smart-finder-form.tsx`

### Domain & Backend

- [Business data modules](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/lib/data/products.ts): domain data · Products, customers, invoices, and deals with shared types. · `src/lib/data/products.ts`
- [Firebase integration](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/lib/firebase.ts): backend adapter · Central Firebase initialization and authentication logic. · `src/lib/firebase.ts`
- **Firebase services**: external backend · Authentication and application backend boundary.

### AI Workflows

- [Server actions](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/lib/actions.ts): service boundary · Separates UI requests from server-side execution. · `src/lib/actions.ts`
- [Genkit runtime](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/ai/genkit.ts): AI runtime · Separate development/runtime process for AI flows. · `src/ai/genkit.ts`
- [AI flows](https://github.com/meetmendapara09/gearlink-crm/blob/main/src/ai/flows/smart-part-finder.ts): Genkit flows · Part finder, campaign generation, and report summarization. · `src/ai/flows/smart-part-finder.ts`
- **Google Gemini**: external AI model

### Other components

- [Firebase App Hosting](https://github.com/meetmendapara09/gearlink-crm/blob/main/apphosting.yaml): deployment · `apphosting.yaml`

## Connections

- Root shell → Public account pages: renders
- Root shell → Authenticated shell: hosts
- Route protection → Authenticated shell: guards
- Public account pages → Login & signup forms: contains
- Login & signup forms → Firebase integration: signs in/up
- Client auth state → Firebase integration: uses
- Firebase integration → Firebase services: connects to
- Authenticated shell → App navigation: includes
- Authenticated shell → CRM operations: routes to
- Authenticated shell → Sales pipeline: routes to
- Authenticated shell → Calendar: routes to
- Authenticated shell → Reports: routes to
- Authenticated shell → AI workflow forms: routes to
- CRM operations → Business data modules: uses
- Sales pipeline → Business data modules: reads deals
- Calendar → Business data modules: uses timing data
- Reports → Business data modules: analyzes
- AI workflow forms → Server actions: invokes
- Server actions → AI flows: executes
- Genkit runtime → AI flows: runs
- AI flows → Google Gemini: uses
- Firebase App Hosting → Root shell: deploys
