# arjunhg/anonymous-guard architecture

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

- Interactive diagram: https://gitdiagram.com/arjunhg/anonymous-guard
- Repository: https://github.com/arjunhg/anonymous-guard

## Overview

##### Project type and purpose
- This is a full-stack web application built with Next.js 14 (App Router) and TypeScript.
- Purpose: AnonGuard is an anonymous crime reporting platform with AI-powered image/incident analysis, a user-facing reporting UI, and an admin dashboard for authorities.

##### File structure
- Top-level “app” directory holds both UI pages and backend API routes under app/api.
- UI routes: page.tsx in app/, app/auth, app/submit-report, app/track-report, app/dashboard.
- API routes: app/api/analyze-image, app/api/reports, app/api/auth, etc.
- “components” holds reusable React components (Navbar, ReportForm, ReportWizard, ReportTracker).
- “lib” contains shared utilities: auth wrappers, Prisma client, helper functions.
- Prisma folder holds database schema and migration files.
- Config files: next.config.mjs, tsconfig.json, tailwind.config.ts, postcss.config.mjs.
- Middleware.ts applies global logic (e.g., auth, redirect).

##### README for additional insights
- Tech stack: Next.js, TypeScript, Prisma ORM, PostgreSQL (Neon), Google Gemini API, NextAuth.js, Framer Motion, Tailwind CSS, Vercel for hosting.
- Features: anonymous reporting, AI analysis, geolocation, emergency categories, admin dashboard, report tracking.

##### Main components & interactions
a. Components
- Client Browser (React UI via Next.js pages/components)
- Next.js Server (SSR/SSG, App Router handling UI requests)
- API Layer (Next.js serverless functions under app/api)
– Auth service (NextAuth.js)
– Report service (CRUD for reports via Prisma)
– Image analysis service (calls Google Gemini API)
- Database (PostgreSQL via Prisma ORM)
- External AI API (Google Gemini)
- Deployment Platform (Vercel)
b. Relationships and data flow
- Browser ⇄ Next.js Server: page requests, SSR/SSG, client-side navigation
- Browser → API Layer: POST/GET for report submission, tracking, auth
- API Layer → Database: Prisma client queries for storing/fetching reports, users
- API Layer → Google Gemini: image/incident analysis calls
- NextAuth (under API Layer) → Database: user/session storage
c. Architectural patterns & design principles
- Separation of concerns: UI components vs. API routes
- Serverless microservices style (each route directory is a discrete function)
- ORM abstraction (Prisma) for database operations
- Environment-driven configuration for secrets and URLs
d. Key technologies
- Next.js App Router + Server Components
- React + TypeScript + Tailwind CSS + Framer Motion for UI
- NextAuth.js for authentication
- Prisma + PostgreSQL for persistence
- Google Gemini API for AI analysis
- Vercel as host and function runner

