# nisargchokshi45/task4nodedynamodb architecture

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

- Interactive diagram: https://gitdiagram.com/nisargchokshi45/task4nodedynamodb
- Repository: https://github.com/nisargchokshi45/task4nodedynamodb

## Overview

##### Project type and purpose
- Type: A RESTful CRUD API (backend only) built with Node.js and Express, persisting movie records in AWS DynamoDB.
- Purpose: Expose endpoints to add, update, query and delete movies, supporting filters by year, letter, and range.

##### File structure
- src/server.js
– The entry point: spins up the Express HTTP server.
- src/app.js
– Configures Express app, middleware (body-parser, morgan, dotenv).
- src/routes/routes.js
– Declares all routes (e.g. POST /movies, GET /movies/:id, etc.) and binds them to controllers.
- src/controllers/
– defaultController.js handles unmatched routes.
– movies.controller.js contains handler functions for each CRUD operation.
– movies.validator.js enforces payload/schema validation with Joi.
- src/models/movie.js
– Defines the Movie domain model / data schema used by the data-access layer.
- src/utils/awsConfiguration.js
– Initializes and configures the AWS SDK DynamoDB client (region, credentials, endpoint).
- src/utils/errorFunction.js
– Central error-formatting helper.
- src/data/movieData.json
– Sample JSON used for tests or initial population.
- Test support (jest.config.js, jest-dynamodb-config.js, src/tests/…)
– Local DynamoDB emulation and unit/integration tests.

##### README for architectural clues
- Clearly calls out dependencies: aws-sdk, express, joi, body-parser, dotenv, morgan.
- Lists all exposed functionalities (CRUD operations with various query filters).
- No frontend—pure backend microservice.

##### Main components and relationships

a. Client / Consumer
– e.g., Postman, Web UI, another service invoking HTTP calls.

b. API Layer (Express App)
– Inside it, two sub-layers:
- Router (routes/routes.js)
- Middleware (body-parser, morgan, error handler)

c. Controller Layer

d. Data-Access / Model Layer

e. Persistence

f. Utilities & Configuration

##### Architectural patterns & principles
- Layered architecture (Presentation / API → Controllers → Domain Model → Data Access)
- Single responsibility: each file focuses on exactly one concern (routing, validation, business logic, data).
- Dependency injection via configuration (AWS client) and environment variables.
- Testability: separation of AWS client init for mocking (jest-dynamodb).

##### Detailed elements to capture
- Entry point (server.js) and configuration flow (dotenv → awsConfiguration).
- Middleware sequence (body-parser → morgan → routes → error handler).
- Validation step (movies.validator) before business logic.
- Data-access calls (AWS.DynamoDB.DocumentClient methods: get, put, scan, delete).

[Client]
|
v
[Express Server (server.js)]
|
v
[Router Layer (routes.js)]
|
v
[Controllers]
├─ movies.validator (Joi)
└─ movies.controller
|
v
[Model (movie.js)]
|
v
[AWS SDK DynamoDB Client (awsConfiguration.js)]
|
v
[DynamoDB “Movies” Table]

Green = Runtime modules
Blue = Data structures/storage
Orange = Configuration & external services

## Diagram (Mermaid)

```mermaid
flowchart TB
    Client["Client / Consumer"]:::external
    Client -->|"HTTP Request"| Server

    Server["Express Server\n(src/server.js)"]:::runtime
    Server -->|"initializes"| App

    App["Express App\n(src/app.js)"]:::runtime
    App -->|"uses"| BodyParser
    App -->|"uses"| Morgan
    App -->|"loads env"| Env
    App -->|"registers routes"| Routes
    App -->|"registers error handler"| ErrorFunc

    BodyParser["body-parser"]:::runtime
    Morgan["morgan"]:::runtime
    Env["dotenv (.env)"]:::config
    ErrorFunc["Error Utility\n(src/utils/errorFunction.js)"]:::config

    Routes["Router Layer\n(src/routes/routes.js)"]:::runtime
    Routes -->|"routes to"| MoviesValidator
    Routes -->|"routes to"| MoviesController
    Routes -->|"routes to"| DefaultController

    MoviesValidator["movies.validator\n(src/controllers/movies/movies.validator.js)"]:::runtime
    MoviesController["movies.controller\n(src/controllers/movies/movies.controller.js)"]:::runtime
    DefaultController["defaultController\n(src/controllers/defaultController.js)"]:::runtime

    MoviesValidator -->|"validates"| MoviesController
    MoviesController -->|"invokes"| MovieModel
    DefaultController -->|"formats error via"| ErrorFunc

    MovieModel["Movie Model\n(src/models/movie.js)"]:::data
    MovieModel -->|"uses AWS SDK"| AWSConfig

    AWSConfig["AWS SDK Client\n(src/utils/awsConfiguration.js)"]:::config
    AWSConfig -->|"API call"| Dynamo

    Dynamo["DynamoDB Table\n\"Movies\""]:::data

    SampleData["Sample Movie Data\n(src/data/movieData.json)"]:::data

    classDef runtime fill:#e0f7e0,stroke:#2d662d,color:#000;
    classDef data fill:#e0f0ff,stroke:#004080,color:#000;
    classDef config fill:#fff4e5,stroke:#bb650b,color:#000;
    classDef external fill:#f0f0f0,stroke:#999999,color:#000;

    click Server "https://github.com/nisargchokshi45/task4nodedynamodb/blob/master/src/server.js"
    click App "https://github.com/nisargchokshi45/task4nodedynamodb/blob/master/src/app.js"
    click Routes "https://github.com/nisargchokshi45/task4nodedynamodb/blob/master/src/routes/routes.js"
    click DefaultController "https://github.com/nisargchokshi45/task4nodedynamodb/blob/master/src/controllers/defaultController.js"
    click MoviesController "https://github.com/nisargchokshi45/task4nodedynamodb/blob/master/src/controllers/movies/movies.controller.js"
    click MoviesValidator "https://github.com/nisargchokshi45/task4nodedynamodb/blob/master/src/controllers/movies/movies.validator.js"
    click MovieModel "https://github.com/nisargchokshi45/task4nodedynamodb/blob/master/src/models/movie.js"
    click AWSConfig "https://github.com/nisargchokshi45/task4nodedynamodb/blob/master/src/utils/awsConfiguration.js"
    click ErrorFunc "https://github.com/nisargchokshi45/task4nodedynamodb/blob/master/src/utils/errorFunction.js"
    click SampleData "https://github.com/nisargchokshi45/task4nodedynamodb/blob/master/src/data/movieData.json"
```
