# pravinmishraaws/book-review-app architecture

> Architecture diagram of the GitHub repository pravinmishraaws/book-review-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pravinmishraaws/book-review-app
- Repository: https://github.com/pravinmishraaws/book-review-app

## Overview

1. **Overall shape**
   - This repository is a **three-tier book review application** split into **frontend**, **backend**, and **database** concerns, with separate deployment/automation layers around it.
   - The runtime app is composed of a **Next.js UI**, a **Node/Express API**, and a **MySQL database** accessed through **Sequelize**.

2. **Frontend subsystem**
   - The `frontend/` folder contains a **Next.js App Router** application under `src/app`, with routes for the home page, login, register, and dynamic book detail pages (`book/[id]`).
   - UI composition is centered around reusable components like `Navbar`, plus global auth state in `src/context/UserContext.js`.

3. **Frontend data access boundary**
   - The frontend does not appear to own business logic; it delegates server interaction to `src/services/api.js`, which is the main integration point with the backend API.
   - This makes the UI a thin presentation layer that fetches books, book details, reviews, and auth-related responses from the backend.

4. **Backend subsystem**
   - The `backend/src` tree follows a clear **controller/route/model/middleware** structure, with `server.js` as the entrypoint.
   - Routes are split by domain: `bookRoutes.js`, `reviewRoutes.js`, and `userRoutes.js`, each calling into matching controllers.

5. **Backend business logic**
   - Controllers (`bookController.js`, `reviewController.js`, `userController.js`) hold the API behavior for listing books, reading book details, registering/logging in users, and creating reviews.
   - This is where the app’s core rules live, while route files stay focused on HTTP wiring.

6. **Authentication and request protection**
   - `middleware/authMiddleware.js` is the security boundary for protected actions.
   - The architecture implies JWT-based auth: users authenticate through the backend, and protected review submission requests are validated before reaching business logic.

7. **Persistence layer**
   - `backend/src/config/db.js` and the Sequelize models (`User.js`, `Book.js`, `Review.js`) show that the data layer is relational and ORM-backed.
   - The database boundary is MySQL, with users, books, and reviews represented as distinct entities linked by application logic and database relations.

8. **Primary application flow**
   - A typical unauthenticated flow is: browser loads the Next.js app, frontend calls backend APIs, backend reads from MySQL, and book/review data is rendered back in the UI.
   - For authenticated users, the flow adds login/register, token issuance, auth state persistence in the frontend context, and token-guarded review submission.

9. **State and session handling**
   - The frontend’s `UserContext` acts as the app-wide state holder for logged-in user identity and auth status.
   - This is the main frontend boundary for session-aware behavior such as showing login/register vs. review submission capabilities.

10. **Containerization**
   - Both `frontend/` and `backend/` have their own `Dockerfile`, indicating each tier can be packaged and run independently.
   - `docker-compose.yml` provides the local orchestration boundary, tying together app containers and the database for development or integration testing.

11. **Infrastructure automation**
   - The `ansible/` directory is organized into roles for `common`, `frontend`, and `backend`, with per-environment `group_vars` and an `inventory.ini`.
   - This suggests server provisioning/deployment is handled as separate concerns per tier, rather than as a single monolithic script.

12. **CI/CD and environment delivery**
   - `azure-pipeline.yaml` is the top-level pipeline entrypoint, so build/test/deploy automation is intended to be part of the project’s delivery path.
   - The extra docs (`Docker_README.md`, `mysql_docker.md`, tier-specific README files) reinforce that this repo is designed for repeatable deployment across local Docker, Ansible-managed hosts, and cloud CI/CD.

13. **Architecture diagram takeaway**
   - If drawing the system, the cleanest boundaries are: **browser/UI → Next.js frontend → Express API → MySQL**, with **JWT auth** crossing the frontend/backend boundary and **Docker/Ansible/Azure Pipelines** sitting around the runtime stack as delivery and operations layers.

