# rajanshah23/yipl-backend-2025 architecture

> Architecture diagram of the GitHub repository rajanshah23/yipl-backend-2025, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rajanshah23/yipl-backend-2025
- Repository: https://github.com/rajanshah23/yipl-backend-2025

## Overview

##### Project Type & Purpose
- This is a backend‐only RESTful API for a Library Management System, built with Node.js, Express, Sequelize (ORM), and SQLite.
- It exposes CRUD endpoints for Authors and Books, with pagination, filtering, error handling, optional JWT‐based authentication, and Docker support for easy deployment.

##### High‐Level Architectural Overview
- Pattern: Classic MVC (Model‐View‐Controller) adapted for an API (no “View” layer beyond JSON responses).
- Layers:
a. Presentation/API Layer (Routes & Middleware)
b. Application/Business Logic Layer (Controllers & Services)
c. Persistence Layer (Sequelize Models + Raw SQLite DB)
d. Infrastructure (Configuration, Migrations, Seeders, Docker)

A. Client (e.g., Frontend App or API Client like Postman)
B. API Server (Docker Container running Node/Express)
1. Routes Layer
- authorRoute.js, bookRoute.js, userRoute.js
2. Middleware
- isAuthenticated.js
3. Controllers
- authorController.js, bookController.js, userController.js
4. Services/Utilities
- catchAsync.js (error‐wrapping)
5. Config
- config/config.json (DB credentials, env variables)
6. Server Entrypoints
- server.js (HTTP server + Docker binding)
- src/app.js (Express app setup)
C. Database
- Sequelize CLI artifacts (migrations/, seeders/)
- SQLite file (sqlite_data/database.sqlite)
D. External/DevOps
- Dockerfile & dockerignore
- .env (JWT_SECRET, DB_PATH – implied)
- npm scripts for migrate/seed/dev

##### Data Flow & Interactions
1. Client → HTTP Request → Express Routes
2. Route → (Optional) Authentication Middleware
3. Middleware → Controller
4. Controller → Service Wrapper (catchAsync) → Business Logic
5. Business Logic → Sequelize Models → SQLite DB
6. DB → Sequelize → Controller → Client (JSON Response)
7. Migrations/Seeders interact directly with Config & DB for schema & initial data
8. Docker wraps entire API Server + persistent volume for sqlite_data

##### Architectural Patterns & Principles
- Separation of Concerns: Routes vs Controllers vs Services vs Models
- Layered Architecture: each layer only calls the next lower layer
- Single Source of Truth: `models/index.js` exports the DB connection & models
- Resilience: `catchAsync` for uniform async error handling
- Configuration Management: `config/config.json` with environment overrides
- Infrastructure as Code: Dockerfile + migrations/seeders for DB lifecycle

