How sumamakhan761/crime-report works
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.