Main entry points: [`frontend/src/app`](https://github.com/pravinmishraaws/book-review-app/tree/main/frontend/src/app) (Next.js App), [`backend/src/routes`](https://github.com/pravinmishraaws/book-review-app/tree/main/backend/src/routes) (Routes), [`backend/src/models`](https://github.com/pravinmishraaws/book-review-app/tree/main/backend/src/models) (Models), [`docker-compose.yml`](https://github.com/pravinmishraaws/book-review-app/blob/main/docker-compose.yml) (Docker Compose)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_ui["Next.js App<br/>nextjs frontend"]
  node_home["Home<br/>route<br/>[page.js]"]
  node_login["Login<br/>route<br/>[page.js]"]
  node_register["Register<br/>route<br/>[page.js]"]
  node_bookdetail["Book Detail<br/>route<br/>[page.js]"]
  node_navbar["Navbar<br/>[Navbar.js]"]
  node_userctx["User Context<br/>state<br/>[UserContext.js]"]
  node_apiclient["API Client<br/>[api.js]"]
end

subgraph group_backend["Backend"]
  node_server["API Server<br/>express entrypoint<br/>[server.js]"]
  node_routes["Routes<br/>http routing"]
  node_bookroutes["Book Routes<br/>route module<br/>[bookRoutes.js]"]
  node_reviewroutes["Review Routes<br/>route module<br/>[reviewRoutes.js]"]
  node_userroutes["User Routes<br/>route module<br/>[userRoutes.js]"]
  node_controllers["Controllers<br/>api logic"]
  node_bookcontroller["Book Controller<br/>[bookController.js]"]
  node_reviewcontroller["Review Controller"]
  node_usercontroller["User Controller<br/>[userController.js]"]
  node_authmw["Auth Middleware<br/>security boundary<br/>[authMiddleware.js]"]
  node_dbconfig["DB Config<br/>sequelize setup<br/>[db.js]"]
  node_models["Models"]
  node_bookmodel["Book<br/>model<br/>[Book.js]"]
  node_reviewmodel["Review<br/>model<br/>[Review.js]"]
  node_usermodel["User<br/>model<br/>[User.js]"]
end

subgraph group_ops["Delivery"]
  node_compose["Docker Compose<br/>orchestration<br/>[docker-compose.yml]"]
  node_frontenddocker["Frontend Dockerfile<br/>container spec"]
  node_backenddocker["Backend Dockerfile<br/>container spec"]
  node_ansible["Ansible<br/>provisioning<br/>[site.yml]"]
  node_pipeline["Azure Pipeline<br/>ci/cd"]
end

node_browser(("Browser<br/>client"))
node_mysql[("MySQL<br/>database")]

node_browser -->|"loads"| node_ui
node_ui -->|"renders"| node_home
node_ui -->|"renders"| node_login
node_ui -->|"renders"| node_register
node_ui -->|"renders"| node_bookdetail
node_ui -->|"composes"| node_navbar
node_ui -->|"shares state"| node_userctx
node_ui -->|"calls"| node_apiclient
node_apiclient -->|"HTTP API"| node_server
node_server -->|"wires"| node_routes
node_routes -->|"includes"| node_bookroutes
node_routes -->|"includes"| node_reviewroutes
node_routes -->|"includes"| node_userroutes
node_bookroutes -->|"delegates"| node_bookcontroller
node_reviewroutes -->|"delegates"| node_reviewcontroller
node_userroutes -->|"delegates"| node_usercontroller
node_reviewroutes -->|"guards"| node_authmw
node_controllers -->|"contains"| node_bookcontroller
node_controllers -->|"contains"| node_reviewcontroller
node_controllers -->|"contains"| node_usercontroller
node_bookcontroller -->|"queries"| node_dbconfig
node_reviewcontroller -->|"queries"| node_dbconfig
node_usercontroller -->|"queries"| node_dbconfig
node_dbconfig -->|"connects"| node_models
node_models -->|"contains"| node_bookmodel
node_models -->|"contains"| node_reviewmodel
node_models -->|"contains"| node_usermodel
node_bookmodel -->|"persists to"| node_mysql
node_reviewmodel -->|"persists to"| node_mysql
node_usermodel -->|"persists to"| node_mysql
node_compose -->|"builds"| node_frontenddocker
node_compose -->|"builds"| node_backenddocker
node_compose -->|"runs with"| node_mysql
node_ansible -->|"deploys"| node_frontenddocker
node_ansible -->|"deploys"| node_backenddocker
node_pipeline -->|"validates"| node_compose
node_pipeline -->|"delivers"| node_ansible

click node_ui "https://github.com/pravinmishraaws/book-review-app/tree/main/frontend/src/app"
click node_home "https://github.com/pravinmishraaws/book-review-app/blob/main/frontend/src/app/page.js"
click node_login "https://github.com/pravinmishraaws/book-review-app/blob/main/frontend/src/app/login/page.js"
click node_register "https://github.com/pravinmishraaws/book-review-app/blob/main/frontend/src/app/register/page.js"
click node_bookdetail "https://github.com/pravinmishraaws/book-review-app/blob/main/frontend/src/app/book/[id]/page.js"
click node_navbar "https://github.com/pravinmishraaws/book-review-app/blob/main/frontend/src/components/Navbar.js"
click node_userctx "https://github.com/pravinmishraaws/book-review-app/blob/main/frontend/src/context/UserContext.js"
click node_apiclient "https://github.com/pravinmishraaws/book-review-app/blob/main/frontend/src/services/api.js"
click node_server "https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/server.js"
click node_routes "https://github.com/pravinmishraaws/book-review-app/tree/main/backend/src/routes"
click node_bookroutes "https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/routes/bookRoutes.js"
click node_reviewroutes "https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/routes/reviewRoutes.js"
click node_userroutes "https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/routes/userRoutes.js"
click node_controllers "https://github.com/pravinmishraaws/book-review-app/tree/main/backend/src/controllers"
click node_bookcontroller "https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/controllers/bookController.js"
click node_reviewcontroller "https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/controllers/reviewController.js"
click node_usercontroller "https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/controllers/userController.js"
click node_authmw "https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/middleware/authMiddleware.js"
click node_dbconfig "https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/config/db.js"
click node_models "https://github.com/pravinmishraaws/book-review-app/tree/main/backend/src/models"
click node_bookmodel "https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/models/Book.js"
click node_reviewmodel "https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/models/Review.js"
click node_usermodel "https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/models/User.js"
click node_compose "https://github.com/pravinmishraaws/book-review-app/blob/main/docker-compose.yml"
click node_frontenddocker "https://github.com/pravinmishraaws/book-review-app/tree/main/frontend/Dockerfile"
click node_backenddocker "https://github.com/pravinmishraaws/book-review-app/tree/main/backend/Dockerfile"
click node_ansible "https://github.com/pravinmishraaws/book-review-app/blob/main/ansible/site.yml"
click node_pipeline "https://github.com/pravinmishraaws/book-review-app/blob/main/azure-pipeline.yaml"

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_ui,node_home,node_login,node_register,node_bookdetail,node_navbar,node_userctx,node_apiclient toneBlue
class node_server,node_routes,node_bookroutes,node_reviewroutes,node_userroutes,node_controllers,node_bookcontroller,node_reviewcontroller,node_usercontroller,node_authmw,node_dbconfig,node_models,node_bookmodel,node_reviewmodel,node_usermodel toneAmber
class node_compose,node_frontenddocker,node_backenddocker,node_ansible,node_pipeline toneMint
class node_browser,node_mysql toneNeutral
```

## Components

### Frontend

Next.js UI and client-side state

- [Next.js App](https://github.com/pravinmishraaws/book-review-app/tree/main/frontend/src/app): nextjs frontend · App Router presentation layer · `frontend/src/app`
- [Home](https://github.com/pravinmishraaws/book-review-app/blob/main/frontend/src/app/page.js): route · Landing page route · `frontend/src/app/page.js`
- [Login](https://github.com/pravinmishraaws/book-review-app/blob/main/frontend/src/app/login/page.js): route · Authentication page · `frontend/src/app/login/page.js`
- [Register](https://github.com/pravinmishraaws/book-review-app/blob/main/frontend/src/app/register/page.js): route · User registration page · `frontend/src/app/register/page.js`
- [Book Detail](https://github.com/pravinmishraaws/book-review-app/blob/main/frontend/src/app/book/[id]/page.js): route · Dynamic book page · `frontend/src/app/book/[id]/page.js`
- [Navbar](https://github.com/pravinmishraaws/book-review-app/blob/main/frontend/src/components/Navbar.js): Shared navigation shell · `frontend/src/components/Navbar.js`
- [User Context](https://github.com/pravinmishraaws/book-review-app/blob/main/frontend/src/context/UserContext.js): state · App-wide auth state · `frontend/src/context/UserContext.js`
- [API Client](https://github.com/pravinmishraaws/book-review-app/blob/main/frontend/src/services/api.js): service · Frontend backend integration · `frontend/src/services/api.js`

### Backend

Express API, auth, and persistence

- [API Server](https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/server.js): express entrypoint · Backend application bootstrap · `backend/src/server.js`
- [Routes](https://github.com/pravinmishraaws/book-review-app/tree/main/backend/src/routes): http routing · Domain route wiring · `backend/src/routes`
- [Book Routes](https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/routes/bookRoutes.js): route module · Book endpoints · `backend/src/routes/bookRoutes.js`
- [Review Routes](https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/routes/reviewRoutes.js): route module · Review endpoints · `backend/src/routes/reviewRoutes.js`
- [User Routes](https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/routes/userRoutes.js): route module · Auth endpoints · `backend/src/routes/userRoutes.js`
- [Controllers](https://github.com/pravinmishraaws/book-review-app/tree/main/backend/src/controllers): api logic · Request handlers for core behavior · `backend/src/controllers`
- [Book Controller](https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/controllers/bookController.js): controller · Book listing and detail logic · `backend/src/controllers/bookController.js`
- [Review Controller](https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/controllers/reviewController.js): controller · Review creation logic · `backend/src/controllers/reviewController.js`
- [User Controller](https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/controllers/userController.js): controller · Login and registration logic · `backend/src/controllers/userController.js`
- [Auth Middleware](https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/middleware/authMiddleware.js): security boundary · Protects authenticated actions · `backend/src/middleware/authMiddleware.js`
- [DB Config](https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/config/db.js): sequelize setup · Database connection setup · `backend/src/config/db.js`
- [Models](https://github.com/pravinmishraaws/book-review-app/tree/main/backend/src/models): orm models · Relational domain entities · `backend/src/models`
- [Book](https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/models/Book.js): model · Book entity · `backend/src/models/Book.js`
- [Review](https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/models/Review.js): model · Review entity · `backend/src/models/Review.js`
- [User](https://github.com/pravinmishraaws/book-review-app/blob/main/backend/src/models/User.js): model · User entity · `backend/src/models/User.js`

### Delivery

Containerization, provisioning, and CI/CD

- [Docker Compose](https://github.com/pravinmishraaws/book-review-app/blob/main/docker-compose.yml): orchestration · Local multi-service runtime · `docker-compose.yml`
- [Frontend Dockerfile](https://github.com/pravinmishraaws/book-review-app/tree/main/frontend/Dockerfile): container spec · Frontend image build · `frontend/Dockerfile`
- [Backend Dockerfile](https://github.com/pravinmishraaws/book-review-app/tree/main/backend/Dockerfile): container spec · Backend image build · `backend/Dockerfile`
- [Ansible](https://github.com/pravinmishraaws/book-review-app/blob/main/ansible/site.yml): provisioning · Server setup and deployment · `ansible/site.yml`
- [Azure Pipeline](https://github.com/pravinmishraaws/book-review-app/blob/main/azure-pipeline.yaml): ci/cd · Build and delivery pipeline · `azure-pipeline.yaml`

### Other components

- **Browser**: client · End-user web client
- **MySQL**: database · Relational data store

## Connections

- Browser → Next.js App: loads · User opens the web app
- Next.js App → Home: renders · Home route is served by the app router
- Next.js App → Login: renders · Login route is served by the app router
- Next.js App → Register: renders · Register route is served by the app router
- Next.js App → Book Detail: renders · Dynamic book detail route
- Next.js App → Navbar: composes · Shared navigation across pages
- Next.js App → User Context: shares state · Authentication state is stored in context
- Next.js App → API Client: calls · Client requests backend data and auth responses
- API Client → API Server: HTTP API · Frontend integrates with backend endpoints
- API Server → Routes: wires · Entrypoint mounts domain routes
- Routes → Book Routes: includes · Book endpoint module
- Routes → Review Routes: includes · Review endpoint module
- Routes → User Routes: includes · User endpoint module
- Book Routes → Book Controller: delegates · Book routes forward to controller logic
- Review Routes → Review Controller: delegates · Review routes forward to controller logic
- User Routes → User Controller: delegates · User routes forward to controller logic
- Review Routes → Auth Middleware: guards · Protected review actions are checked by auth middleware
- Controllers → Book Controller: contains · Book business logic
- Controllers → Review Controller: contains · Review business logic
- Controllers → User Controller: contains · User authentication logic
- Book Controller → DB Config: queries · Book operations use the database layer
- Review Controller → DB Config: queries · Review operations use the database layer
- User Controller → DB Config: queries · User operations use the database layer
- DB Config → Models: connects · Sequelize connection backs the ORM models
- Models → Book: contains · Book model
- Models → Review: contains · Review model
- Models → User: contains · User model
- Book → MySQL: persists to · Book records live in MySQL
- Review → MySQL: persists to · Review records live in MySQL
- User → MySQL: persists to · User records live in MySQL
- Docker Compose → Frontend Dockerfile: builds · Frontend container definition
- Docker Compose → Backend Dockerfile: builds · Backend container definition
- Docker Compose → MySQL: runs with · Local orchestration includes the database
- Ansible → Frontend Dockerfile: deploys · Frontend tier provisioning and rollout
- Ansible → Backend Dockerfile: deploys · Backend tier provisioning and rollout
- Azure Pipeline → Docker Compose: validates · CI/CD can exercise the containerized stack
- Azure Pipeline → Ansible: delivers · Pipeline supports infrastructure delivery
