# deepanshurajput-2027/intern_task architecture

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

- Interactive diagram: https://gitdiagram.com/deepanshurajput-2027/intern_task
- Repository: https://github.com/deepanshurajput-2027/intern_task

## Overview

#### Purpose and Entry Points
Store Rating Application is a role-based SaaS for store discovery, 1–5 star ratings, administration, and owner-facing rating analytics. It is a React SPA backed by an Express API and MySQL via Sequelize. Client bootstraps at `client/src/main.jsx` and server bootstraps through `server/src/server.js` into `server/src/app.js`.

#### Client Application Shell and Routing
React Router defines public, role-protected, and unauthorized views in `client/src/routes/AppRoutes.jsx`. Authentication state is centralized in `client/src/context/AuthContext.jsx`; route access is enforced by `client/src/components/protected/ProtectedRoute.jsx`. Shared authenticated page structure, including navigation/sidebar, is provided by `client/src/components/layout/DashboardLayout.jsx` and `client/src/components/layout/Sidebar.jsx`.

#### Role-Specific UI Modules
Admin pages manage users, stores, and aggregate metrics through `client/src/pages/admin/Dashboard.jsx`, `client/src/pages/admin/Users.jsx`, and `client/src/pages/admin/Stores.jsx`. Users browse/search stores and submit ratings from `client/src/pages/user/UserDashboard.jsx` with `client/src/components/user/RatingModal.jsx`. Store owners consume their ratings and settings through `client/src/pages/storeOwner/Dashboard.jsx` and `client/src/components/storeOwner/RatingsTable.jsx`.

#### Client API and State Flow
Views invoke domain hooks such as `client/src/hooks/useStores.js`, `client/src/hooks/useUsers.js`, and `client/src/hooks/useStoreRatings.js`; hooks call role/domain service modules. `client/src/api/axios.js` owns Axios setup and JWT interceptor behavior, while `client/src/services/auth.service.js`, `client/src/services/admin.service.js`, and `client/src/services/user.service.js` encapsulate API calls. This keeps component rendering separate from remote-data operations and token transport.

#### API Boundary and Authorization
Express routes partition API capabilities by domain and role: `server/src/routes/auth.routes.js`, `server/src/routes/admin.routes.js`, `server/src/routes/store.routes.js`, and `server/src/routes/store-owner.routes.js`, collected by `server/src/routes/index.js`. Requests traverse authentication and RBAC middleware in `server/src/middlewares/authenticate.js` and `server/src/middlewares/authorize.js`; controllers validate inputs with domain validators, e.g. `server/src/controllers/rating.controller.js` and `server/src/validators/rating.validator.js`.

#### Backend Business Layers and Persistence
The backend follows controller → service → repository → Sequelize model flow. Domain logic resides in modules such as `server/src/services/store.service.js`, `server/src/services/rating.service.js`, and `server/src/services/admin.service.js`; database access is isolated in corresponding repositories including `server/src/repositories/store.repository.js` and `server/src/repositories/rating.repository.js`. Core persisted entities are `server/src/models/User.js`, `server/src/models/Store.js`, and `server/src/models/Rating.js`, with database connection setup in `server/src/config/db.js`.

#### Runtime, Security, and Infrastructure
Client runs/builds under Vite; server runs on Node.js/Express. MySQL is the required external datastore, accessed through Sequelize and configured via `server/src/config/env.js` and `server/src/config/db.js`. JWT issuance/verification and password hashing are handled by `server/src/utils/jwt.js` and `server/src/utils/password.js`. API failures are normalized through `server/src/middlewares/errorHandler.js` and response/error utilities under `server/src/utils/`.

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React Client"]
  node_client_bootstrap["Vite bootstrap<br/>React entry<br/>[main.jsx]"]
  node_routing["App routes<br/>React Router<br/>[AppRoutes.jsx]"]
  node_auth_context["Auth state<br/>React context<br/>[AuthContext.jsx]"]
  node_route_guard["Protected route<br/>route guard<br/>[ProtectedRoute.jsx]"]
  node_dashboard_shell["Dashboard shell<br/>shared layout"]
  node_role_views["Role-specific views<br/>page modules<br/>[Dashboard.jsx]"]
  node_domain_hooks["Domain hooks<br/>client data layer<br/>[useStores.js]"]
  node_api_services["API services<br/>service modules<br/>[auth.service.js]"]
  node_axios_client["Axios JWT client<br/>HTTP transport<br/>[axios.js]"]
