I want to build a webapp based on hexagonal architecture… · The Chat Archive
Explore / Human feedback I want to build a webapp based on hexagonal architecture. I am using typescript and aws… Save Share Download ▾ ReportI want to build a webapp based on hexagonal architecture. I am using typescript and aws lambda and other serverless technologies. Could you give me the folder strucuture for my code under hexagonal architecture?
Sure, I'd be happy to help you structure your project using the Hexagonal Architecture (also known as Ports and Adapters) with TypeScript and AWS Lambda. Here's a suggested folder structure:
/my-webapp
├── src
│ ├── application
│ │ ├── use_cases
│ │ │ ├── UseCase1.ts
│ │ │ └── UseCase2.ts
│ │ └── ports
│ │ ├── Port1.ts
│ │ └── Port2.ts
│ ├── domain
│ │ ├── Entity1.ts
│ │ └── Entity2.ts
│ ├── infrastructure
│ │ ├── adapters
│ │ │ ├── Adapter1.ts
│ │ │ └── Adapter2.ts
│ │ ├── database
│ │ │ ├── DatabaseConnection.ts
│ │ │ └── DatabaseSchema.ts
│ │ └── aws
│ │ ├── LambdaFunction1.ts
│ │ └── LambdaFunction2.ts
│ └── config
│ └── index.ts
├── test
│ ├── use_cases
│ │ ├── UseCase1.test.ts
│ │ └── UseCase2.test.ts
│ ├── adapters
│ │ ├── Adapter1.test.ts
│ │ └── Adapter2.test.ts
│ └── aws
│ ├── LambdaFunction1.test.ts
│ └── LambdaFunction2.test.ts
├── package.json
├── tsconfig.json
└── README.md
Certainly! Here's a more detailed explanation of the folders and files:
src: This is where your source code lives.
application: This layer contains application use cases and ports (interfaces) that define the expected behavior of adapters.
use_cases: This folder contains the implementation of your application use cases. Each use case should have its own file.
: This folder contains the interfaces that define the expected behavior of adapters. Each port should have its own file.
Could you give me the example code for UserUseCase.ts and ProductUseCase.ts?
Create a new folder called api in the root of your project.
Inside the api folder, create a new file called index.ts. This file will serve as the entry point for your API.
In the index.ts file, import the necessary modules and define the routes for your API.
Here's an example of how you can structure the api folder and the index.ts file:
/my-webapp
├── api
│ ├── index.ts
│ ├── routes
│ │ ├── userRoutes.ts
│ │ ├── productRoutes.ts
│ │ └── ...
│ └── controllers
│ ├── UserController.ts
│ ├── ProductController.ts
│ └── ...
├── src
│ ├── application
│ ├── domain
│ ├── infrastructure
│ └── ...
├── test
│ ├── ...
├── package.json
├── tsconfig.json
└── README.md
Copy first prompt Copy first response
Other models, same or similar prompt Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Details
Model Unknown
Provider unknown
Model provenance As recorded by source dataset
Turns 3 (6 messages)
Language —
Added to archive Nov 22, 2026
ID 01m80tz6rxema3cr3a9s5bvgyfSource & license Imported from NVIDIA HelpSteer3 Preference (source ). Imported records earn no Research Points.
Upstream record: preference/train.jsonl.gz:383:response2
nvidia/HelpSteer3, revision f6d145777bcbde96137596340fab89793acd1031. Original NVIDIA preference release. Each response becomes a separate transcript retaining its shared context. Generator identity is not supplied per row. Dialogue normalized; system instructions, tools and private metadata omitted.
License: CC-BY-4.0
Dataset releases Not yet included in a published release.
Here's a brief explanation of the folders:
src: This is where your source code lives.
application: This layer contains application use cases and ports (interfaces) that define the expected behavior of adapters.
domain: This layer contains your business logic and domain entities.
infrastructure: This layer contains the implementation details of your adapters, database connections, and AWS Lambda functions.
config: This is where you can put your configuration files.
test: This is where your test files live. The structure should mirror your src folder.
package.json: This file contains your project dependencies and scripts.
tsconfig.json: This file is used to specify the root files and the compiler options required to compile the project.
README.md: This file is used to document your project.
ports
domain: This layer contains your business logic and domain entities.
Entity1.ts: This file contains the definition of a domain entity.
Entity2.ts: This file contains the definition of another domain entity.
infrastructure: This layer contains the implementation details of your adapters, database connections, and AWS Lambda functions.
adapters: This folder contains the implementation of your adapters. Each adapter should have its own file.
database: This folder contains the implementation details of your database connections and schema.
aws: This folder contains the implementation details of your AWS Lambda functions. Each Lambda function should have its own file.
config: This is where you can put your configuration files.
index.ts: This file exports your configuration objects.
test: This is where your test files live. The structure should mirror your src folder.
use_cases: This folder contains the tests for your application use cases. Each use case should have its own test file.
adapters: This folder contains the tests for your adapters. Each adapter should have its own test file.
aws: This folder contains the tests for your AWS Lambda functions. Each Lambda function should have its own test file.
package.json: This file contains your project dependencies and scripts.
tsconfig.json: This file is used to specify the root files and the compiler options required to compile the project.
README.md: This file is used to document your project.By following this structure, you can keep your code organized and maintainable, and make it easier to test and deploy your application.
Here's an example of how you can define the routes and controllers for the User and Product resources:
import { Router } from 'express';
import { UserController } from '../controllers/UserController';
const router = Router();
router.get('/', UserController.list);
router.get('/:id', UserController.findById);
router.post('/', UserController.create);
router.put('/:id', UserController.update);
router.delete('/:id', UserController.delete);
export default router;
controllers/UserController.ts:
import { Request, Response, NextFunction } from 'express';
import { User } from '../domain/User';
export const list = async (req: Request, res: Response) => {
// Retrieve all users from the database and send them as a response
};
export const findById = async (req: Request, res: Response) => {
// Retrieve a user by ID from the database and send it as a response
};
// Define the other CRUD operations for the User resource
By following this structure, you can keep your API code organized and maintainable, and make it easier to test and deploy your application.