##### Technologies & Frameworks
- Node.js & Express for HTTP server
- Sequelize ORM for DB abstraction & migrations
- SQLite for zero-admin, file‐based persistence
- Docker for containerization
- npm scripts for automation (migrate, seed, dev, start)

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client (Postman/Frontend)"):::external

    subgraph "Docker Container"
        subgraph "API Server"
            subgraph "Routes Layer"
                AR["authorRoute.js"]:::api
                BR["bookRoute.js"]:::api
                UR["userRoute.js"]:::api
            end
            MW["isAuthenticated.js"]:::api
            subgraph "Controller Layer"
                AC["authorController.js"]:::api
                BC["bookController.js"]:::api
                UC["userController.js"]:::api
            end
            SU["catchAsync.js"]:::api
            subgraph "Model Layer"
                AI["models/index.js"]:::api
                AU["author.js"]:::api
                BU["book.js"]:::api
                UU["user.js"]:::api
                DC["connection.js"]:::api
            end
            CFG["config/config.json"]:::api
            App["src/app.js"]:::api
            Server["server.js"]:::api
        end
        DB["SQLite DB\n(database.sqlite)"]:::db
    end

    subgraph "Migrations & Seeders" 
        MIGA["migrations/migrateAuthor.js"]:::infra
        MIGB["migrations/migrateBooks.js"]:::infra
        SEEDA["seeders/seedAuthor.js"]:::infra
        SEEDB["seeders/seedBooks.js"]:::infra
    end
    ENV[".env"]:::infra
    DOCKERFILE["Dockerfile"]:::infra
    DOCKERIGNORE[".dockerignore"]:::infra
    PKG["package.json"]:::infra
    PKGLOCK["package-lock.json"]:::infra

    Client -->|HTTP Request| AR
    Client -->|HTTP Request| BR
    Client -->|HTTP Request| UR
    AR -->|route handler| MW
    BR -->|route handler| MW
    UR -->|route handler| MW
    MW -->|auth pass| AC
    MW -->|auth pass| BC
    MW -->|auth pass| UC
    AC -->|wrap| SU
    BC -->|wrap| SU
    UC -->|wrap| SU
    SU -->|"business logic"| AU
    SU -->|"business logic"| BU
    SU -->|"business logic"| UU
    AU -->|"Sequelize queries"| DB
    BU -->|"Sequelize queries"| DB
    UU -->|"Sequelize queries"| DB

    MIGA --> CFG
    MIGB --> CFG
    SEEDA --> CFG
    SEEDB --> CFG
    CFG -->|DB config| DB

    Server --> App
    App --> AR
    App --> BR
    App --> UR

    class Client external
    class AR,BR,UR,MW,AC,BC,UC,SU,AI,AU,BU,UU,DC,CFG,App,Server api
    class DB db
    class MIGA,MIGB,SEEDA,SEEDB,ENV,DOCKERFILE,DOCKERIGNORE,PKG,PKGLOCK infra

    click AR "https://github.com/rajanshah23/yipl-backend-2025/blob/main/routes/authorRoute.js"
    click BR "https://github.com/rajanshah23/yipl-backend-2025/blob/main/routes/bookRoute.js"
    click UR "https://github.com/rajanshah23/yipl-backend-2025/blob/main/routes/userRoute.js"
    click MW "https://github.com/rajanshah23/yipl-backend-2025/blob/main/middleware/isAuthenticated.js"
    click AC "https://github.com/rajanshah23/yipl-backend-2025/blob/main/controller/authorController.js"
    click BC "https://github.com/rajanshah23/yipl-backend-2025/blob/main/controller/bookController.js"
    click UC "https://github.com/rajanshah23/yipl-backend-2025/blob/main/controller/userController.js"
    click SU "https://github.com/rajanshah23/yipl-backend-2025/blob/main/services/catchAsync.js"
    click CFG "https://github.com/rajanshah23/yipl-backend-2025/blob/main/config/config.json"
    click App "https://github.com/rajanshah23/yipl-backend-2025/blob/main/src/app.js"
    click Server "https://github.com/rajanshah23/yipl-backend-2025/blob/main/server.js"
    click AU "https://github.com/rajanshah23/yipl-backend-2025/blob/main/models/author.js"
    click BU "https://github.com/rajanshah23/yipl-backend-2025/blob/main/models/book.js"
    click UU "https://github.com/rajanshah23/yipl-backend-2025/blob/main/models/user.js"
    click AI "https://github.com/rajanshah23/yipl-backend-2025/blob/main/models/index.js"
    click DC "https://github.com/rajanshah23/yipl-backend-2025/blob/main/database/connection.js"
    click DB "https://github.com/rajanshah23/yipl-backend-2025/blob/main/sqlite_data/database.sqlite"
    click MIGA "https://github.com/rajanshah23/yipl-backend-2025/blob/main/migrations/migrateAuthor.js"
    click MIGB "https://github.com/rajanshah23/yipl-backend-2025/blob/main/migrations/migrateBooks.js"
    click SEEDA "https://github.com/rajanshah23/yipl-backend-2025/blob/main/seeders/seedAuthor.js"
    click SEEDB "https://github.com/rajanshah23/yipl-backend-2025/blob/main/seeders/seedBooks.js"
    click DOCKERFILE "https://github.com/rajanshah23/yipl-backend-2025/tree/main/Dockerfile"
    click DOCKERIGNORE "https://github.com/rajanshah23/yipl-backend-2025/blob/main/.dockerignore"
    click PKG "https://github.com/rajanshah23/yipl-backend-2025/blob/main/package.json"
    click PKGLOCK "https://github.com/rajanshah23/yipl-backend-2025/blob/main/package-lock.json"
```