end

subgraph group_api["Express API"]
  node_server_entry["Express server<br/>Node entry<br/>[server.js]"]
  node_express_app["Express app<br/>application shell<br/>[app.js]"]
  node_route_registry["API routes<br/>route registry<br/>[index.js]"]
  node_auth_rbac["Authentication &amp; RBAC<br/>middleware<br/>[authenticate.js]"]
  node_controllers["Controllers &amp; validators<br/>request layer"]
  node_services["Business services<br/>domain layer<br/>[store.service.js]"]
  node_error_handling["Error normalization<br/>error middleware<br/>[errorHandler.js]"]
end

subgraph group_data["Data &amp; Security"]
  node_repositories["Repositories<br/>persistence layer"]
  node_models["Sequelize models<br/>entity models<br/>[User.js]"]
  node_mysql[("MySQL<br/>external datastore")]
  node_security_utils["JWT &amp; password utilities<br/>security utilities<br/>[jwt.js]"]
end

node_client_bootstrap -->|"mounts"| node_routing
node_routing -->|"reads session"| node_auth_context
node_routing -->|"protects routes"| node_route_guard
node_route_guard -->|"admits"| node_dashboard_shell
node_dashboard_shell -->|"hosts"| node_role_views
node_role_views -->|"uses"| node_domain_hooks
node_domain_hooks -->|"calls"| node_api_services
node_api_services -->|"uses"| node_axios_client
node_axios_client -->|"HTTPS API requests"| node_express_app
node_server_entry -->|"starts"| node_express_app
node_express_app -->|"mounts"| node_route_registry
node_route_registry -->|"passes protected requests"| node_auth_rbac
node_auth_rbac -->|"authorizes"| node_controllers
node_controllers -->|"delegates"| node_services
node_services -->|"queries"| node_repositories
node_repositories -->|"uses"| node_models
node_models -->|"persists via Sequelize"| node_mysql
node_auth_rbac -->|"verifies JWT"| node_security_utils
node_services -->|"issues JWTs / hashes passwords"| node_security_utils
node_express_app -->|"normalizes failures"| node_error_handling

