TODO:
- Briefly describe what the Car Inventory Application does.
- What are its main goals and objectives?
- Who is the target audience or users for this application?
- What key problems does it solve or what value does it provide?
TODO:
- Briefly explain the top-level directory structure:
frontend/: Contains the React/Next.js frontend application.backend/: Houses the AWS Lambda functions (Node.js) for business logic.infra/: Includes Infrastructure as Code (IaC) using AWS CDK (TypeScript) for defining AWS resources..github/workflows/: CI/CD pipeline configurations for GitHub Actions.tests/: Placeholder for End-to-End tests.
- Mention key technologies used (React, Node.js, AWS Lambda, API Gateway, DynamoDB, Cognito, CDK, Amplify, CodePipeline).
- Node.js (e.g., v18.x or later) & npm: [Link to Node.js installation]
- AWS CLI configured: [Link to AWS CLI installation and configuration guide]
- Ensure you have an AWS profile configured with necessary permissions.
- AWS CDK Toolkit:
npm install -g aws-cdk(or ensure it's a dev dependency ininfra/cdk/package.json) - Git: [Link to Git installation]
- (Optional) Docker Desktop (if running local DynamoDB or other services in containers).
- Clone the repository:
git clone https://github.com/YOUR_GITHUB_OWNER/car-inventory-app.git cd car-inventory-app - Install Frontend Dependencies:
cd frontend npm ci # TODO: Add command if using Yarn (yarn install --frozen-lockfile) cd ..
- Install Backend Lambda Dependencies:
- Each Lambda function with dependencies has its own
package.json. - Example for
createVehicleLambda:
cd backend/lambdas/createVehicle npm ci cd ../../..
- TODO: List other Lambdas that require
npm ci(e.g.,getVehicle,searchVehiclesif they have specific deps,calculateKBB,booksheetOCRstubs).
- Each Lambda function with dependencies has its own
- Install CDK Project Dependencies:
cd infra/cdk npm ci cd ../..
- Configure Environment Variables (Frontend):
- Copy
frontend/.env.exampletofrontend/.env.local. - Fill in the required values in
frontend/.env.local. These will typically come from your deployed AWS backend resources (Cognito IDs, API URL). See section "5. Environment Variables" for details.
- Copy
cd frontend
# TODO: Verify and update the dev script name if different from "npm run dev"
npm run dev- Access the frontend at
http://localhost:3000(or the port specified by your dev server). - TODO: Add note about configuring
REACT_APP_API_URLinfrontend/.env.localto point to your deployed staging API Gateway or a local mock.
- Bootstrap CDK (if first time in an AWS account/region):
TODO: Clarify which context variables are essential for a local/staging bootstrap and deploy. The GitHub placeholders are likely not needed for a local deploy of core stacks unless CiCdPipelineStack is included.
cd infra/cdk # Replace YOUR_AWS_ACCOUNT_ID and YOUR_AWS_REGION with your actual details cdk bootstrap aws://YOUR_AWS_ACCOUNT_ID/YOUR_AWS_REGION \ -c env=staging \ -c projectPrefix=CarInv \ # Add other necessary context variables as defined in cdk.json or app.ts (e.g., github placeholders)
- Synthesize CloudFormation Templates (Optional Check):
cd infra/cdk cdk synth -c env=staging # Add other context vars if needed
- Deploy Core Stacks to Staging:
- It's recommended to deploy stacks individually or in logical groups first.
cd infra/cdk # Deploy Auth stack cdk deploy CarInv-staging-AuthStack -c env=staging # Deploy Database stack cdk deploy CarInv-staging-DatabaseStack -c env=staging # Deploy Compute stack (API and Lambdas for core features) cdk deploy CarInv-staging-ComputeStack -c env=staging
- TODO: Confirm stack names are correct based on
app.tsinstantiation (e.g.,CarInv-staging-AuthStack). - TODO: Note that
CiCdPipelineStackis usually not deployed manually for local dev. - After deployment, update
frontend/.env.localwith the outputs (Cognito IDs, API Gateway URL).
REACT_APP_API_URL: URL of the deployed API Gateway (e.g.,https://api-id.execute-api.region.amazonaws.com/staging).REACT_APP_REGION: AWS region where backend is deployed (e.g.,us-east-1).REACT_APP_COGNITO_USER_POOL_ID: Cognito User Pool ID.REACT_APP_COGNITO_APP_CLIENT_ID: Cognito User Pool App Client ID.REACT_APP_COGNITO_IDENTITY_POOL_ID(Optional): If using Cognito Identity Pool for unauthenticated access.- TODO: List any other custom frontend environment variables.
VEHICLES_TABLE_NAME: Name of the DynamoDB table for vehicles.REGION: AWS region of the Lambda and other services.COGNITO_USER_POOL_ID: Cognito User Pool ID (can be used for token validation or other Cognito interactions within Lambdas if necessary, though API Gateway handles auth).KBB_API_KEY_SECRET_ARN(ForcalculateKBBLambda): ARN of the Secrets Manager secret holding the KBB API key.TEXTRACT_SNS_TOPIC_ARN(ForbooksheetOCR/textractService): ARN of the SNS topic Textract publishes to.TEXTRACT_ROLE_ARN(ForbooksheetOCR/textractService): ARN of the IAM role Textract assumes for SNS access.- TODO: List any other Lambda-specific environment variables.
env: (Required) Deployment environment (e.g.,staging,production,dev).projectPrefix: Project prefix for resource naming (default:CarInv).githubOwner: GitHub repository owner (forCiCdPipelineStack).githubRepo: GitHub repository name (forCiCdPipelineStack).githubConnectionArn: AWS CodeStar Connection ARN for GitHub (forCiCdPipelineStack).- TODO: List any other CDK context variables.
developbranch:- Represents the staging environment.
- Pushes to
developtrigger:- Frontend (AWS Amplify): Automatic build, test, and deploy to the staging frontend URL (e.g.,
https://develop.YOUR_AMPLIFY_APP_ID.amplifyapp.com). - Backend (AWS CodePipeline): Automatic build, test, CDK synth, and deploy of backend stacks (Auth, Database, Compute, etc.) to the staging environment in AWS.
- Frontend (AWS Amplify): Automatic build, test, and deploy to the staging frontend URL (e.g.,
mainbranch:- Represents the production environment.
- Pushes to
maintrigger:- Frontend (AWS Amplify): Automatic build, test, and deploy to the production frontend URL (e.g.,
https://YOUR_DOMAIN.com). - Backend (AWS CodePipeline): Automatic build, test, CDK synth, and deploy of backend stacks to the production environment in AWS.
- TODO: Mention if manual approval steps are planned for production deployment in CodePipeline.
- Frontend (AWS Amplify): Automatic build, test, and deploy to the production frontend URL (e.g.,
- Feature branches (
feature/...):- Create feature branches from
develop. - Make changes, commit, and push.
- Create Pull Requests (PRs) to merge back into
develop. - PRs to
developormainshould trigger CI checks (linting, tests) via GitHub Actions (frontend-ci.yml,backend-ci.yml).
- Create feature branches from
- Create Lambda Directory:
- In
backend/lambdas/, create a new directory for your Lambda (e.g.,myNewFunction).
- In
- Implement Handler:
- Create
handler.js(or.ts) with your Lambda logic. - Add
validation.jsif needed for input validation (e.g., using Joi). - Create
package.jsonif your Lambda has specific dependencies and runnpm ciornpm install.
- Create
- Update CDK (e.g.,
ComputeStack.ts):- Define a new
lambda.Functionresource, pointing to your Lambda's code. - Set environment variables, memory, timeout, and IAM permissions.
- Grant necessary permissions (e.g.,
myTable.grantReadData(myNewFunction)).
- Define a new
- Integrate with API Gateway (if applicable):
- In
ComputeStack.ts, add a new API Gateway resource/method and link it to your Lambda. - Secure it with the Cognito authorizer if needed.
- In
- Update Backend CI/CD:
- If your new Lambda has dependencies, ensure
npm ciis run for its directory in.github/workflows/backend-ci.yml(CodeBuild buildspec withinCiCdPipelineStack.tsalready attempts this for all lambda folders with package.json). - Add tests for the new Lambda.
- If your new Lambda has dependencies, ensure
- Choose or Create a Stack:
- Add the resource to an existing relevant stack in
infra/cdk/stacks/(e.g.,StorageStack.tsfor S3,OcrPipelineStack.tsfor SQS in the OCR flow). - Or, create a new stack file if it represents a new logical component.
- Add the resource to an existing relevant stack in
- Define the Resource:
- Use CDK constructs to define the resource (e.g.,
new sqs.Queue(...),new s3.Bucket(...)). - Configure properties, permissions, and outputs as needed.
- Use CDK constructs to define the resource (e.g.,
- Update
app.ts:- If you created a new stack, import and instantiate it in
infra/cdk/bin/app.ts. - Pass any necessary props or outputs from other stacks.
- If you created a new stack, import and instantiate it in
- Update CI/CD Pipeline (
CiCdPipelineStack.ts):- If you created a new stack that needs to be deployed, add a new
CloudFormationCreateUpdateStackActionto the deploy stage inCiCdPipelineStack.ts. - Ensure its template is included in the CodeBuild artifacts.
- If you created a new stack that needs to be deployed, add a new
- Frontend (Jest & React Testing Library):
- TODO: Describe how to run frontend unit tests (e.g.,
npm testinfrontend/directory). - TODO: Mention what should be tested (components, services, utility functions).
- TODO: Specify location for test files (e.g.,
frontend/src/**/*.test.tsx).
- TODO: Describe how to run frontend unit tests (e.g.,
- Backend Lambdas (Jest):
- TODO: Describe how to run Lambda unit tests (e.g.,
npm testin individual Lambda directories or a root backend test script). - Test handlers, validation logic (
validation.js), and any helper modules. - Mock AWS SDK calls (e.g.,
dbClient.jsinteractions) and external dependencies. - Example test files:
backend/lambdas/createVehicle/test_createVehicle.js.
- TODO: Describe how to run Lambda unit tests (e.g.,
- CDK Infrastructure (Jest):
- TODO: Describe how to run CDK unit tests (e.g.,
npm testininfra/cdk/directory). - Use CDK's assertions library (
aws-cdk-lib/assertions) to test synthesized CloudFormation templates for resource properties, counts, etc.
- TODO: Describe how to run CDK unit tests (e.g.,
- TODO: Describe strategy for integration tests (e.g., testing API Gateway endpoints with live Lambdas and DynamoDB in a staging environment).
- This might involve using tools like Postman, Newman, or custom scripts.
- Framework: Placeholder (e.g., Cypress, Playwright) - see
tests/e2e/README.md. - TODO: Describe how to run E2E tests once implemented.
- E2E tests will cover full user flows through the UI against a deployed environment.
- Frontend Build/Run Issues:
- Check Node.js/npm versions.
- Ensure all dependencies are installed (
npm ciinfrontend/). - Verify
.env.localconfiguration, especiallyREACT_APP_API_URLand Cognito IDs. - Check browser console for errors.
- Backend Deployment (CDK) Issues:
- Ensure AWS CLI is configured correctly with appropriate permissions.
- Check CDK bootstrap status for the account/region.
- Verify context variables (
-c env=...) are passed correctly tocdk deploy. - Examine CloudFormation console for detailed error messages on stack failures.
cdk diffcan show pending changes before deployment.
- API Gateway / Lambda Errors:
- Check CloudWatch Logs for your Lambda functions. Enable detailed logging in handlers.
- Test API Gateway endpoints with tools like Postman or
curl, ensuring correct headers (Authorization for protected routes). - Verify IAM permissions for Lambdas (e.g., DynamoDB access, Secrets Manager access).
- CI/CD Pipeline Failures:
- Amplify (Frontend): Check build logs in the Amplify console.
- CodePipeline (Backend): Examine logs for CodeBuild stage and CloudFormation deployment events.
- GitHub Actions: Review workflow run logs for linting/testing errors.
- TODO: Add more specific common errors and their solutions as the project develops.
- AWS Resources (CDK):
- General Pattern:
${projectPrefix}-${envName}-${ResourceName}(e.g.,CarInv-staging-VehiclesTable). - Lambdas:
CarInv-${envName}-createVehicle - API Gateway:
CarInv-${envName}-Api - DynamoDB Table:
CarInv-${envName}-VehiclesTable - Cognito User Pool:
CarInv-${envName}-UserPool - Cognito App Client:
CarInv-${envName}-AppClient - S3 Buckets:
carinv-${envName}-<purpose>-<random_suffix_if_needed_for_global_uniqueness>(e.g.,carinv-staging-booksheets-uniqueid)
- General Pattern:
- Tags on AWS Resources:
Project:CarInv(Set globally inapp.tsor per stack)Environment:${envName}(e.g.,staging,production)Owner:HarrisAbbaali
- TODO: Add any other specific naming conventions (e.g., for variables, functions, components).
- HTTPS: Ensure API Gateway and Amplify frontend use HTTPS. (Default for these services).
- Least Privilege IAM:
- Lambda execution roles should only have permissions necessary for their tasks (e.g., specific DynamoDB actions on a specific table).
- CDK deployment roles/users should also follow least privilege.
- Cognito Security:
- Strong password policy enforced (as configured in
AuthStack.ts). - MFA enabled for users (TODO: Consider making this configurable or mandatory).
- Email verification required (as configured).
- Strong password policy enforced (as configured in
- Input Validation:
- Validate all inputs from users/clients on both frontend and backend (Lambda handlers using Joi schemas).
- Protect against common web vulnerabilities (XSS, SQLi - though less relevant for NoSQL/Lambda).
- Secrets Management:
- Store sensitive data like external API keys (e.g., KBB API key) in AWS Secrets Manager, not in code.
- Access secrets securely via IAM permissions for Lambdas. (Placeholder in
calculateKBBLambda).
- Dependency Management:
- Regularly update dependencies to patch vulnerabilities (
npm audit). - Use
npm cifor consistent installs in CI/CD.
- Regularly update dependencies to patch vulnerabilities (
- Data Security (DynamoDB/S3):
- Enable server-side encryption for S3 buckets and DynamoDB tables (default or configurable in CDK).
- Implement Point-in-Time Recovery (PITR) for DynamoDB (as configured in
DatabaseStack.ts). - Configure S3 bucket policies and block public access settings appropriately.
- API Gateway Authorization:
- All protected API routes use Cognito authorizer (as configured in
ComputeStack.ts).
- All protected API routes use Cognito authorizer (as configured in
- Logging & Monitoring:
- Implement sufficient logging in Lambdas for audit and debugging.
- Set up CloudWatch Alarms for critical errors/issues (as planned in
MonitoringStack.ts).
- TODO: Add more specific security considerations as features are built out (e.g., rate limiting on API Gateway, WAF).
TODO: Add sections for "Future Enhancements", "Known Issues", "Contributing Guidelines" if applicable later.