# anmol6213/lawsageapp architecture

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

- Interactive diagram: https://gitdiagram.com/anmol6213/lawsageapp
- Repository: https://github.com/anmol6213/lawsageapp

## Overview

##### Project Type and Purpose
- Project Type: It is a mobile (React Native/Expo) application with a focus on legal advisory and chat interactions powered by fine-tuned language models.
- Purpose: LawSageApp provides legal advice by interfacing with LLM-powered services and Retrieval-Augmented Generation (RAG) techniques using legal texts like the Indian Constitution, laws, and legal forum threads. It includes user authentication, chat views, and profile/home screens.

##### File Structure for Architectural Insights
- Top-Level Files & Configuration:
- Files such as App.js, app.json, babel.config.js, package.json indicate this is a mobile app (using Expo/React Native).
- The assets directory holds fonts and images for UI.
- Feature-based Directory Organization:
- The src folder is organized into features like Authentication, Chat, Home, MenuOptions, Profile.
- Each feature has its own subfolders for components and screens, following a component-driven design.
- Navigation and Infrastructure:
- There is a dedicated directory for navigation (AppStack.jsx, AuthStack.jsx, BottomTabNavigation.jsx) which suggests the use of stack and tab navigation patterns.
- A theme directory exists that shows centralized styling.
- Contexts and Services:
- The src/context folder holds the AuthContext for global state management.
- In services, several scripts (LLMResponseService.js, RAGResponseService.js, checkupLLMService.js) handle the integration with backend services powering the LLM functionalities.
- Utility and Environment:
- Utility files provide helper functions.
- The env folder suggests points for external configuration (like Hosts.js).

##### Main Components
a. Frontend Layers:
- Presentation/UI Components:
- Core UI components under src/components (e.g., CustomModal, LinkButton, etc.)
- Feature-specific components and screens under src/features (Authentication, Chat, Home, Profile, etc.)
- Navigation:
- AppStack, AuthStack, and BottomTabNavigation indicate how different screens are navigated.
- Theme & Styling:
- Centralized theming under src/infrastructure/theme and styling under individual component folders.
b. Context and State Management:
- AuthContext for managing user authentication state across the app.
c. Service Integration:
- Services that call out to backend endpoints for LLM responses (LLMResponseService, RAGResponseSevice, checkupLLMService).
d. External Environment Configurations:
- Environment variables or host configurations under src/env.

##### Relationships and Interactions
- User flows start with the authentication screens (LoginScreen, RegisterScreen) using AuthContext.
- Once authenticated, navigation flows through the BottomTabNavigation separating Home, Chat, Profile, and Menu options.
- UI components and screens communicate with the state/context layer as well as directly call services and utilities for processing data (such as formatting chat data to HTML).
- The theming infrastructure and styling files influence overall UI/UX consistently across components.

