Skip to content

5dr/digitinary_challenge

Repository files navigation

# Digitinary TMDB Challenge — Backend (Node.js + TypeScript + TSOA)

## Overview

This project is a **backend API** built using **Node.js**, **TypeScript**, and **TSOA** for automatic OpenAPI (Swagger) documentation generation.  
It provides APIs for **user management** (register, login, update) and **movie management** (listing, filtering, rating, and favorites).

The stack integrates **MySQL** as the main relational database and **Redis** for caching to optimize performance and reduce database load.

---

## 🧩 Tech Stack

- **Node.js** + **TypeScript**
- **Express.js** + **TSOA**
- **Sequelize ORM (MySQL)**
- **Redis (Caching Layer)**
- **Jest (Unit Testing Framework)**
- **Docker + Docker Compose**
- **InversifyJS (Dependency Injection)**

---

## 🧱 Architecture Overview

### 🧩 Modular Layered Design

src/
┣ modules/
┃ ┣ users/ → user registration, authentication, update, profile
┃ ┗ movie/ → movies listing, rating, favorites, filtering logic
┣ config/ → environment setup, redis and database configuration
┣ db/ → sequelize models, migrations, and associations
┣ utils/ → helper functions, HttpException, validation utils
┣ tests/ → Jest test files (unit/integration)
┗ server.ts → main application entry point


### 🧠 Layer Responsibilities

| Layer | Responsibility |
|--------|----------------|
| **Controller** | Handles HTTP routes and responses |
| **Service** | Business logic + data manipulation |
| **Model** | Sequelize models and DB relations |
| **Validation** | Joi schemas and request validation |
| **Utils** | Common reusable helpers and error handlers |

---

## 🧠 System Architecture (Flow Diagram)

```mermaid
graph TD
    A[Client Request] --> B[Controller Layer]
    B --> C[Service Layer]
    C --> D[(MySQL Database)]
    C --> E[(Redis Cache)]
    E -->|Cache Hit| F[Return Cached Response]
    D -->|Cache Miss| G[Query Database and Update Cache]
    G --> F
    F --> H[Response to Client]


✅ Testing Strategy

Jest for full test coverage.

Each module (users, movies, helpers) has its own test suite.

Mocked Sequelize + Redis to isolate logic.

Coverage report included (npm run test:cov).

✅ Validation

Centralized Joi validation schemas.

All validation errors throw custom HttpException(422, message).

1️⃣ Clone the repository
git clone https://github.com/<your-username>/digitinary-challenge.git
cd digitinary-challenge

2️⃣ Install dependencies
npm install

3️⃣ Start MySQL & Redis locally

Option 1 — via Docker:

docker run --name tmdb-mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -e MYSQL_DATABASE=tmdb -p 3306:3306 -d mysql:8.0
docker run --name tmdb-redis -p 6379:6379 -d redis:7-alpine


Option 2 — install manually:

Start MySQL server on port 3306

Start Redis server on port 6379

4️⃣ Run database migrations
npm run createTable

5️⃣ Run the application
npm run dev

6️⃣ Access Swagger Docs
http://localhost:8080/docs

🧪 Running Tests
Run all test suites
npm test

Run tests with coverage
npm run test:cov

🐳 Running with Docker
1️⃣ Build Docker images
docker-compose build

2️⃣ Start all containers
docker-compose up -d

3️⃣ Verify containers
docker ps

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published