##### Detailed capture of essential elements
- Don’t just group “Backend” – break out auth, reports, analysis.
- Explicitly call out Prisma as the ORM layer between API and DB.
- Environment variables for secrets and URLs (e.g., NEXTAUTH_URL, GEMINI_API_KEY).
- If desired, annotate deployment boundaries: “Serverless on Vercel” vs. “Client in Browser”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Browser)" 
        direction TB
        Page["app/page.tsx"]:::ui
        Layout["app/layout.tsx"]:::ui
        Globals["app/globals.css"]:::ui
        Providers["app/providers.tsx"]:::ui
        Navbar["Navbar"]:::ui
        SignIn["app/auth/signin/page.tsx"]:::ui
        SignUp["app/auth/signup/page.tsx"]:::ui
        SubmitReportPage["app/submit-report/page.tsx"]:::ui
        ReportForm["components/report/ReportForm.tsx"]:::ui
        ReportWizard["components/report/ReportWizard.tsx"]:::ui
        ReportFormCompleted["components/report/ReportFormCompleted.tsx"]:::ui
        TrackReportPage["app/track-report/page.tsx"]:::ui
        ReportTracker["components/report/ReportTracker.tsx"]:::ui
        Dashboard["app/dashboard/page.tsx"]:::ui
    end

    %% Backend Layer
    subgraph "Backend (Vercel Serverless)" 
        direction TB
        NextServer["Next.js Server (App Router)"]:::server
        AuthAPI["Auth API"]:::server
        SignUpAPI["app/api/auth/signup/route.ts"]:::server
        NextAuthAPI["app/api/auth/[...nextauth]/route.ts"]:::server
        ReportAPI["Report API"]:::server
        ReportsRoot["app/api/reports/route.ts"]:::server
        ReportsCreate["app/api/reports/create/route.ts"]:::server
        ReportId["app/api/reports/[reportId]/route.ts"]:::server
        ReportDetails["app/api/reports/[reportId]/details/route.ts"]:::server
        AnalysisAPI["app/api/analyze-image/route.ts"]:::server
        Middleware["middleware.ts"]:::server
        AuthUtil["lib/auth.ts"]:::server
        Utils["lib/utils.ts"]:::server
    end

    %% Database Layer
    subgraph "Database" 
        direction TB
        PrismaClient["lib/prisma.ts"]:::db
        Schema["prisma/schema.prisma"]:::db
        Migrations["prisma/migrations/"]:::db
        Postgres["PostgreSQL DB"]:::db
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Gemini["Google Gemini AI"]:::external
    end

    %% Configurations
    Config["Config Files\n(next.config.mjs, tailwind.config.ts,\npostcss.config.mjs, tsconfig.json)"]:::config

    %% Connections
    Page -->|serves UI| NextServer
    Layout --> NextServer
    Providers --> NextServer
    Navbar --> NextServer
    NextServer -->|SSR/SSG| Page
    NextServer -->|SSR/SSG| SubmitReportPage
    NextServer -->|SSR/SSG| TrackReportPage
    NextServer -->|SSR/SSG| Dashboard

    Page -->|navigation| SignIn
    Page -->|navigation| SignUp

    Page -->|navigation| SubmitReportPage
    SubmitReportPage -->|uses| ReportForm
    SubmitReportPage -->|uses| ReportWizard
    SubmitReportPage -->|uses| ReportFormCompleted

    Page -->|navigation| TrackReportPage
    TrackReportPage -->|uses| ReportTracker

    Page -->|navigation| Dashboard

    %% API calls
    SignIn -->|POST signin| NextServer
    SignIn -->|calls| AuthAPI
    SignUp -->|POST signup| SignUpAPI
    AuthAPI -->|handles session| NextAuthAPI
    AuthAPI -->|uses| AuthUtil
    AuthAPI -->|CRUD session| Postgres
    AuthAPI -->|via ORM| PrismaClient

    SubmitReportPage -->|POST report| ReportsCreate
    ReportsCreate -->|writes| Postgres
    ReportsRoot -->|GET reports| ReportsRoot
    ReportId -->|GET/DELETE| Postgres
    ReportDetails -->|GET details| Postgres
    ReportAPI -->|uses| PrismaClient

    AnalysisAPI -->|analyzes| Gemini
    AnalysisAPI -->|stores results| Postgres
    AnalysisAPI -->|uses| PrismaClient

    Middleware -->|global logic| NextServer

    %% ORM connections
    PrismaClient -->|connects| Postgres
    Schema -->|defines schema| PrismaClient
    Migrations -->|run migrations| Postgres

    %% Config linking
    Config -->|env vars| AuthAPI
    Config -->|env vars| AnalysisAPI

    %% Deployment
    NextServer -->|deployed on| Vercel["Vercel"]:::external

    %% Click Events
    click Page "https://github.com/arjunhg/anonymous-guard/blob/master/app/page.tsx"
    click Layout "https://github.com/arjunhg/anonymous-guard/blob/master/app/layout.tsx"
    click Globals "https://github.com/arjunhg/anonymous-guard/blob/master/app/globals.css"
    click Providers "https://github.com/arjunhg/anonymous-guard/blob/master/app/providers.tsx"
    click SignIn "https://github.com/arjunhg/anonymous-guard/blob/master/app/auth/signin/page.tsx"
    click SignUp "https://github.com/arjunhg/anonymous-guard/blob/master/app/auth/signup/page.tsx"
    click SubmitReportPage "https://github.com/arjunhg/anonymous-guard/blob/master/app/submit-report/page.tsx"
    click ReportForm "https://github.com/arjunhg/anonymous-guard/blob/master/components/report/ReportForm.tsx"
    click ReportWizard "https://github.com/arjunhg/anonymous-guard/blob/master/components/report/ReportWizard.tsx"
    click ReportFormCompleted "https://github.com/arjunhg/anonymous-guard/blob/master/components/report/ReportFormCompleted.tsx"
    click TrackReportPage "https://github.com/arjunhg/anonymous-guard/blob/master/app/track-report/page.tsx"
    click ReportTracker "https://github.com/arjunhg/anonymous-guard/blob/master/components/report/ReportTracker.tsx"
    click Dashboard "https://github.com/arjunhg/anonymous-guard/blob/master/app/dashboard/page.tsx"
    click NextAuthAPI "https://github.com/arjunhg/anonymous-guard/blob/master/app/api/auth/[...nextauth]/route.ts"
    click SignUpAPI "https://github.com/arjunhg/anonymous-guard/blob/master/app/api/auth/signup/route.ts"
    click ReportsRoot "https://github.com/arjunhg/anonymous-guard/blob/master/app/api/reports/route.ts"
    click ReportsCreate "https://github.com/arjunhg/anonymous-guard/blob/master/app/api/reports/create/route.ts"
    click ReportId "https://github.com/arjunhg/anonymous-guard/blob/master/app/api/reports/[reportId]/route.ts"
    click ReportDetails "https://github.com/arjunhg/anonymous-guard/blob/master/app/api/reports/[reportId]/details/route.ts"
    click AnalysisAPI "https://github.com/arjunhg/anonymous-guard/blob/master/app/api/analyze-image/route.ts"
    click PrismaClient "https://github.com/arjunhg/anonymous-guard/blob/master/lib/prisma.ts"
    click Schema "https://github.com/arjunhg/anonymous-guard/blob/master/prisma/schema.prisma"
    click Migrations "https://github.com/arjunhg/anonymous-guard/tree/master/prisma/migrations/"
    click AuthUtil "https://github.com/arjunhg/anonymous-guard/blob/master/lib/auth.ts"
    click Utils "https://github.com/arjunhg/anonymous-guard/blob/master/lib/utils.ts"
    click Middleware "https://github.com/arjunhg/anonymous-guard/blob/master/middleware.ts"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef server fill:#E2F0D9,stroke:#2E7D32,color:#2E7D32;
    classDef db fill:#FFF4E5,stroke:#F57C00,color:#E65100;
    classDef external fill:#FFE5D9,stroke:#D84315,color:#BF360C;
    classDef config fill:#F3F4F6,stroke:#6B7280,color:#374151;
```
