Skip to content

gitcoinco/grants-calculator

Repository files navigation

grants-calculator-api

Structure

.
β”œβ”€β”€ Dockerfile                  # Docker configuration for containerization
β”œβ”€β”€ docker-compose.yml          # Docker Compose configuration for local development
β”œβ”€β”€ infrastructure/             # AWS infrastructure automation scripts
β”‚   β”œβ”€β”€ config.sh               # Configuration variables for infrastructure
β”‚   β”œβ”€β”€ deploy.sh               # Full deployment script for new environments
β”‚   β”œβ”€β”€ ecr.sh                  # Amazon ECR (Container Registry) setup
β”‚   β”œβ”€β”€ ecs.sh                  # Amazon ECS (Elastic Container Service) setup
β”‚   β”œβ”€β”€ iam.sh                  # IAM roles and permissions setup
β”‚   β”œβ”€β”€ loadbalancer.sh         # Application Load Balancer configuration
β”‚   β”œβ”€β”€ network.sh              # VPC, subnets, and security groups setup
β”‚   β”œβ”€β”€ secrets.sh              # AWS Secrets Manager configuration
β”‚   β”œβ”€β”€ update.sh               # Update script for existing deployments
β”‚   └── utils.sh                # Utility functions for infrastructure scripts
β”œβ”€β”€ scripts/                    # Build helper scripts to solve docker build issues
β”‚   β”œβ”€β”€ postbuild.js
β”‚   └── prebuild.js
└── src/                        # Source code for the application
    β”œβ”€β”€ cache/                  # Caching mechanisms
    β”œβ”€β”€ config/                 # Application configuration
    β”œβ”€β”€ controllers/            # API controllers
    β”œβ”€β”€ ext/                    # External integrations
    β”‚   └── indexer/            # Blockchain indexer integration
    β”œβ”€β”€ logger/                 # Logging configuration
    β”œβ”€β”€ middleware/             # Express middleware
    β”œβ”€β”€ parsers/                # Data parsing utilities
    β”œβ”€β”€ routes/                 # API route definitions
    β”œβ”€β”€ service/                # Business logic services
    β”‚   └── priceService/       # Cryptocurrency price services
    β”œβ”€β”€ types/                  # TypeScript type definitions
    β”œβ”€β”€ utils/                  # Utility functions
    β”œβ”€β”€ env.ts                  # Environment configuration
    β”œβ”€β”€ errors.ts               # Error handling
    β”œβ”€β”€ index.ts                # Application entry point
    └── swagger.ts              # API documentation with Swagger

Getting Started

  1. Basic Setup:

    pnpm install
  2. Configure Environment Variables: Copy the .env.example file in the root of the project and set coingecko api key.

  3. Run the Development Server:

    pnpm run dev
  4. API Overview

  • Visit http://localhost:4000

Update ECS Service

The application can be updated using the provided update script:

  1. Prerequisites:

    • Install AWS CLI

      # For macOS
      brew install awscli
      
      # For Ubuntu/Debian
      sudo apt-get install awscli
      
      # For Windows (using PowerShell)
      choco install awscli
    • Configure AWS CLI with appropriate credentials

      aws configure

      You'll need to provide:

      • AWS Access Key ID
      • AWS Secret Access Key
      • Default region (e.g., us-east-2)
      • Default output format (json recommended)
  2. Run the update script:

    ./infrastructure/update.sh [wait_time_in_seconds]

    The script performs the following operations:

    • Builds a new Docker image from the current codebase
    • Tags and pushes the image to Amazon ECR
    • Checks the current state of the ECS service
    • Handles any health check failures or multiple deployments
    • Updates the ECS service with the new image
    • Waits for the deployment to complete (default: 5 minutes)

    Optional parameter:

    • wait_time_in_seconds: How long to wait for deployment to complete (default: 300 seconds)
  3. Troubleshooting:

    • If health check failures are detected, the script will show recent logs and prompt before continuing
    • If multiple deployments are in progress, you'll be given options to:
      • Wait for current deployments to complete
      • Force cleanup by stopping all tasks
      • Continue with the update anyway
  4. Monitoring the update: After running the update script, you can monitor the deployment status:

    aws ecs describe-services --cluster grants-calculator-cluster --services grants-calculator-api

    Or check the logs:

    aws logs get-log-events --log-group-name "/ecs/grants-calculator-api" --log-stream-name [log-stream-name]

Note

  • For Logging.md to understand use winston for logging
  • For Try catch handling done via catchError
  • All routes are documented using swagger (NOT YET)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published