How nisargchokshi45/task4nodedynamodb works
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