NB Backend Architecture Details

Codebase Overview

Name: starter-oracle-shatab

Type: Backend API Server

Purpose: A boilerplate backend for News Portal - a news/media platform

Language: TypeScript

Runtime: Node.js (>=18)

Architecture

Tech Stack

  1. Framework: Express.js
  2. Database: Oracle (via TypeORM)
  3. Authentication: JWT (JSON Web Tokens)
  4. Real-time: WebSocket (ws library)
  5. File Storage: AWS S3 + local uploads
  6. Documentation: Swagger/OpenAPI
  7. Scheduling: node-cron
  8. Validation: Zod
  9. Caching: Node-cache

Directory Structure

src/
├── app.ts # Express app configuration
├── server.ts # Server entry point
├── data-source.ts # TypeORM data source config
├── config/
│ ├── index.ts # Environment config
│ └── swaggerConfig.ts # Swagger setup
├── app/
│ ├── entities/ # TypeORM entity definitions
│ ├── modules/ # Feature modules (News, Auth, Users, etc.)
│ ├── route/ # Express router
│ ├── middleware/ # Express middleware
│ ├── helper/ # Utility functions
│ ├── interface/ # Repository interfaces
│ ├── DB/ # Database connection
│ └── error/ # API error handling
└── shared/
└── catchAsync.ts # Async handler wrapper

Core Features

1. Entity Models (Database Tables)

The application uses TypeORM with Oracle and defines these main entities:

EntityDescription
NewsArticles with title, description, images, tags, location (division/district/upazila), scheduling
AdminsAdmin users with role-based access control
BulletinsNews bulletins/categories
AdsAdvertisements
VideosVideo content
PollsVoting polls linked to parties
PartyPolitical parties for voting
CategoryContent categorization
CommentsUser comments on news
MenofestosManifestos
EResultImagesElection result images

2. Module Structure (by feature)

Each module follows MVC-like pattern:

modules/
├── Auth/
│ ├── auth.controller.ts # Login, token generation
│ ├── auth.router.ts # Routes
│ └── auth.validation.ts # Zod validation
├── News/
├── Users/
├── Advertise/
├── Videos/
├── Poll/
└── Ramadan/

3. Authentication Flow

  1. Login via /api/v1/auth/login with email/password
  2. JWT token generated (30-day expiry)
  3. Token verification via auth middleware
  4. Role-based access: super_admin bypasses role checks

4. Key Middleware

  1. auth.ts - JWT authentication and role checking
  2. checkClient.ts - Client identification
  3. globalErrorHandler.ts - Centralized error handling
  4. validateRequest.ts - Zod request validation

5. Cron Jobs

Automatically publishes scheduled news when scheduledTime arrives (runs every minute).

API Routes

All routes are under /api/v1/:

/api/v1/
├── users - User management
├── auth - Authentication (login, tokens)
├── news - News CRUD operations
├── advertise - Advertisements
├── videos - Video content
├── poll - Polling system
└── ramadan - Ramadan-specific content

Plus:

  1. /api/token - Token generation endpoint
  2. /api-docs - Swagger documentation
  3. /media, /uploads - Static file serving

Database Configuration

Dual configuration approach:

  1. data-source.ts - Simple config with hardcoded values (dev placeholder)
  2. app/DB/database.config.ts - Environment-based config with Oracle connection

Uses Oracle database with SID/service_name mypdb/XE, port 1521.

Key Dependencies

  1. TypeORM - ORM for Oracle database
  2. OracleDB - Official Oracle driver
  3. JWT + bcryptjs - Authentication and password hashing
  4. AWS SDK + multer-s3 - S3 file uploads
  5. node-cron - Scheduled tasks
  6. Zod - Request validation
  7. Swagger - API documentation

This is a production-ready news media backend with multi-module content management, designed for News Portal's news, video, polling, and advertising needs.




===================================================



