# nikhil3113/billeasy-assessment architecture

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

- Interactive diagram: https://gitdiagram.com/nikhil3113/billeasy-assessment
- Repository: https://github.com/nikhil3113/billeasy-assessment

## Overview

##### Project type and purpose
- This is a backend‐only, RESTful API service for managing books and reviews.
- Tech stack: Node.js + Express (HTTP server), MongoDB (database), Prisma (ORM), JWT (authentication).

##### File structure
- src/server.ts: entry point, sets up Express and mounts routes.
- src/routes/*.ts: defines HTTP endpoints for users, books, reviews.
- src/controller/*.ts: implements business logic for each resource.
- src/middleware/auth.ts: enforces JWT authentication on protected routes.
- src/prisma.ts + src/generated/prisma: Prisma client setup and generated code.
- prisma/schema.prisma: data model definitions.

##### README for additional insights
- Confirms layered architecture: HTTP server → routing → controllers → ORM → database
- JWT secret is stored in env vars; database URL likewise.
- No UI/front end—clients consume JSON over HTTP.

a. Main components:
- Client (e.g. browser, mobile app, Postman)
- API Server (Express app)
- Routing Layer
- Middleware Layer (Auth)
- Controller Layer (User, Book, Review controllers)
- Data Access Layer (Prisma ORM)
- Database: MongoDB
b. Relationships & data flow:
1) Client → HTTP request → Express Router
2) Router → [Auth Middleware] → Controller
3) Controller → Prisma Client → MongoDB
4) MongoDB → Prisma → Controller → HTTP response → Client
c. Architectural patterns & principles:
- Layered (Controller, Middleware, Data Access)
- Separation of concerns (routing vs business logic vs data logic)
- Stateless authentication via JWT
- Modular file organization by resource
d. Key technologies & libraries:
- Express: HTTP server & routing
- Prisma: type‐safe ORM connecting Node.js to MongoDB
- MongoDB: document database
- jsonwebtoken: JWT creation/verification

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client"]:::client
    subgraph "API Server"
        Router["Express Router"]:::http
        Auth["Auth Middleware"]:::http
        subgraph "Controllers"
            UserCtrl["User Controller"]:::business
            BookCtrl["Book Controller"]:::business
            ReviewCtrl["Review Controller"]:::business
        end
        subgraph "Data Access Layer"
            PrismaSetup["Prisma Setup"]:::data
            PrismaGen["Prisma Client"]:::data
        end
    end
    MongoDB["MongoDB"]:::db

    %% Request Flow
    Client -->|"HTTP Request"| Router
    Router -->|"JWT Check"| Auth
    Auth -->|"Invoke Handler"| UserCtrl
    Auth -->|"Invoke Handler"| BookCtrl
    Auth -->|"Invoke Handler"| ReviewCtrl
    UserCtrl -->|"Query/Mutate"| PrismaGen
    BookCtrl -->|"Query/Mutate"| PrismaGen
    ReviewCtrl -->|"Query/Mutate"| PrismaGen
    PrismaGen -->|"Reads/Writes"| MongoDB

    %% Response Flow
    MongoDB -->|"Data"| PrismaGen
    PrismaGen -->|"Result"| UserCtrl
    PrismaGen -->|"Result"| BookCtrl
    PrismaGen -->|"Result"| ReviewCtrl
    UserCtrl -->|"HTTP Response"| Client
    BookCtrl -->|"HTTP Response"| Client
    ReviewCtrl -->|"HTTP Response"| Client

    %% Click Events
    click Router "https://github.com/nikhil3113/billeasy-assessment/tree/main/src/routes/"
    click Auth "https://github.com/nikhil3113/billeasy-assessment/blob/main/src/middleware/auth.ts"
    click UserCtrl "https://github.com/nikhil3113/billeasy-assessment/blob/main/src/controller/user.ts"
    click BookCtrl "https://github.com/nikhil3113/billeasy-assessment/blob/main/src/controller/books.ts"
    click ReviewCtrl "https://github.com/nikhil3113/billeasy-assessment/blob/main/src/controller/reviews.ts"
    click PrismaSetup "https://github.com/nikhil3113/billeasy-assessment/blob/main/src/prisma.ts"
    click PrismaGen "https://github.com/nikhil3113/billeasy-assessment/tree/main/src/generated/prisma/"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef http fill:#FFFF99,stroke:#333,stroke-width:1px
    classDef business fill:#FFA500,stroke:#333,stroke-width:1px
    classDef data fill:#90EE90,stroke:#333,stroke-width:1px
    classDef db fill:#228B22,stroke:#333,stroke-width:1px, color:#fff
```
