# sujal1123/civic-mangement architecture

> Architecture diagram of the GitHub repository sujal1123/civic-mangement, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sujal1123/civic-mangement
- Repository: https://github.com/sujal1123/civic-mangement

## Overview

#### Purpose and Topology
CivicSync is a mobile civic-reporting system: an Expo/React Native client submits, browses, edits, and tracks reports through a Node.js API. The repository has two deployable boundaries: `mobile-app/` for Android/mobile UI and `server/` for HTTP API, persistence, media storage, analytics, and notifications.

#### Mobile Entry and Navigation
Expo Router file-based routing is rooted at `mobile-app/app/_layout.tsx`; native Android boots the React Native host through `mobile-app/android/app/src/main/java/com/anonymous/CivicSync/MainActivity.kt` and `MainApplication.kt`. Route groups separate public onboarding, authentication, and authenticated tab navigation:
- `mobile-app/app/(public)/index.tsx`
- `mobile-app/app/(auth)/login.tsx`
- `mobile-app/app/(tabs)/_layout.tsx`

Individual report detail is parameterized by `mobile-app/app/posts/[id].tsx`.

#### Client State, Session, and Server Selection
Client-wide providers manage language, visual theme, and configurable API-server location, principally:
- `mobile-app/context/ServerConfigContext.tsx`
- `mobile-app/context/ThemeContext.tsx`
- `mobile-app/context/LanguageContext.tsx`

Authentication and local identity persistence are encapsulated in `mobile-app/hooks/useAuth.tsx` and `mobile-app/lib/storage/userStorage.ts`. Server address persistence in `mobile-app/lib/storage/serverStorage.ts` is an important environment boundary, allowing the app to target a selected backend rather than a compile-time endpoint.

#### Reporting Workflow
The main product flow is report creation and management: tab routes render report UI, form hooks manage input/submission, and media/location components collect report evidence and geography. Key stages are:
- Create report: `mobile-app/app/(tabs)/create/index.tsx`, `mobile-app/hooks/useCreateReportForm.ts`
- Browse/refresh reports: `mobile-app/app/(tabs)/home/index.tsx`, `mobile-app/hooks/useReports.ts`
- Render/edit/details: `mobile-app/components/reports/ReportForm.tsx`, `mobile-app/components/reports/EditPostModal.tsx`, `mobile-app/components/reports/PostDetails.tsx`
- Map/location selection: `mobile-app/components/maps/MapView.tsx`, `mobile-app/components/common/LocationPicker.tsx`

#### Client API Boundary
All mobile-to-server communication should pass through the API layer: `mobile-app/lib/api/apiClient.ts`, with domain services in `mobile-app/lib/api/reportService.ts` and `userService.ts`. This isolates route/auth/header/error behavior from screens and hooks. Report hooks and forms consume this boundary; they should not directly own transport or backend URL construction.

#### Server HTTP Pipeline
The backend starts from `server/src/server.js`, builds the Express application in `server/src/app.js`, and exposes separate authentication, report, and user route domains:
- `server/src/routes/authRoutes.js`
- `server/src/routes/reportRoutes.js`
- `server/src/routes/userRoutes.js`

Requests flow route → authorization/upload middleware → controller → model/services → standardized response/error handling. Core enforcement boundaries are `server/src/middlewares/authMiddleware.js`, `roleMiddleware.js`, `uploadMiddleware.js`, and `errorHandler.js`.

#### Domain, Persistence, and External Services
Mongoose-style domain models define users, departments, and civic reports in `server/src/models/User.js`, `Report.js`, and `Department.js`; database configuration is centralized in `server/src/config/db.js`. Report controllers coordinate API behavior in `server/src/controllers/reportController.js`. Media passes through upload middleware and storage abstractions (`server/src/services/storageService.js`, `server/src/config/cloudStorage.js`), separating cloud-provider handling from report logic. Notification and analytics side effects are isolated in `server/src/services/notificationService.js` and `analyticsService.js`.

#### Material Runtime and Infrastructure
The client is TypeScript React Native/Expo with Android Gradle packaging configured under `mobile-app/android/` and Expo configuration at `mobile-app/app.config.js`. The API is Node.js/Express, configured from `server/src/config/index.js` and environment values in `server/src/.env`; it depends on a database plus cloud media storage, with notification and analytics integrations represented as service boundaries.

