# sumamakhan761/crime-report architecture

> Architecture diagram of the GitHub repository sumamakhan761/crime-report, 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/sumamakhan761/crime-report
- Repository: https://github.com/sumamakhan761/crime-report

## Overview

##### Project Type & Purpose
- SafeReport is a full-stack web application for anonymously reporting crimes and incidents. It provides secure reporting, AI-powered incident detection using Gemini, map/user location tracking via Mapbox, and a secure admin dashboard for emergency personnel.
- The purpose is to ensure privacy and expedite emergency responses with a robust reporting/tracking system.

##### Analyzing the File Structure
- The top-level directories include:
– “app”: Contains pages, layouts, and API routes using Next.js conventions.
– “app/api”: Contains subdirectories for different API endpoints (analyze-image, auth, reports) with a route.ts reactivity indicating serverless API endpoints.
– “components”: Holds reusable UI components such as Navbar, MobileMenu, and various report components (wizard, file uploader, location input).
– “lib”: Contains utility modules including authentication logic (auth.ts), Prisma client (prisma.ts), and custom TypeScript types.
– “prisma”: Contains the database schema and migrations, indicating usage of PostgreSQL with Prisma ORM.
- Configuration files (next.config.mjs, tsconfig.json, tailwind.config.ts) indicate the project uses modern JavaScript tooling and styling frameworks.

##### Key Architectural Components
a. Frontend:
– Built with Next.js and TypeScript.
– Pages include user authentication (/app/auth), dashboard (/app/dashboard), reporting (submit-report, track-report), and general pages (how-it-works, homepage).
– Presentational components are structured under /components (Navbar, MobileMenu) and specialized report components (ReportForm, ReportStatus, ReportWizard).
– Global styles with Tailwind CSS support consistent and modern look & feel.

b. Backend / API Endpoints:
– Organized in /app/api with endpoints for:
- AI-based image analysis (app/api/analyze-image): Integrates Gemini AI.
- Authentication (app/api/auth): Uses NextAuth for login/sign-up.
- Report management (app/api/reports): Endpoints for creating, retrieving, and updating reports.
– The API endpoints follow Next.js’s file-based routing, enabling serverless functions.

c. Database & ORM:
– Using Prisma ORM with a PostgreSQL database (configured in the prisma folder). Database is the persistence layer for user data, reports, and possibly audit logs.

d. External Services:
– Gemini AI for analyzing images and generating report insights.
– Mapbox for location tracking and map integration.
– Likely integration with Clerk (as seen in the tech stack README) for authentication and potentially role-based access control (RBAC).

##### Relationships & Interactions
- Users interact with the Frontend (UI pages) which consume the API endpoints for data operations.
- The Frontend communicates with various API endpoints via HTTP calls. The APIs perform business logic and interact with the database using Prisma.
- For image analysis, the API calls out to Gemini AI services.
- Location data from users is processed, and Mapbox is used to render maps.
- Authentication endpoints manage signing in/up and RBAC, ensuring only allowed users (e.g., admin emergency personnel) can access the secure dashboard.

