MacPro Mako - Codebase Analysis & Setup Guide

Table of Contents

  1. Project Overview
  2. Architecture Overview
  3. Technology Stack
  4. Key Concepts Explained
  5. Project Structure
  6. Local Development Setup
  7. AWS Deployment Setup
  8. Development Workflow
  9. Testing Strategy
  10. Troubleshooting

Project Overview

MacPro Mako is a full-stack web application built with modern TypeScript/Node.js technologies. It's a government healthcare application that appears to handle form submissions, user management, and data processing for various healthcare-related forms (ABP, CS, ER, G series forms).

The application consists of:

Architecture Overview

``` ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ React App │ │ API Gateway │ │ Lambda │ │ (Frontend) │◄──►│ (REST API) │◄──►│ Functions │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │ │ │ │ │ │ ▼ ▼ ▼ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ CloudFront │ │ Cognito │ │ OpenSearch │ │ (CDN) │ │ (Auth) │ │ (Database) │ └─────────────────┘ └─────────────────┘ └─────────────────┘

Technology Stack

Frontend Technologies

Backend Technologies

Infrastructure & DevOps

Additional Tools

Key Concepts Explained

1. Monorepo Architecture

The project uses a monorepo structure where multiple related projects are managed in a single repository:

``` macpro-mako/ ├── lib/ # Backend infrastructure and libraries ├── react-app/ # Frontend React application ├── bin/ # CLI tools and CDK entry point ├── test/ # End-to-end tests └── mocks/ # Mock data and services

Benefits:

2. Infrastructure as Code (IaC)

The project uses AWS CDK to define infrastructure using TypeScript:

``` // Example from lib/stacks/parent.ts new Stacks.Api(this, "api", { project: props.project, stage: props.stage, vpc, privateSubnets, // ... other configuration });

Benefits:

3. Serverless Architecture

The backend uses AWS Lambda functions for serverless compute:

4. Type Safety

The entire project uses TypeScript for type safety:

``` // Shared types between frontend and backend export interface User { id: string; email: string; role: UserRole; }

Benefits:

5. Feature Flags

Uses LaunchDarkly for feature flag management:

``` const loginFlag = useFeatureFlag("LOGIN_PAGE");

Benefits:

Project Structure

Core Directories

/lib - Backend Infrastructure

/react-app - Frontend Application

/bin - CLI and Tools

/test - Testing

Local Development Setup

Prerequisites

  1. Node.js (v18 or higher)
  2. Bun (v1.1.20 or higher) - Fast JavaScript runtime
  3. AWS CLI configured with appropriate credentials
  4. Docker (for some local services)

Installation Steps

  1. Clone the repository:

    ``` git clone cd macpro-mako
  2. Install dependencies:

    ``` # Install Bun if not already installed curl -fsSL https://bun.sh/install | bash # Install project dependencies bun install
  3. Set up environment variables:

    ``` # Copy example environment file cp .env.example .env # Edit with your local configuration nano .env
  4. Start development servers:

    ``` # Start frontend development server bun run bun:dev # Start backend services (if needed) bun run cdk:watch

Development Commands

``` # Build the project bun run build # Run tests bun run test # Run end-to-end tests bun run e2e # Lint code bun run lint # Format code bun run format:write # Type checking bun run test-tsc

AWS Deployment Setup

Prerequisites

  1. AWS Account with appropriate permissions
  2. AWS CLI configured
  3. AWS CDK installed globally
  4. Domain name (for production)

Deployment Steps

  1. Configure AWS credentials:

    ``` aws configure
  2. Bootstrap CDK (first time only):

    ``` cdk bootstrap
  3. Set up secrets in AWS Secrets Manager:

    ``` # Create project-default secret aws secretsmanager create-secret \ --name "your-project-default" \ --secret-string '{"brokerString":"...","dbInfoSecretName":"..."}' # Create stage-specific secret aws secretsmanager create-secret \ --name "your-project-local" \ --secret-string '{"stage":"local"}'
  4. Deploy to a specific stage:

    ``` # Deploy to local stage cdk deploy -c stage=local # Deploy to production cdk deploy -c stage=production

Environment Variables Required

``` # Required for deployment export PROJECT="your-project-name" export REGION_A="us-east-1" export CDK_DEFAULT_ACCOUNT="your-aws-account-id" export CDK_DEFAULT_REGION="us-east-1" # Optional for development export STAGE="local"

Infrastructure Components Deployed

  1. Networking Stack: VPC, subnets, security groups
  2. API Stack: API Gateway, Lambda functions
  3. Auth Stack: Cognito user pools and identity pools
  4. Data Stack: OpenSearch domain, S3 buckets
  5. UI Stack: CloudFront distribution, S3 hosting
  6. Email Stack: Email processing Lambda functions
  7. Alerts Stack: SNS topics for notifications

Development Workflow

1. Feature Development

``` # Create a new feature branch git checkout -b feature/new-feature # Make changes and test locally bun run test bun run e2e # Commit changes git add . git commit -m "feat: add new feature" # Push and create pull request git push origin feature/new-feature

2. Code Quality

The project enforces code quality through:

3. Deployment Pipeline

``` # Deploy to development cdk deploy -c stage=dev # Deploy to validation cdk deploy -c stage=val # Deploy to production cdk deploy -c stage=production

Testing Strategy

1. Unit Tests (Vitest)

``` # Run all unit tests bun run test # Run tests with coverage bun run test:coverage # Run tests in watch mode bun run test:ui

2. End-to-End Tests (Playwright)

``` # Run all E2E tests bun run e2e # Run E2E tests with UI bun run e2e:ui

3. Type Checking

``` # Check TypeScript types bun run test-tsc

Troubleshooting

Common Issues

  1. Bun installation issues:

    ``` # Reinstall Bun curl -fsSL https://bun.sh/install | bash source ~/.bashrc
  2. CDK deployment failures:

    ``` # Check AWS credentials aws sts get-caller-identity # Bootstrap CDK cdk bootstrap
  3. TypeScript errors:

    ``` # Clear TypeScript cache rm -rf node_modules/.cache bun install
  4. Test failures:

    ``` # Clear test cache rm -rf node_modules/.cache bun run test --reporter=verbose

Getting Help

  1. Check the project's GitHub issues
  2. Review AWS CDK documentation
  3. Check TypeScript and React documentation
  4. Review the project's internal documentation

Additional Resources

📚 Documentation Files

🎯 Start Here


This documentation provides a comprehensive overview of the MacPro Mako codebase. For specific implementation details, refer to the individual source files and their inline documentation.