Main entry points: [`server/src/controllers/reportController.js`](https://github.com/sujal1123/civic-mangement/blob/main/server/src/controllers/reportController.js) (Report controller), [`mobile-app/lib/api/apiClient.ts`](https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/lib/api/apiClient.ts) (API client), [`mobile-app/app/(tabs)/create/index.tsx`](https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/app/(tabs)/create/index.tsx) (Report screens), [`server/src/routes/reportRoutes.js`](https://github.com/sujal1123/civic-mangement/blob/main/server/src/routes/reportRoutes.js) (Route domains)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Mobile app"]
  node_mobile_router["Expo Router<br/>routing<br/>[_layout.tsx]"]
  node_mobile_tabs["Authenticated tabs<br/>navigation<br/>[_layout.tsx]"]
  node_mobile_auth["Login route<br/>screen<br/>[login.tsx]"]
  node_mobile_session["Auth session<br/>hook<br/>[useAuth.tsx]"]
  node_mobile_providers["App providers<br/>state"]
  node_mobile_server_storage[("Server preference<br/>local storage<br/>[serverStorage.ts]")]
  node_mobile_reports["Report screens<br/>[index.tsx]"]
  node_mobile_report_form["Report form hook"]
  node_mobile_evidence["Location and map<br/>UI component<br/>[MapView.tsx]"]
  node_mobile_api{{"API client<br/>transport boundary<br/>[apiClient.ts]"}}
  node_mobile_report_api["Report service<br/>domain service<br/>[reportService.ts]"]
end

subgraph group_server["API server"]
  node_server_boot["Server bootstrap<br/>runtime entry<br/>[server.js]"]
  node_server_app["Express app<br/>HTTP composition<br/>[app.js]"]
  node_server_routes["Route domains<br/>routes<br/>[reportRoutes.js]"]
  node_server_middleware["Auth, role, and upload middleware<br/>[authMiddleware.js]"]
  node_server_reports["Report controller"]
  node_server_models["Civic domain models<br/>[Report.js]"]
  node_server_error["Error handler<br/>middleware<br/>[errorHandler.js]"]
  node_server_storage{{"Media storage service<br/>[storageService.js]"}}
  node_server_side_effects["Notifications and analytics<br/>services"]
end

subgraph group_external["External infrastructure"]
  node_database[("Database<br/>persistence")]
  node_cloud_media[("Cloud media storage<br/>external storage")]
end

node_mobile_router -->|"routes to"| node_mobile_auth
node_mobile_router -->|"routes to"| node_mobile_tabs
node_mobile_tabs -->|"renders"| node_mobile_reports
node_mobile_auth -->|"authenticates through"| node_mobile_session
node_mobile_providers -->|"persists selection in"| node_mobile_server_storage
node_mobile_reports -->|"uses"| node_mobile_report_form
node_mobile_reports -->|"collects location with"| node_mobile_evidence
node_mobile_report_form -->|"submits through"| node_mobile_report_api
node_mobile_report_api -->|"uses"| node_mobile_api
node_mobile_session -->|"supplies session"| node_mobile_api
node_mobile_providers -->|"supplies server address"| node_mobile_api
node_mobile_api -->|"HTTP requests"| node_server_app
node_server_boot -->|"starts"| node_server_app
node_server_app -->|"mounts"| node_server_routes
node_server_routes -->|"applies"| node_server_middleware
node_server_middleware -->|"authorizes and forwards"| node_server_reports
node_server_routes -.->|"errors handled by"| node_server_error
node_server_reports -->|"reads and writes"| node_server_models
node_server_models -->|"persists to"| node_database
node_server_reports -->|"stores media through"| node_server_storage
node_server_storage -->|"uploads to"| node_cloud_media
node_server_reports -.->|"emits events to"| node_server_side_effects

click node_mobile_router "https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/app/_layout.tsx"
click node_mobile_tabs "https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/app/(tabs)/_layout.tsx"
click node_mobile_auth "https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/app/(auth)/login.tsx"
click node_mobile_session "https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/hooks/useAuth.tsx"
click node_mobile_providers "https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/context/ServerConfigContext.tsx"
click node_mobile_server_storage "https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/lib/storage/serverStorage.ts"
click node_mobile_reports "https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/app/(tabs)/create/index.tsx"
click node_mobile_report_form "https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/hooks/useCreateReportForm.ts"
click node_mobile_evidence "https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/components/maps/MapView.tsx"
click node_mobile_api "https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/lib/api/apiClient.ts"
click node_mobile_report_api "https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/lib/api/reportService.ts"
click node_server_boot "https://github.com/sujal1123/civic-mangement/blob/main/server/src/server.js"
click node_server_app "https://github.com/sujal1123/civic-mangement/blob/main/server/src/app.js"
click node_server_routes "https://github.com/sujal1123/civic-mangement/blob/main/server/src/routes/reportRoutes.js"
click node_server_middleware "https://github.com/sujal1123/civic-mangement/blob/main/server/src/middlewares/authMiddleware.js"
click node_server_reports "https://github.com/sujal1123/civic-mangement/blob/main/server/src/controllers/reportController.js"
click node_server_models "https://github.com/sujal1123/civic-mangement/blob/main/server/src/models/Report.js"
click node_server_error "https://github.com/sujal1123/civic-mangement/blob/main/server/src/middlewares/errorHandler.js"
click node_server_storage "https://github.com/sujal1123/civic-mangement/blob/main/server/src/services/storageService.js"
click node_server_side_effects "https://github.com/sujal1123/civic-mangement/blob/main/server/src/services/notificationService.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_mobile_router,node_mobile_tabs,node_mobile_auth,node_mobile_session,node_mobile_providers,node_mobile_server_storage,node_mobile_reports,node_mobile_report_form,node_mobile_evidence,node_mobile_api,node_mobile_report_api toneBlue
class node_server_boot,node_server_app,node_server_routes,node_server_middleware,node_server_reports,node_server_models,node_server_error,node_server_storage,node_server_side_effects toneAmber
class node_database,node_cloud_media toneMint
```

## Components

### Mobile app

Expo/React Native client.

- [Expo Router](https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/app/_layout.tsx): routing · File-based mobile route root. · `mobile-app/app/_layout.tsx`
- [Authenticated tabs](https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/app/(tabs)/_layout.tsx): navigation · Primary signed-in navigation. · `mobile-app/app/(tabs)/_layout.tsx`
- [Login route](https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/app/(auth)/login.tsx): screen · `mobile-app/app/(auth)/login.tsx`
- [Auth session](https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/hooks/useAuth.tsx): hook · Manages authentication and local identity. · `mobile-app/hooks/useAuth.tsx`
- [App providers](https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/context/ServerConfigContext.tsx): state · Server selection, theme, and language state. · `mobile-app/context/ServerConfigContext.tsx`
- [Server preference](https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/lib/storage/serverStorage.ts): local storage · Persists the selected API server. · `mobile-app/lib/storage/serverStorage.ts`
- [Report screens](https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/app/(tabs)/create/index.tsx): screens · Create, browse, edit, and view reports. · `mobile-app/app/(tabs)/create/index.tsx`
- [Report form hook](https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/hooks/useCreateReportForm.ts): hook · Owns report input and submission state. · `mobile-app/hooks/useCreateReportForm.ts`
- [Location and map](https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/components/maps/MapView.tsx): UI component · Collects report geography. · `mobile-app/components/maps/MapView.tsx`
- [API client](https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/lib/api/apiClient.ts): transport boundary · Centralizes mobile HTTP behavior. · `mobile-app/lib/api/apiClient.ts`
- [Report service](https://github.com/sujal1123/civic-mangement/blob/main/mobile-app/lib/api/reportService.ts): domain service · `mobile-app/lib/api/reportService.ts`

### API server

Node.js/Express backend.

- [Server bootstrap](https://github.com/sujal1123/civic-mangement/blob/main/server/src/server.js): runtime entry · `server/src/server.js`
- [Express app](https://github.com/sujal1123/civic-mangement/blob/main/server/src/app.js): HTTP composition · `server/src/app.js`
- [Route domains](https://github.com/sujal1123/civic-mangement/blob/main/server/src/routes/reportRoutes.js): routes · Authentication, report, and user endpoints. · `server/src/routes/reportRoutes.js`
- [Auth, role, and upload middleware](https://github.com/sujal1123/civic-mangement/blob/main/server/src/middlewares/authMiddleware.js): middleware · Enforces access and handles uploaded media. · `server/src/middlewares/authMiddleware.js`
- [Report controller](https://github.com/sujal1123/civic-mangement/blob/main/server/src/controllers/reportController.js): controller · Coordinates report API behavior. · `server/src/controllers/reportController.js`
- [Civic domain models](https://github.com/sujal1123/civic-mangement/blob/main/server/src/models/Report.js): models · Users, departments, and reports. · `server/src/models/Report.js`
- [Error handler](https://github.com/sujal1123/civic-mangement/blob/main/server/src/middlewares/errorHandler.js): middleware · Standardizes API failures. · `server/src/middlewares/errorHandler.js`
- [Media storage service](https://github.com/sujal1123/civic-mangement/blob/main/server/src/services/storageService.js): service · Abstracts cloud media operations. · `server/src/services/storageService.js`
- [Notifications and analytics](https://github.com/sujal1123/civic-mangement/blob/main/server/src/services/notificationService.js): services · Report side-effect integrations. · `server/src/services/notificationService.js`

### External infrastructure

- **Database**: persistence · Configured through the server database layer.
- **Cloud media storage**: external storage

## Connections

- Expo Router → Login route: routes to
- Expo Router → Authenticated tabs: routes to
- Authenticated tabs → Report screens: renders
- Login route → Auth session: authenticates through
- App providers → Server preference: persists selection in
- Report screens → Report form hook: uses
- Report screens → Location and map: collects location with
- Report form hook → Report service: submits through
- Report service → API client: uses
- Auth session → API client: supplies session
- App providers → API client: supplies server address
- API client → Express app: HTTP requests
- Server bootstrap → Express app: starts
- Express app → Route domains: mounts
- Route domains → Auth, role, and upload middleware: applies
- Auth, role, and upload middleware → Report controller: authorizes and forwards
- Route domains → Error handler: errors handled by
- Report controller → Civic domain models: reads and writes
- Civic domain models → Database: persists to
- Report controller → Media storage service: stores media through
- Media storage service → Cloud media storage: uploads to
- Report controller → Notifications and analytics: emits events to