##### Architectural Patterns & Design Principles
- Separation of concerns: Clear delineation between presentation (React components/pages), business logic (API endpoints), and persistence (Prisma/Database).
- Next.js file-based routing is used for the organization of pages and APIs.
- Use of API routes encapsulates serverless functions that process request/response cycles.
- Modular design: Components and libraries are well separated to allow extensibility and easier maintenance.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend UI: Pages
    subgraph "Frontend UI"
        FP1["Home Page"]:::frontend
        FP2["Sign In Page"]:::frontend
        FP3["Sign Up Page"]:::frontend
        FP4["Dashboard Page"]:::frontend
        FP5["How It Works Page"]:::frontend
        FP6["Submit Report Page"]:::frontend
        FP7["Track Report Page"]:::frontend
    end

    %% UI Components
    subgraph "UI Components"
        subgraph "Global Components"
            GC1["Navbar"]:::component
            GC2["Mobile Menu"]:::component
        end
        subgraph "Report Components"
            RC1["Report Form"]:::component
            RC2["Report Wizard"]:::component
            RC3["File Uploader"]:::component
            RC4["Location Input"]:::component
            RC5["Report Form Completed"]:::component
            RC6["Report Status"]:::component
            RC7["Report Tracker"]:::component
        end
    end

    %% API Endpoints
    subgraph "API Endpoints"
        subgraph "Image Analysis"
            IA["Image Analysis API"]:::api
        end
        subgraph "Authentication"
            A1["NextAuth API"]:::api
            A2["Sign Up API"]:::api
        end
        subgraph "Report Management"
            RM1["Reports API"]:::api
            RM2["Create Report API"]:::api
            RM3["Report API"]:::api
            RM4["Report Details API"]:::api
        end
    end

    %% Database & ORM Layer
    subgraph "Database & ORM"
        DB["PostgreSQL via Prisma"]:::db
    end

    %% Utility & Configuration Modules
    subgraph "Utility & Config"
        U1["Auth Utils"]:::utils
        U2["Prisma Client"]:::utils
        U3["Type Definitions"]:::utils
        U4["Utils"]:::utils
    end

    %% External Services
    subgraph "External Services"
        ES1["Gemini AI"]:::external
        ES2["Mapbox"]:::external
        ES3["Clerk"]:::external
    end

    %% Connections from Frontend Pages to API Endpoints
    FP2 -->|"calls"| A1
    FP3 -->|"calls"| A2
    FP4 -->|"calls"| RM1
    FP6 -->|"calls"| RM2
    FP7 -->|"calls"| RM3

    %% Connections from UI Components to API Endpoints
    RC1 -->|"submits"| RM2
    RC2 -->|"guides"| RM2
    RC3 -->|"uploads to"| IA
    RC4 -->|"provides"| ES2
    RC6 -->|"updates"| RM1
    RC7 -->|"tracks"| RM1

    %% API Endpoints to Database
    A1 -->|"reads/writes"| DB
    A2 -->|"reads/writes"| DB
    RM1 -->|"reads/writes"| DB
    RM2 -->|"writes"| DB
    RM3 -->|"reads/writes"| DB
    RM4 -->|"reads"| DB

    %% API Endpoints to External Services
    IA -->|"analyzes"| ES1
    RM1 -- "location" --> ES2
    A1 -- "auth check" --> ES3
    A2 -- "auth check" --> ES3

    %% Utility Modules usage (indicative arrows)
    U1 --> A1
    U1 --> A2
    U2 --> DB
    U3 --> FP1
    U3 --> FP2
    U3 --> FP3
    U4 --> RM1

    %% Click Events for Frontend Pages
    click FP1 "https://github.com/sumamakhan761/crime-report/blob/main/app/page.tsx"
    click FP2 "https://github.com/sumamakhan761/crime-report/blob/main/app/auth/signin/page.tsx"
    click FP3 "https://github.com/sumamakhan761/crime-report/blob/main/app/auth/signup/page.tsx"
    click FP4 "https://github.com/sumamakhan761/crime-report/blob/main/app/dashboard/page.tsx"
    click FP5 "https://github.com/sumamakhan761/crime-report/blob/main/app/how-it-works/page.tsx"
    click FP6 "https://github.com/sumamakhan761/crime-report/blob/main/app/submit-report/page.tsx"
    click FP7 "https://github.com/sumamakhan761/crime-report/blob/main/app/track-report/page.tsx"

    %% Click Events for Global UI Components
    click GC1 "https://github.com/sumamakhan761/crime-report/blob/main/components/Navbar.tsx"
    click GC2 "https://github.com/sumamakhan761/crime-report/blob/main/components/MobileMenu.tsx"

    %% Click Events for Report Components
    click RC1 "https://github.com/sumamakhan761/crime-report/blob/main/components/report/ReportForm.tsx"
    click RC2 "https://github.com/sumamakhan761/crime-report/blob/main/components/report/ReportWizard.tsx"
    click RC3 "https://github.com/sumamakhan761/crime-report/blob/main/components/report/FileUploader.tsx"
    click RC4 "https://github.com/sumamakhan761/crime-report/blob/main/components/report/LocationInput.tsx"
    click RC5 "https://github.com/sumamakhan761/crime-report/blob/main/components/report/ReportFormCompleted.tsx"
    click RC6 "https://github.com/sumamakhan761/crime-report/blob/main/components/report/ReportStatus.tsx"
    click RC7 "https://github.com/sumamakhan761/crime-report/blob/main/components/report/ReportTracker.tsx"

    %% Click Events for API Endpoints
    click IA "https://github.com/sumamakhan761/crime-report/blob/main/app/api/analyze-image/route.ts"
    click A1 "https://github.com/sumamakhan761/crime-report/blob/main/app/api/auth/[...nextauth]/route.ts"
    click A2 "https://github.com/sumamakhan761/crime-report/blob/main/app/api/auth/signup/route.ts"
    click RM1 "https://github.com/sumamakhan761/crime-report/blob/main/app/api/reports/route.ts"
    click RM2 "https://github.com/sumamakhan761/crime-report/blob/main/app/api/reports/create/route.ts"
    click RM3 "https://github.com/sumamakhan761/crime-report/blob/main/app/api/reports/[reportId]/route.ts"
    click RM4 "https://github.com/sumamakhan761/crime-report/blob/main/app/api/reports/[reportId]/details/route.ts"

    %% Click Events for Database & ORM
    click DB "https://github.com/sumamakhan761/crime-report/blob/main/prisma/schema.prisma"

    %% Click Events for Utility & Config
    click U1 "https://github.com/sumamakhan761/crime-report/blob/main/lib/auth.ts"
    click U2 "https://github.com/sumamakhan761/crime-report/blob/main/lib/prisma.ts"
    click U3 "https://github.com/sumamakhan761/crime-report/blob/main/lib/types/next-auth.d.ts"
    click U4 "https://github.com/sumamakhan761/crime-report/blob/main/lib/utils.ts"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#1e88e5,stroke-width:2px;
    classDef component fill:#c8e6c9,stroke:#43a047,stroke-width:2px;
    classDef api fill:#ffcc80,stroke:#f57c00,stroke-width:2px;
    classDef db fill:#ffe082,stroke:#f9a825,stroke-width:2px;
    classDef external fill:#ffcdd2,stroke:#e53935,stroke-width:2px;
    classDef utils fill:#d1c4e9,stroke:#5e35b1,stroke-width:2px;
```
