# faizm10/hackcanada architecture

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

- Interactive diagram: https://gitdiagram.com/faizm10/hackcanada
- Repository: https://github.com/faizm10/hackcanada

## Overview

##### Main Components
- Frontend UI: This is built using Next.js, Tailwind CSS, and React components. It includes pages for authentication, chat, case builder, cases dashboard, legal document generation, etc.
- Backend/API Server: A Node.js based server that handles API endpoints. Although the file tree only has a single backend file (e.g., testChatBot.js), it implies that API endpoints (for chat or legal document generation) delegate AI interactions.
- AI Integration: Incorporate the integration with Google’s Gemini API, used by the chatbot and document generator.
- Authentication Service: Firebase Authentication for secure user login/sign-up.
- Database: Supabase serves as the storage backend for tenant cases, chat history, and other essential data.
- External Integrations: Link to Firebase for auth and possibly Firestore (as mentioned in the README for storing chat history) as well as Supabase for case data storage.

##### Out Interactions and Relationships
- The User starts at the Frontend UI where they log in (Firebase Auth is used behind the scenes) and access the dashboard.
- Once logged in, users interact with various pages:
– The Chatbot page will send user legal questions to an API endpoint (within the Next.js app, under the “/api/chat” route). That API then interacts with the Google Gemini API to fetch province-specific legal advice.
– The Case Builder and Dispute Tracker pages allow the user to document disputes (including evidence upload) and monitor their progress. This data is then stored in the Supabase database.
– The Legal Document Generator page uses AI to auto-fill legal language for documents which are generated and can be previewed/downloaded as PDFs.
- The Backend API (or functions within the Next.js application) acts as an intermediary that manages and secures the data flow between the frontend, AI service, and databases.
- Additional integrations such as Firebase, Supabase, and potentially Firestore (for chat history) are connected to ensure proper authentication and data availability.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly separate the frontend client (UI, pages, and React components) from backend API logic and external services.
- API-Driven Design: The Next.js app contains several API routes (like /api/chat and /api/legal-document) that act as middle layers for external integrations.
- External Service Integration: Clearly mark Firebase for authentication, Supabase for your database, and Google Gemini for AI-powered functions.

##### Relevant Technologies and Frameworks
- Tailwind CSS for styling.
- Node.js backend components, even if minimal.
- Denote Firebase Auth for login mechanisms.
- Specify Supabase (and potentially Firestore if applicable) for the database tier.
- Google Gemini API as the AI service that powers legal advice and document generation.

##### Essential Elements
- Each component should have a clear, descriptive label (e.g., “User Interface (Next.js)”, “Chat API Endpoint”, “AI Integration (Google Gemini)”, “Authentication (Firebase)”, “Database (Supabase)”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    User["User"]:::user

    %% Frontend Group
    subgraph "Frontend (Next.js & Tailwind)"
        FE_UI["User Interface (Next.js)"]:::frontend
        Auth["Authentication Module"]:::frontend
        FirebaseHook["Firebase Auth Hook"]:::frontend
        Chat_Page["Chatbot Page"]:::frontend
        Chat_API["Chat API Endpoint"]:::frontend
        Legal_Doc_Page["Legal Document Page"]:::frontend
        Legal_Doc_API["Legal Document API Endpoint"]:::frontend
        Case_Builder["Case Builder"]:::frontend
        Cases_Dashboard["Cases Dashboard"]:::frontend
    end

    %% Backend and External Services
    Backend["Backend/API Server"]:::backend
    AI["AI Integration (Google Gemini API)"]:::external
    Firebase["Firebase Auth Service"]:::external
    DB["Database (Supabase)"]:::external

    %% User to Frontend
    User -->|"accesses"| FE_UI

    %% Frontend Internal Components
    FE_UI -->|"includes"| Auth
    FE_UI -->|"provides"| Chat_Page
    FE_UI -->|"provides"| Legal_Doc_Page
    FE_UI -->|"features"| Case_Builder
    FE_UI -->|"features"| Cases_Dashboard

    %% Authentication Flow
    Auth -->|"utilizes"| FirebaseHook
    Auth -->|"authenticates-via"| Firebase

    %% Chat Functionality Flow
    Chat_Page -->|"sends query to"| Chat_API
    Chat_API -->|"forwards request to"| Backend
    Backend -->|"processes using"| AI

    %% Legal Document Generation Flow
    Legal_Doc_Page -->|"sends request to"| Legal_Doc_API
    Legal_Doc_API -->|"calls"| AI

    %% Case & Dashboard Data Flow
    Case_Builder -->|"stores data in"| DB
    Cases_Dashboard -->|"retrieves data from"| DB

    %% Click Events (paths from component mapping)
    click FE_UI "https://github.com/faizm10/hackcanada/tree/main/frontend/app"
    click Auth "https://github.com/faizm10/hackcanada/tree/main/frontend/app/auth"
    click FirebaseHook "https://github.com/faizm10/hackcanada/blob/main/frontend/hooks/useFirebaseAuth.js"
    click Chat_API "https://github.com/faizm10/hackcanada/tree/main/frontend/app/api/chat"
    click Chat_Page "https://github.com/faizm10/hackcanada/blob/main/frontend/app/chatbot/page.tsx"
    click Legal_Doc_API "https://github.com/faizm10/hackcanada/blob/main/frontend/app/api/legal-document/route.ts"
    click Legal_Doc_Page "https://github.com/faizm10/hackcanada/tree/main/frontend/app/legal-document"
    click Case_Builder "https://github.com/faizm10/hackcanada/tree/main/frontend/app/case-builder"
    click Cases_Dashboard "https://github.com/faizm10/hackcanada/tree/main/frontend/app/cases"
    click Backend "https://github.com/faizm10/hackcanada/blob/main/backend/testChatBot.js"
    click AI "https://github.com/faizm10/hackcanada/blob/main/frontend/app/api/chat/fetchGoogleGermini.js"
    click DB "https://github.com/faizm10/hackcanada/blob/main/frontend/lib/supabaseClient.ts"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef backend fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef external fill:#FFECB3,stroke:#F9A825,stroke-width:2px;
    classDef user fill:#E1BEE7,stroke:#6A1B9A,stroke-width:2px;
```