TypeScript backend starter boilerplate built with:

  1. Express.js for APIs/server
  2. TypeORM for database access
  3. Oracle Database via oracledb
  4. Authentication, file upload, Swagger docs, cron jobs, caching, WebSocket support, etc.

It is structured as a production-ready backend template for scalable REST APIs.

1. High-Level Architecture

Your project follows a layered backend architecture:

Client
Express Routes
Controllers
Services
Database Layer (TypeORM + OracleDB)

Typical flow:

HTTP Request
→ Route
→ Controller
→ Service
→ Repository/Entity
→ Oracle Database
→ Response

2. package.json Breakdown

Project Metadata


{
"name": "starter-oracle-shatab",
"version": "1.0.0"
}

Defines:

  1. package name
  2. versioning
  3. npm publishing metadata

Main Entry


"main": "dist/server.js",
"types": "dist/server.d.ts"

After build:

src/server.ts
dist/server.js

types exposes TypeScript declarations when used as a package.

Files


"files": ["dist"]

When publishing to npm, only dist/ is included.

Good practice.

3. Scripts Explained

Start Production Server


"start": "node ./dist/server.js"

Runs compiled JavaScript.

Production flow:


npm run build
npm start

Development Mode


"dev": "ts-node-dev --respawn --transpile-only src/server.ts"

What happens:

  1. watches file changes
  2. restarts automatically
  3. runs TS directly without build

Flags

FlagMeaning
--respawnrestart process on crash/change
--transpile-onlyskips type checking for speed

Very common dev setup.

Build


"build": "tsgo"

Interesting part.

Normally people use:


tsc

But here:


tsgo

Likely:

  1. faster TypeScript compiler wrapper
  2. experimental/native TS compiler
  3. using:

"@typescript/native-preview"

This suggests you're experimenting with Microsoft's new native TS compiler.

Fallback build:


"build:old": "tsc"

Lint


"lint": "eslint src --ignore-path .eslintignore --ext .ts"

Checks code quality and style.

4. Database Layer

Core Database Packages


"oracledb": "^6.3.0",
"typeorm": "^0.3.27",
"reflect-metadata": "^0.1.13"

Architecture

TypeORM
OracleDB Driver
Oracle Database

TypeORM Purpose

TypeORM allows:

  1. Entities
  2. Repositories
  3. Migrations
  4. Query Builder
  5. Relations
  6. Decorators

Example:


@Entity()
class User {
@PrimaryGeneratedColumn()
id: number;

@Column()
email: string;
}

Instead of raw SQL everywhere.

reflect-metadata

Required because TypeORM uses decorators.

Without it:


@Entity()
@Column()

won't work.

Usually imported once in server.ts:


import "reflect-metadata";

5. Migration System

These scripts are currently disabled/commented conceptually:


"migration:generate"
"migration:run"
"migration:revert"

They use:


typeorm-ts-node-commonjs

Meaning migrations run directly in TypeScript.

Migration Flow

Generate migration


npm run migration:generate

Compares entities vs database.

Run migration


npm run migration:run

Executes pending schema changes.

Revert


npm run migration:revert

Rollback last migration.

6. API Layer Packages

Express


"express": "^4.21.2"

Main HTTP server framework.

Likely structure:

src/
├── app/
├── routes/
├── controllers/
├── services/
├── middlewares/
└── server.ts

CORS


"cors"

Allows frontend apps to access backend APIs.

Example:


app.use(cors())

Compression


"compression"

Gzip compression for responses.

Improves performance.

Morgan


"morgan"

HTTP request logger.

Example log:

GET /users 200 15ms

7. Authentication & Security

JWT


"jsonwebtoken"

Token-based authentication.

Typical flow:

Login
→ Generate JWT
→ Client stores token
→ Client sends Authorization header
→ Middleware verifies token

bcryptjs


"bcryptjs"

Password hashing.

Example:


const hashed = await bcrypt.hash(password, 10)

Never store plain passwords.

8. Validation

Zod


"zod"

Modern schema validation library.

Example:


const schema = z.object({
email: z.string().email(),
})

