Structure
This is our Node.js TypeScript version of backend with AWS CDK integrated. Let's dive into each folder.
.github
- This folder contains the GitHub workflow and CI/CD configuration files.
cdk
- Structure for an AWS CDK application. Here's a breakdown of the key components shown:
bin: Main entry point for the CDK application where stacks are defined and instantiated.
lib: Core logic of CDK application, further organized into nested directories.
nested: Includes various files defining specific AWS resource stacks:
- acm-stack.ts: Related to AWS Certificate Manager.
- ec2-stack.ts: Defines Amazon EC2 configurations for database access.
- ecs-stack.ts: Contains definitions for Amazon ECS.
- github-oidc-stack.ts: Configures GitHub OIDC for authentication.
- rds-stack.ts: Used for Amazon RDS configurations.
- vpc-stack.ts: Contains the configurations for Amazon VPC.
- cdk-stack.ts: General CDK stack configurations.
prisma
- This folder is dedicated to Prisma, an ORM (Object-Relational Mapping) tool used for interacting with the database in a type-safe manner.
schema.prisma:
- Defines our database schema. It describes the models in our application and their relationships.
seed.ts:
- Used to populate the database with initial data during development or testing.
src
- Structure of a Node.js project using TypeScript. Here’s a brief explanation of each component:
src: Main directory where the source code of the application is stored.
config: Contains config files, such as DB configurations, or other environmental settings.
controllers: Houses the logic for handling requests and responses.
middlewares: Includes functions that can run between receiving the request and sending the response.
routes: Defines the endpoints of your API and connects them to the corresponding controllers.
services: Contains business logic, services are used by controllers.
utils: Stores utility functions that can be used across the application.
validations: Validates data to ensure it matches expected formats or values before processing.
- app.ts: Main application file that sets up the server, connects middleware, and imports routes.
- index.ts: Bootstraps the application by importing app.ts and listening on a port.
tests
- This folder helps in organizing test scripts in a way that they are separate from the main codebase. Test files must all be passed during the CI/CD process.
Other key files
- docker-compose.yml: Uses
Dockerfile.dev
to set up a containerized backend linked to a PostgreSQL DB. - docker-compose.test.yml: Uses
Dockerfile.staging
to run test files. - Dockerfile: Contains the necessary instructions to build a Docker image for the production environment during the CI/CD process.
- Dockerfile.staging: Builds a Docker image specifically tailored for running test files during the CI/CD process in the staging environment.
- Dockerfile.dev: Builds a Docker image specifically tailored for running local backend in the development environment.