# arn101/jonomot architecture

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

- Interactive diagram: https://gitdiagram.com/arn101/jonomot
- Repository: https://github.com/arn101/jonomot

## Overview

#### Purpose and deployment shape
Jonomot is a Bangladesh citizen-opinion and government/organization feedback portal. It is a React SPA backed by a Laravel JSON API: browser requests use Sanctum Bearer tokens, while Laravel persists domain data in MySQL (or SQLite locally) and exposes uploaded media from public storage. Main runtime entry points are `frontend/src/main.jsx`, `frontend/src/App.jsx`, `backend/public/index.php`, and `backend/routes/api.php`.

#### SPA composition and navigation
The frontend owns the product UI and calls only `/api/*` through its centralized Axios client. Route-level views cover public feed/login plus authenticated profile, polls, ministry inbox, and admin dashboard. Auth state, persisted token handling, localization, and notifications are application-wide contexts; role gates protect privileged views.
Paths: `frontend/src/api/client.js`, `frontend/src/context/AuthContext.jsx`, `frontend/src/components/RoleRoute.jsx`, `frontend/src/views/Feed.jsx`, `frontend/src/views/AdminPanel.jsx`.

#### API boundary, authentication, and hardening
Laravel routes requests to API controllers by domain. Registration/login issue Sanctum personal-access tokens; later calls use `auth:sanctum`. Custom role and NID-verification middleware enforce capability boundaries, while sanitization/security middleware and route throttles defend writes. The frontend stores the token as `jonomot_token`.
Paths: `backend/routes/api.php`, `backend/app/Http/Controllers/Api/AuthController.php`, `backend/app/Http/Middleware/RoleMiddleware.php`, `backend/app/Http/Middleware/NidVerifiedMiddleware.php`.

#### Civic reporting and ministry workflow
Posts are the central feedback artifact: citizens create categorized reports with optional images, then users can vote, save, comment, and report them. Posts can be tagged to ministries through the post–ministry relationship; ministry users consume a dedicated inbox, star posts, and post official responses. Admins review reports/flagged posts and restore moderated content.
Paths: `backend/app/Http/Controllers/Api/PostController.php`, `backend/app/Http/Controllers/Api/CommentController.php`, `backend/app/Http/Controllers/Api/AdminController.php`, `backend/app/Models/Post.php`.

#### Surveys, eligibility, and reward accounting
Organizations and admins create/manage polls with options, demographic filters, closure, analytics/results, and reward-point values. Only NID-verified citizens vote; eligibility includes normalized division and age filtering. A successful response records poll participation and credits the points ledger. Payment endpoints/views support the survey-payment surface, though polls may operate as free.
Paths: `backend/app/Http/Controllers/Api/PollController.php`, `backend/app/Models/Poll.php`, `backend/app/Models/PollResponse.php`, `backend/app/Models/PointsLedger.php`, `backend/app/Http/Controllers/Api/PaymentController.php`.

#### Identity, organizations, and verification
A shared user model represents citizens, ministries, companies, and admins. Ministry/company detail models hold organization profiles and approval state; admins approve pending organizations. Citizen NID verification is a local mock service, but gates civic publishing and poll voting, making it a replaceable external-integration boundary.
Paths: `backend/app/Models/User.php`, `backend/app/Models/MinistryDetail.php`, `backend/app/Models/CompanyDetail.php`, `backend/app/Services/NidVerificationService.php`.

#### Persistence, media, and infrastructure
Laravel migrations define users, organization profiles, posts/interactions, polls/responses, ledger, cache/jobs, and Sanctum tokens. MySQL 8 is the intended production database; Laravel supports database-backed cache/session/queue settings. Post images and avatars use Laravel’s public disk and require the `storage:link` symlink. Vite serves/builds the React application.
Paths: `backend/database/migrations/2026_07_10_173139_create_profiles_tables.php`, `backend/database/migrations/2026_07_10_173140_create_posts_and_interactions_tables.php`, `backend/database/migrations/2026_07_10_173140_create_polls_and_ledgers_tables.php`, `backend/storage/app/public`.