Used for:

  1. request validation
  2. DTO validation
  3. environment validation

Excellent choice.

9. File Upload System

Multer


"multer"

Handles multipart/form-data uploads.

AWS S3


"@aws-sdk/client-s3"
"multer-s3"

Means uploads likely go directly to S3.

Flow:

Client Upload
→ Multer
→ multer-s3
→ AWS S3 Bucket

Scalable approach.

10. API Documentation

Swagger


"swagger-jsdoc"
"swagger-ui-express"

Auto-generates API docs.

Usually exposed at:

/api-docs

Allows frontend developers to test APIs visually.

11. Background Jobs & Scheduling

node-cron


"node-cron"

Runs scheduled tasks.

Examples:

  1. cleanup jobs
  2. sending emails
  3. nightly syncs
  4. report generation

Example:


cron.schedule("0 0 * * *", () => {
console.log("Runs daily")
})

12. Caching

node-cache


"node-cache"

In-memory caching.

Useful for:

  1. OTP caching
  2. temporary session data
  3. API response cache

Example:


cache.set("user_1", userData)

13. Email System

Nodemailer


"nodemailer"

Used for:

  1. OTP emails
  2. password reset
  3. notifications

Typical flow:

Backend
→ SMTP
→ User Email

14. Real-Time Communication

ws


"ws": "^8.18.3"

Native WebSocket support.

Used for:

  1. live notifications
  2. chats
  3. dashboards
  4. realtime updates

15. Development Tooling

ts-node

Runs TS directly.

ts-node-dev

Hot reload dev server.

tsx

Modern TS runtime alternative.

TypeScript


"typescript": "^5.9.3"

Core language.

16. Interesting Design Decisions

OracleDB Instead of PostgreSQL/MySQL

This project is enterprise-oriented.

Oracle is common in:

  1. banking
  2. telecom
  3. government
  4. ERP systems

TypeORM + Oracle

This combo indicates:

  1. enterprise backend
  2. relational-heavy systems
  3. strong schema modeling

Native TypeScript Preview

This is advanced/experimental:


"@typescript/native-preview"

Very few starter projects use this yet.

17. Expected Folder Structure

Based on dependencies, likely something like:

src/
├── app/
│ ├── config/
│ │ └── database.config.ts
│ ├── modules/
│ │ ├── user/
│ │ ├── auth/
│ │ └── ...
│ ├── middlewares/
│ ├── utils/
│ ├── services/
│ └── routes/
├── server.ts
└── types/

18. Typical Request Lifecycle

Example:

POST /auth/login

Flow:

Route
→ Validation Middleware (Zod)
→ Controller
→ Service
→ TypeORM Repository
→ OracleDB
→ JWT Generation
→ Response

19. Strengths of This Boilerplate

✅ Type-safe

✅ Enterprise-ready

✅ OracleDB support

✅ Swagger docs

✅ JWT auth ready

✅ File uploads ready

✅ WebSocket support

✅ Cron jobs

✅ Scalable architecture

✅ Production-oriented setup

20. Potential Improvements

You could later add:

  1. Prisma support
  2. Redis caching
  3. Docker
  4. CI/CD
  5. Unit testing
  6. Role-based access control
  7. Rate limiting
  8. Helmet security
  9. OpenTelemetry logging
  10. Queue system (BullMQ)

21. One Important Observation

Your description says:


"Express, Prisma, TypeScript"

But dependencies actually use:

TypeORM
NOT Prisma

So the description is outdated/inconsistent.

You should update:


"description"

to something like:


"A starter backend boilerplate with Express, TypeScript, OracleDB, TypeORM, and common backend utilities."

22. Overall Summary

This is a:

Enterprise-grade TypeScript backend starter template focused on OracleDB systems using Express + TypeORM architecture.

It is designed for:

  1. scalable APIs
  2. enterprise apps
  3. authentication systems
  4. real-time systems
  5. file-heavy systems
  6. modular backend architecture

and is much more advanced than a beginner Express starter.