click node_client_bootstrap "https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/main.jsx"
click node_routing "https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/routes/AppRoutes.jsx"
click node_auth_context "https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/context/AuthContext.jsx"
click node_route_guard "https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/components/protected/ProtectedRoute.jsx"
click node_dashboard_shell "https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/components/layout/DashboardLayout.jsx"
click node_role_views "https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/pages/admin/Dashboard.jsx"
click node_domain_hooks "https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/hooks/useStores.js"
click node_api_services "https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/services/auth.service.js"
click node_axios_client "https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/api/axios.js"
click node_server_entry "https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/server.js"
click node_express_app "https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/app.js"
click node_route_registry "https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/routes/index.js"
click node_auth_rbac "https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/middlewares/authenticate.js"
click node_controllers "https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/controllers/rating.controller.js"
click node_services "https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/services/store.service.js"
click node_repositories "https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/repositories/store.repository.js"
click node_models "https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/models/User.js"
click node_security_utils "https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/utils/jwt.js"
click node_error_handling "https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/middlewares/errorHandler.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_client_bootstrap,node_routing,node_auth_context,node_route_guard,node_dashboard_shell,node_role_views,node_domain_hooks,node_api_services,node_axios_client toneBlue
class node_server_entry,node_express_app,node_route_registry,node_auth_rbac,node_controllers,node_services,node_error_handling toneAmber
class node_repositories,node_models,node_mysql,node_security_utils toneMint
```

## Components

### React Client

- [Vite bootstrap](https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/main.jsx): React entry · `client/src/main.jsx`
- [App routes](https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/routes/AppRoutes.jsx): React Router · Public, protected, and unauthorized views. · `client/src/routes/AppRoutes.jsx`
- [Auth state](https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/context/AuthContext.jsx): React context · `client/src/context/AuthContext.jsx`
- [Protected route](https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/components/protected/ProtectedRoute.jsx): route guard · Enforces authenticated role access. · `client/src/components/protected/ProtectedRoute.jsx`
- [Dashboard shell](https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/components/layout/DashboardLayout.jsx): shared layout · Authenticated navigation and sidebar. · `client/src/components/layout/DashboardLayout.jsx`
- [Role-specific views](https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/pages/admin/Dashboard.jsx): page modules · Admin management, user ratings, and owner analytics. · `client/src/pages/admin/Dashboard.jsx`
- [Domain hooks](https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/hooks/useStores.js): client data layer · Store, user, and rating remote-data hooks. · `client/src/hooks/useStores.js`
- [API services](https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/services/auth.service.js): service modules · Domain-specific API calls. · `client/src/services/auth.service.js`
- [Axios JWT client](https://github.com/deepanshurajput-2027/intern_task/blob/main/client/src/api/axios.js): HTTP transport · Configures requests and JWT interception. · `client/src/api/axios.js`

### Express API

- [Express server](https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/server.js): Node entry · `server/src/server.js`
- [Express app](https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/app.js): application shell · `server/src/app.js`
- [API routes](https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/routes/index.js): route registry · Auth, admin, store, and owner route domains. · `server/src/routes/index.js`
- [Authentication & RBAC](https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/middlewares/authenticate.js): middleware · Verifies JWTs and authorizes roles. · `server/src/middlewares/authenticate.js`
- [Controllers & validators](https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/controllers/rating.controller.js): request layer · Validates inputs and handles domain requests. · `server/src/controllers/rating.controller.js`
- [Business services](https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/services/store.service.js): domain layer · Store, rating, and admin business logic. · `server/src/services/store.service.js`
- [Error normalization](https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/middlewares/errorHandler.js): error middleware · `server/src/middlewares/errorHandler.js`

### Data & Security

- [Repositories](https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/repositories/store.repository.js): persistence layer · Isolates Sequelize data access. · `server/src/repositories/store.repository.js`
- [Sequelize models](https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/models/User.js): entity models · User, Store, and Rating entities. · `server/src/models/User.js`
- **MySQL**: external datastore
- [JWT & password utilities](https://github.com/deepanshurajput-2027/intern_task/blob/main/server/src/utils/jwt.js): security utilities · Issues tokens and hashes passwords. · `server/src/utils/jwt.js`

## Connections

- Vite bootstrap → App routes: mounts
- App routes → Auth state: reads session
- App routes → Protected route: protects routes
- Protected route → Dashboard shell: admits
- Dashboard shell → Role-specific views: hosts
- Role-specific views → Domain hooks: uses
- Domain hooks → API services: calls
- API services → Axios JWT client: uses
- Axios JWT client → Express app: HTTPS API requests
- Express server → Express app: starts
- Express app → API routes: mounts
- API routes → Authentication & RBAC: passes protected requests
- Authentication & RBAC → Controllers & validators: authorizes
- Controllers & validators → Business services: delegates
- Business services → Repositories: queries
- Repositories → Sequelize models: uses
- Sequelize models → MySQL: persists via Sequelize
- Authentication & RBAC → JWT & password utilities: verifies JWT
- Business services → JWT & password utilities: issues JWTs / hashes passwords
- Express app → Error normalization: normalizes failures