Main entry points: [`backend/app/Http/Middleware/RoleMiddleware.php`](https://github.com/arn101/jonomot/blob/main/backend/app/Http/Middleware/RoleMiddleware.php) (Access gates), [`backend/app/Models/User.php`](https://github.com/arn101/jonomot/blob/main/backend/app/Models/User.php) (Users & organizations), [`backend/app/Models/Post.php`](https://github.com/arn101/jonomot/blob/main/backend/app/Models/Post.php) (Posts & interactions), [`frontend/src/main.jsx`](https://github.com/arn101/jonomot/blob/main/frontend/src/main.jsx) (SPA entry & routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React SPA"]
  node_spa_entry["SPA entry &amp; routes<br/>React application<br/>[main.jsx]"]
  node_api_client["Central API client<br/>Axios client<br/>[client.js]"]
  node_auth_context["Auth &amp; app state<br/>React contexts<br/>[AuthContext.jsx]"]
  node_role_route["Role-gated views<br/>route guard<br/>[RoleRoute.jsx]"]
  node_civic_views["Feed &amp; civic views<br/>route views<br/>[Feed.jsx]"]
  node_admin_view["Admin dashboard<br/>route view<br/>[AdminPanel.jsx]"]
end

subgraph group_api["Laravel API"]
  node_api_routes["API routes<br/>Laravel routing<br/>[api.php]"]
  node_auth_api["Authentication API<br/>controller<br/>[AuthController.php]"]
  node_access_middleware{{"Access gates<br/>middleware<br/>[RoleMiddleware.php]"}}
  node_post_api["Post &amp; comment API<br/>controllers<br/>[PostController.php]"]
  node_poll_api["Poll &amp; payment API<br/>controllers<br/>[PollController.php]"]
  node_admin_api["Administration API<br/>controller"]
end

subgraph group_domain["Civic domain"]
  node_identity_orgs["Users &amp; organizations<br/>domain models<br/>[User.php]"]
  node_nid_service{{"NID verification<br/>verification service"}}
  node_post_domain["Posts &amp; interactions<br/>domain model<br/>[Post.php]"]
  node_poll_rewards["Polls &amp; reward ledger<br/>domain models<br/>[PollResponse.php]"]
end

subgraph group_storage["Persistence &amp; media"]
  node_mysql[("MySQL / SQLite<br/>relational database")]
  node_public_media["Public media disk<br/>file storage"]
end

node_browser(("Citizen &amp; staff browsers<br/>clients"))

node_browser -->|"loads UI"| node_spa_entry
node_spa_entry -->|"provides state"| node_auth_context
node_spa_entry -->|"renders protected routes"| node_role_route
node_role_route -->|"authorizes"| node_civic_views
node_role_route -->|"authorizes"| node_admin_view
node_civic_views -->|"API calls"| node_api_client
node_admin_view -->|"API calls"| node_api_client
node_api_client -->|"Bearer /api requests"| node_api_routes
node_api_routes -->|"auth endpoints"| node_auth_api
node_api_routes -->|"authenticates &amp; gates"| node_access_middleware
node_access_middleware -->|"authorized civic writes"| node_post_api
node_access_middleware -->|"verified poll voting"| node_poll_api
node_access_middleware -->|"admin operations"| node_admin_api
node_access_middleware -->|"checks verification"| node_nid_service
node_auth_api -->|"accounts &amp; tokens"| node_identity_orgs
node_post_api -->|"manages"| node_post_domain
node_post_api -->|"authors &amp; ministries"| node_identity_orgs
node_poll_api -->|"records responses &amp; points"| node_poll_rewards
node_poll_api -->|"poll creators"| node_identity_orgs
node_admin_api -->|"moderates"| node_post_domain
node_admin_api -->|"approves organizations"| node_identity_orgs
node_identity_orgs -->|"persists"| node_mysql
node_post_domain -->|"persists"| node_mysql
node_poll_rewards -->|"persists"| node_mysql
node_post_domain -->|"stores images"| node_public_media

click node_spa_entry "https://github.com/arn101/jonomot/blob/main/frontend/src/main.jsx"
click node_api_client "https://github.com/arn101/jonomot/blob/main/frontend/src/api/client.js"
click node_auth_context "https://github.com/arn101/jonomot/blob/main/frontend/src/context/AuthContext.jsx"
click node_role_route "https://github.com/arn101/jonomot/blob/main/frontend/src/components/RoleRoute.jsx"
click node_civic_views "https://github.com/arn101/jonomot/blob/main/frontend/src/views/Feed.jsx"
click node_admin_view "https://github.com/arn101/jonomot/blob/main/frontend/src/views/AdminPanel.jsx"
click node_api_routes "https://github.com/arn101/jonomot/blob/main/backend/routes/api.php"
click node_auth_api "https://github.com/arn101/jonomot/blob/main/backend/app/Http/Controllers/Api/AuthController.php"
click node_access_middleware "https://github.com/arn101/jonomot/blob/main/backend/app/Http/Middleware/RoleMiddleware.php"
click node_post_api "https://github.com/arn101/jonomot/blob/main/backend/app/Http/Controllers/Api/PostController.php"
click node_poll_api "https://github.com/arn101/jonomot/blob/main/backend/app/Http/Controllers/Api/PollController.php"
click node_admin_api "https://github.com/arn101/jonomot/blob/main/backend/app/Http/Controllers/Api/AdminController.php"
click node_identity_orgs "https://github.com/arn101/jonomot/blob/main/backend/app/Models/User.php"
click node_nid_service "https://github.com/arn101/jonomot/blob/main/backend/app/Services/NidVerificationService.php"
click node_post_domain "https://github.com/arn101/jonomot/blob/main/backend/app/Models/Post.php"
click node_poll_rewards "https://github.com/arn101/jonomot/blob/main/backend/app/Models/PollResponse.php"
click node_mysql "https://github.com/arn101/jonomot/blob/main/backend/database/migrations/2026_07_10_173140_create_polls_and_ledgers_tables.php"
click node_public_media "https://github.com/arn101/jonomot/tree/main/backend/storage/app/public"

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_spa_entry,node_api_client,node_auth_context,node_role_route,node_civic_views,node_admin_view toneBlue
class node_api_routes,node_auth_api,node_access_middleware,node_post_api,node_poll_api,node_admin_api toneAmber
class node_identity_orgs,node_nid_service,node_post_domain,node_poll_rewards toneMint
class node_mysql,node_public_media toneRose
class node_browser toneNeutral
```

## Components

### React SPA

- [SPA entry & routes](https://github.com/arn101/jonomot/blob/main/frontend/src/main.jsx): React application · `frontend/src/main.jsx`
- [Central API client](https://github.com/arn101/jonomot/blob/main/frontend/src/api/client.js): Axios client · Sends all application requests to /api/*. · `frontend/src/api/client.js`
- [Auth & app state](https://github.com/arn101/jonomot/blob/main/frontend/src/context/AuthContext.jsx): React contexts · Persists the jonomot_token and provides shared session state. · `frontend/src/context/AuthContext.jsx`
- [Role-gated views](https://github.com/arn101/jonomot/blob/main/frontend/src/components/RoleRoute.jsx): route guard · `frontend/src/components/RoleRoute.jsx`
- [Feed & civic views](https://github.com/arn101/jonomot/blob/main/frontend/src/views/Feed.jsx): route views · Public feed, profile, polls, and ministry inbox. · `frontend/src/views/Feed.jsx`
- [Admin dashboard](https://github.com/arn101/jonomot/blob/main/frontend/src/views/AdminPanel.jsx): route view · `frontend/src/views/AdminPanel.jsx`

### Laravel API

- [API routes](https://github.com/arn101/jonomot/blob/main/backend/routes/api.php): Laravel routing · Maps JSON endpoints and applies throttling. · `backend/routes/api.php`
- [Authentication API](https://github.com/arn101/jonomot/blob/main/backend/app/Http/Controllers/Api/AuthController.php): controller · Registration and login issue Sanctum personal-access tokens. · `backend/app/Http/Controllers/Api/AuthController.php`
- [Access gates](https://github.com/arn101/jonomot/blob/main/backend/app/Http/Middleware/RoleMiddleware.php): middleware · Sanctum auth plus role and NID-verification capability checks. · `backend/app/Http/Middleware/RoleMiddleware.php`
- [Post & comment API](https://github.com/arn101/jonomot/blob/main/backend/app/Http/Controllers/Api/PostController.php): controllers · Creates reports and handles interactions, comments, ministry responses, and moderation reports. · `backend/app/Http/Controllers/Api/PostController.php`
- [Poll & payment API](https://github.com/arn101/jonomot/blob/main/backend/app/Http/Controllers/Api/PollController.php): controllers · Manages polls, eligibility, responses, rewards, and payment endpoints. · `backend/app/Http/Controllers/Api/PollController.php`
- [Administration API](https://github.com/arn101/jonomot/blob/main/backend/app/Http/Controllers/Api/AdminController.php): controller · Reviews flagged content and approves organizations. · `backend/app/Http/Controllers/Api/AdminController.php`

### Civic domain

- [Users & organizations](https://github.com/arn101/jonomot/blob/main/backend/app/Models/User.php): domain models · Shared users plus ministry and company profiles with approval state. · `backend/app/Models/User.php`
- [NID verification](https://github.com/arn101/jonomot/blob/main/backend/app/Services/NidVerificationService.php): verification service · Local mock integration that gates civic publishing and poll voting. · `backend/app/Services/NidVerificationService.php`
- [Posts & interactions](https://github.com/arn101/jonomot/blob/main/backend/app/Models/Post.php): domain model · Categorized citizen reports linked to ministries, votes, saves, comments, and flags. · `backend/app/Models/Post.php`
- [Polls & reward ledger](https://github.com/arn101/jonomot/blob/main/backend/app/Models/PollResponse.php): domain models · Poll responses record participation and credit reward points. · `backend/app/Models/PollResponse.php`

### Persistence & media

- [MySQL / SQLite](https://github.com/arn101/jonomot/blob/main/backend/database/migrations/2026_07_10_173140_create_polls_and_ledgers_tables.php): relational database · Stores users, organizations, posts, polls, ledger, Sanctum tokens, and runtime tables. · `backend/database/migrations/2026_07_10_173140_create_polls_and_ledgers_tables.php`
- [Public media disk](https://github.com/arn101/jonomot/tree/main/backend/storage/app/public): file storage · Serves post images and avatars through Laravel public storage. · `backend/storage/app/public`

### Other components

- **Citizen & staff browsers**: clients

## Connections

- Citizen & staff browsers → SPA entry & routes: loads UI
- SPA entry & routes → Auth & app state: provides state
- SPA entry & routes → Role-gated views: renders protected routes
- Role-gated views → Feed & civic views: authorizes
- Role-gated views → Admin dashboard: authorizes
- Feed & civic views → Central API client: API calls
- Admin dashboard → Central API client: API calls
- Central API client → API routes: Bearer /api requests
- API routes → Authentication API: auth endpoints
- API routes → Access gates: authenticates & gates
- Access gates → Post & comment API: authorized civic writes
- Access gates → Poll & payment API: verified poll voting
- Access gates → Administration API: admin operations
- Access gates → NID verification: checks verification
- Authentication API → Users & organizations: accounts & tokens
- Post & comment API → Posts & interactions: manages
- Post & comment API → Users & organizations: authors & ministries
- Poll & payment API → Polls & reward ledger: records responses & points
- Poll & payment API → Users & organizations: poll creators
- Administration API → Posts & interactions: moderates
- Administration API → Users & organizations: approves organizations
- Users & organizations → MySQL / SQLite: persists
- Posts & interactions → MySQL / SQLite: persists
- Polls & reward ledger → MySQL / SQLite: persists
- Posts & interactions → Public media disk: stores images
