# 111maaz/tg_c_lens architecture

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

- Interactive diagram: https://gitdiagram.com/111maaz/tg_c_lens
- Repository: https://github.com/111maaz/tg_c_lens

## Overview

##### Project type and purpose
- This is a full-stack, serverless-style web application called “T-G Crime Lens.”
- Purpose: Provide interactive crime analytics for the Indian state of Telangana, combining official crime statistics (from CSV/GeoJSON) with an unofficial, rate-limited citizen reporting system, all administered via Supabase.

##### File structure
- Top-level artifacts:
- public/: static assets and data (CSV, districts.json, robots.txt)
- src/: all React/TypeScript code
- supabase/: database configuration & migrations (SQL)
- telangana_boundaries-master/: geo-boundary data package
- src/ substructure indicates:
- auth/: authentication UI, context, hooks (OAuth/JWT handled by Supabase Auth)
- components/: reusable UI (maps, charts, forms, modals)
- pages/: route-level components (dashboard, admin panels, error pages)
- integrations/supabase/: client setup and types for Supabase SDK
- services/: wrappers around Supabase queries (authService, crimeDataService, etc.)
- contexts/hooks/: global state (filters, toast notifications, data fetching hooks)
- Config/build scripts:
- vite.config.ts, tsconfig*.json, tailwind.config.ts for building with Vite, TS, TailwindCSS
- postcss.config.js, eslint.config.js

##### README for additional insights
- Frontend stack: React + TypeScript + Vite, UI via shadcn/ui + TailwindCSS
- Maps: Leaflet + MapLibre
- Backend entirely handled by Supabase (PostgreSQL + PostGIS for spatial data)
- Form validation: react-hook-form + Zod
- Data fetching & caching: TanStack Query

##### Elements
- Clear labels: “React App,” “Supabase Auth,” “PostgreSQL + PostGIS,” “Leaflet Map Layer,” “Admin Panel”
- From React App to Supabase endpoints (Auth, CRUD services)
- From Supabase DB to React App (data fetching)
- Rectangles for services/components (blue for frontend, green for backend, orange for DB)
- Clouds for external services (Supabase)
- Annotations for rate-limiting logic (5 reports/hour/IP) near the Unofficial Reports service

##### Final advice
- Be thorough: show each major React context, service layer, and Supabase module.
- Don’t overcomplicate: stick to discrete components (Frontend, Auth, DB, Map service, Admin).
- Iterate: validate with stakeholders or architects to ensure all flows are covered.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client - Browser" 
        direction TB
        ReactApp["React App"]:::frontend
        subgraph "UI Layer"
            direction TB
            UIComponents["UI Components"]:::frontend
            shadcnLibrary["shadcn/ui Library"]:::frontend
        end
        subgraph "Routing & Pages"
            direction TB
            Pages["Page-Level Routes & Views"]:::frontend
        end
        subgraph "Auth & State"
            direction TB
            AuthUI["Authentication UI & Logic"]:::frontend
            FilterContext["React Contexts (FilterContext)"]:::frontend
            Hooks["Custom Hooks"]:::frontend
        end
        subgraph "Map Layer"
            direction TB
            MapRendering["Map Rendering Components"]:::frontend
        end
        subgraph "Service Layer"
            direction TB
            ServiceLayer["Service Layer (Supabase wrappers)"]:::frontend
            SupabaseClient["Supabase Client Integration"]:::frontend
        end
    end

    %% CDN / Static Hosting
    subgraph "Static Hosting / CDN"
        direction TB
        StaticData["Static Data & Assets"]:::external
        ViteConfig["Vite Configuration"]:::infra
        TsConfigs["TypeScript Configs"]:::infra
        TailwindConfig["TailwindCSS Config"]:::infra
    end

    %% Backend as a Service
    subgraph "Supabase Service" 
        direction TB
        SupabaseAuth["Supabase Auth"]:::backend
        SupabaseDBAPI["PostgreSQL + PostGIS API"]:::backend
        Storage["Supabase Storage"]:::backend
        EdgeFunctions["Edge Functions / RPC"]:::backend
        SupabaseConfig["Supabase Project Config"]:::infra
    end

    %% Database
    subgraph "Database"
        direction TB
        PostgreSQL["PostgreSQL + PostGIS"]:::db
        Migrations["Database Migrations"]:::infra
    end

    %% External Geo Package
    Boundary["Telangana Boundary Geo Package"]:::external

    %% Flows
    ReactApp -->|1: HTTP Requests| SupabaseAuth
    ReactApp -->|2: Query & Mutations| SupabaseDBAPI
    ReactApp -->|3: File Uploads| Storage
    ReactApp -->|4: Call Edge Functions| EdgeFunctions
    StaticData -->|served to| ReactApp
    ViteConfig -->|build config| ReactApp
    TsConfigs -->|type-check| ReactApp
    TailwindConfig -->|styles| ReactApp
    SupabaseConfig -->|project setup| SupabaseAuth
    SupabaseConfig -->|project setup| SupabaseDBAPI
    SupabaseDBAPI -->|stores data in| PostgreSQL
    Migrations -->|schema migrations| PostgreSQL
    Boundary -->|geo data imported| PostgreSQL

    %% Click Events
    click UIComponents "https://github.com/111maaz/tg_c_lens/tree/main/src/components"
    click MapRendering "https://github.com/111maaz/tg_c_lens/tree/main/src/components/map"
    click shadcnLibrary "https://github.com/111maaz/tg_c_lens/tree/main/src/components/ui"
    click Pages "https://github.com/111maaz/tg_c_lens/tree/main/src/pages"
    click AuthUI "https://github.com/111maaz/tg_c_lens/tree/main/src/auth"
    click FilterContext "https://github.com/111maaz/tg_c_lens/blob/main/src/contexts/FilterContext.tsx"
    click Hooks "https://github.com/111maaz/tg_c_lens/tree/main/src/hooks"
    click ServiceLayer "https://github.com/111maaz/tg_c_lens/tree/main/src/services"
    click SupabaseClient "https://github.com/111maaz/tg_c_lens/blob/main/src/integrations/supabase/client.ts"
    click SupabaseConfig "https://github.com/111maaz/tg_c_lens/blob/main/supabase/config.toml"
    click Migrations "https://github.com/111maaz/tg_c_lens/tree/main/supabase/migrations"
    click StaticData "https://github.com/111maaz/tg_c_lens/tree/main/public"
    click ViteConfig "https://github.com/111maaz/tg_c_lens/blob/main/vite.config.ts"
    click TsConfigs "https://github.com/111maaz/tg_c_lens/blob/main/tsconfig.json"
    click TailwindConfig "https://github.com/111maaz/tg_c_lens/blob/main/tailwind.config.ts"
    click Boundary "https://github.com/111maaz/tg_c_lens/tree/main/telangana_boundaries-master"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0A62A1,stroke-width:1px
    classDef backend fill:#E0FFE0,stroke:#2C862C,stroke-width:1px
    classDef db fill:#FFE8C0,stroke:#A66B00,stroke-width:1px
    classDef infra fill:#F0F0F0,stroke:#888888,stroke-width:1px
    classDef external fill:#F5E8FF,stroke:#71317B,stroke-width:1px
```
