# mechanist01/clausal-fe architecture

> Architecture diagram of the GitHub repository mechanist01/clausal-fe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mechanist01/clausal-fe
- Repository: https://github.com/mechanist01/clausal-fe

## Overview

##### Main Components Identification

A. Frontend Layer (React Application)
- Present this as the top-level layer with these main modules:
- Authentication (Auth component)
- Contract Analysis
- Contract IQ (Chat interface)
- Risk Assessment
- Upload functionality
- Layout components

B. State Management Layer
- Two distinct stores:
- Chat Store (src/store/chatStore.ts)
- Risk Store (src/store/riskStore.ts)

C. Services Layer
- API Service (src/services/api.ts)
- Contract Service (src/services/contractService.ts)

D. External Services
- Supabase (Authentication & Database)

##### Component Relationships

**┌─────────────────────────────────────── UI Layer ───────────────────────────────────────┐**

- ┌─────────────┐    ┌─────────────┐    ┌─────────────┐    ┌─────────────┐            │
- Auth     │    │  Contract   │    │  Contract   │    │    Risk     │            │
- Components │    │  Analysis   │    │     IQ      │    │ Assessment  │            │
- ┘    └─────────────┘    └─────────────┘    └─────────────┘            │

- ┘
- ▲

- ▼
**┌─────────────────────────────────── State Layer ──────────────────────────────────────┐**

- ┌──────────────┐            ┌──────────────┐                      │
- Chat Store  │            │  Risk Store  │                      │
- ┘            └──────────────┘                      │

- ┘
- ▲

- ▼
**┌────────────────────────────────── Services Layer ────────────────────────────────────┐**

- ┌──────────────┐                  ┌──────────────┐                     │
- API Service  │                  │   Contract   │                     │
- Service    │                     │
- ┘                  └──────────────┘                     │

- ┘
- ▲

- ▼
**┌────────────────────────────────── External Services ──────────────────────────────────┐**

- ┌──────────────┐                                   │
- Supabase   │                                   │
- ┘                                   │

- ┘

##### Additional Elements
- A Context section showing ContractContext
- Private routing flow
- Authentication flow through Supabase
- Where TypeScript types (from src/types) are used

##### Important Notes
- Clear separation between authenticated and public routes
- Data flow between Contract Analysis, Risk Assessment, and Contract IQ features
- Role of LoadingSpinner components in the UI layer

##### Technical Stack Indicators
- React (TypeScript)
- Tailwind CSS for styling
- Supabase for backend services
- Context API for state management

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions that impact the system's behavior and maintainability.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#3b82f6,color:white
    classDef state fill:#22c55e,color:white
    classDef service fill:#f97316,color:white
    classDef external fill:#a855f7,color:white
    classDef context fill:#64748b,color:white

    %% UI Layer
    subgraph UI
        Auth["Authentication"]:::ui
        ContractAnalysis["Contract Analysis"]:::ui
        ContractIQ["Contract IQ"]:::ui
        RiskAssess["Risk Assessment"]:::ui
        Upload["Upload"]:::ui
        Layout["Layout Components"]:::ui
        Loading["Loading Components"]:::ui
        Pages["Pages"]:::ui
    end

    %% State Layer
    subgraph State
        ChatStore["Chat Store"]:::state
        RiskStore["Risk Store"]:::state
        ContractCtx["Contract Context"]:::context
    end

    %% Services Layer
    subgraph Services
        APIService["API Service"]:::service
        ContractService["Contract Service"]:::service
    end

    %% External Layer
    Supabase["Supabase"]:::external

    %% Types
    Types["Type Definitions"]:::context

    %% Relationships
    Auth --> ContractCtx
    ContractAnalysis --> ContractCtx
    ContractIQ --> ChatStore
    RiskAssess --> RiskStore
    Upload --> ContractService
    
    ChatStore --> APIService
    RiskStore --> APIService
    ContractCtx --> ContractService
    
    APIService --> Supabase
    ContractService --> Supabase
    Auth --> Supabase

    Types --> ContractCtx
    Types --> ChatStore
    Types --> RiskStore

    %% Click Events
    click Auth "https://github.com/mechanist01/clausal-FE/blob/master/src/components/Auth/PrivateRoute.tsx"
    click ContractAnalysis "https://github.com/mechanist01/clausal-FE/blob/master/src/components/ContractAnalysis/ContractAnalysis.tsx"
    click ContractIQ "https://github.com/mechanist01/clausal-FE/blob/master/src/components/ContractIQ/Chat.tsx"
    click RiskAssess "https://github.com/mechanist01/clausal-FE/blob/master/src/components/RiskAssessment/RiskAssessment.tsx"
    click Upload "https://github.com/mechanist01/clausal-FE/blob/master/src/components/Upload/Upload.tsx"
    click Layout "https://github.com/mechanist01/clausal-FE/blob/master/src/components/Layout/Sidebar.tsx"
    click Loading "https://github.com/mechanist01/clausal-FE/tree/master/src/components/LoadingSpinner"
    click ChatStore "https://github.com/mechanist01/clausal-FE/blob/master/src/store/chatStore.ts"
    click RiskStore "https://github.com/mechanist01/clausal-FE/blob/master/src/store/riskStore.ts"
    click APIService "https://github.com/mechanist01/clausal-FE/blob/master/src/services/api.ts"
    click ContractService "https://github.com/mechanist01/clausal-FE/blob/master/src/services/contractService.ts"
    click Supabase "https://github.com/mechanist01/clausal-FE/blob/master/src/config/supabase.ts"
    click ContractCtx "https://github.com/mechanist01/clausal-FE/blob/master/src/contexts/ContractContext.tsx"
    click Types "https://github.com/mechanist01/clausal-FE/tree/master/src/types"
    click Pages "https://github.com/mechanist01/clausal-FE/tree/master/src/pages"
```