##### Architectural Patterns and Design Principles
- Modular & Feature-based Structure: Each feature is encapsulated in its directory, promoting separation of concerns.
- Component-driven UI: Reusable components for common UI elements.
- Declarative Navigation: Use of tailored navigation stacks (auth, main app) for clear separation of flows.
- Service Abstraction: Distinct service modules handle backend interactions, encapsulating complexity.
- Context API for Global State Management: A centralized AuthContext provides state throughout the app.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface Layer"
        %% Authentication Feature
        subgraph "Authentication Feature"
            A1("LoginScreen"):::auth
            A2("RegisterScreen"):::auth
            A3("Auth Components"):::auth
        end
        %% Chat Feature
        subgraph "Chat Feature"
            C1("ChatScreen"):::chat
            C2("Chat Components"):::chat
        end
        %% Home Feature
        subgraph "Home Feature"
            H1("HomeScreen"):::home
        end
        %% Profile Feature
        subgraph "Profile Feature"
            P1("ProfileScreen"):::profile
        end
        %% Menu Options Feature
        subgraph "Menu Options Feature"
            M1("SavedSession"):::menu
        end
        %% Reusable UI Components
        RUI("Shared UI Components"):::shared
    end

    subgraph "Navigation & Routing"
        N1("AuthStack"):::nav
        N2("AppStack"):::nav
        N3("BottomTabNavigation"):::nav
    end

    subgraph "Global State Management"
        G1("AuthContext"):::state
    end

    subgraph "Services/Backend Integration"
        S1("LLMResponseService"):::service
        S2("RAGResponseService"):::service
        S3("checkupLLMService"):::service
    end

    subgraph "Infrastructure"
        I1("Theme"):::infra
        I2("Environment"):::infra
    end

    %% Connections between Authentication and Global State
    A1 -->|"uses"| G1
    A2 -->|"uses"| G1

    %% Navigation flows
    N1 -->|"loginFlow"| A1
    N1 -->|"registerFlow"| A2
    G1 -->|"controlsRouting"| N3
    N3 -->|"navigatesTo"| H1
    N3 -->|"navigatesTo"| P1
    N3 -->|"navigatesTo"| C1
    N3 -->|"navigatesTo"| M1

    %% Chat feature calling services
    C1 -->|"calls"| S1
    C1 -->|"calls"| S2
    C1 -->|"calls"| S3

    %% Infrastructure applied across UI Layer
    I1 -->|"theming"| A1
    I1 -->|"theming"| C1
    I1 -->|"theming"| H1
    I1 -->|"theming"| P1
    I1 -->|"theming"| M1

    I2 -->|"envConfig"| A1
    I2 -->|"envConfig"| C1
    I2 -->|"envConfig"| H1
    I2 -->|"envConfig"| P1
    I2 -->|"envConfig"| M1

    %% Shared UI components support
    RUI -->|"reusableUI"| A1
    RUI -->|"reusableUI"| C1
    RUI -->|"reusableUI"| H1
    RUI -->|"reusableUI"| P1
    RUI -->|"reusableUI"| M1

    %% Click Events
    click A1 "https://github.com/anmol6213/lawsageapp/blob/master/src/features/Authentication/screens/LoginScreen.jsx"
    click A2 "https://github.com/anmol6213/lawsageapp/blob/master/src/features/Authentication/screens/RegisterScreen.jsx"
    click A3 "https://github.com/anmol6213/lawsageapp/tree/master/src/features/Authentication/components"
    click C1 "https://github.com/anmol6213/lawsageapp/blob/master/src/features/Chat/screens/ChatScreen.jsx"
    click C2 "https://github.com/anmol6213/lawsageapp/tree/master/src/features/Chat/components"
    click H1 "https://github.com/anmol6213/lawsageapp/blob/master/src/features/Home/screens/HomeScreen.jsx"
    click P1 "https://github.com/anmol6213/lawsageapp/blob/master/src/features/Profile/screens/ProfileScreen.jsx"
    click M1 "https://github.com/anmol6213/lawsageapp/blob/master/src/features/MenuOptions/screens/SavedSession.jsx"
    click N1 "https://github.com/anmol6213/lawsageapp/blob/master/src/infrastructure/navigation/AuthStack.jsx"
    click N2 "https://github.com/anmol6213/lawsageapp/blob/master/src/infrastructure/navigation/AppStack.jsx"
    click N3 "https://github.com/anmol6213/lawsageapp/blob/master/src/infrastructure/navigation/BottomTabNavigation.jsx"
    click G1 "https://github.com/anmol6213/lawsageapp/blob/master/src/context/AuthContext.js"
    click S1 "https://github.com/anmol6213/lawsageapp/blob/master/src/services/LLMResponseService.js"
    click S2 "https://github.com/anmol6213/lawsageapp/blob/master/src/services/RAGResponseSevice.js"
    click S3 "https://github.com/anmol6213/lawsageapp/blob/master/src/services/checkupLLMService.js"
    click I1 "https://github.com/anmol6213/lawsageapp/tree/master/src/infrastructure/theme"
    click I2 "https://github.com/anmol6213/lawsageapp/blob/master/src/env/Hosts.js"
    click RUI "https://github.com/anmol6213/lawsageapp/tree/master/src/components"

    %% Styles
    classDef auth fill:#ADD8E6,stroke:#000,stroke-width:2px
    classDef chat fill:#AFEEEE,stroke:#000,stroke-width:2px
    classDef home fill:#98FB98,stroke:#000,stroke-width:2px
    classDef profile fill:#F5DEB3,stroke:#000,stroke-width:2px
    classDef menu fill:#FFE4B5,stroke:#000,stroke-width:2px
    classDef shared fill:#90EE90,stroke:#000,stroke-width:2px
    classDef nav fill:#FFD700,stroke:#000,stroke-width:2px
    classDef state fill:#FFB6C1,stroke:#000,stroke-width:2px
    classDef service fill:#FFA07A,stroke:#000,stroke-width:2px
    classDef infra fill:#DDA0DD,stroke:#000,stroke-width:2px
```
