README.md

Practice Tool #

Build Status Node version ReScript TypeScript License

A serverless web application designed to help you track and optimize your practice sessions for exercises across multiple projects. Built with ReScript, Next.js, and AWS serverless technologies.

Overview • Features • Prerequisites • Getting Started • Development • Deployment • Architecture

Overview #

Practice Tool is a Progressive Web App (PWA) that enables you to organize exercises into projects, configure practice sessions, and maintain a comprehensive practice history. The application uses a sophisticated algorithm to prioritize exercises based on tempo (slow/fast) and recency, ensuring you focus on what needs the most attention.

Whether you're practicing musical instruments, language learning, physical exercises, or any skill that requires structured repetition, Practice Tool helps you stay organized and track your progress over time.

Features #

  • Project Management: Organize exercises into projects with configurable tempo settings (slow/fast) for each exercise
  • Smart Practice Sessions: Generate practice sessions with a specified number of exercises, automatically prioritizing based on:
    • Top priority flag
    • Time since last practice
    • Tempo variation (alternating between slow and fast)
  • Practice History: Track all completed sessions with detailed exercise-level data
  • Offline Support: Works offline as a Progressive Web App with service worker caching
  • Multi-language Support: Built-in internationalization using React Intl
  • Responsive Design: Optimized for both desktop and mobile with Material-UI components
  • Secure Authentication: AWS Cognito integration for user authentication and authorization

Prerequisites #

Getting Started #

Clone the Repository #

git clone https://github.com/DrMorbid/practice-tool-rescript.git
cd practice-tool-rescript

Install Dependencies #

The project uses Yarn workspaces with separate dependencies for frontend and backend:

# Install frontend dependencies
cd frontend
yarn install

# Install lambda dependencies
cd ../lambdas
yarn install

Environment Configuration #

Frontend Configuration #

Create environment files in the frontend/ directory:

.env.development.local (for local development):

NEXT_PUBLIC_COGNITO_USER_POOL_ID=your-user-pool-id
NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID=your-client-id
NEXT_PUBLIC_COGNITO_URL=https://cognito-idp.your-region.amazonaws.com
NEXT_PUBLIC_COGNITO_REDIRECT_URL=http://localhost:3000/signIn/redirect/
NEXT_PUBLIC_BACK_END_URL=your-api-gateway-url

Note

You'll need to set up AWS Cognito User Pool and obtain the required credentials. Update the serverless.yml configuration with your AWS account details.

Build ReScript Code #

Both frontend and lambdas use ReScript and need to be compiled:

# Build frontend ReScript code
cd frontend
yarn res:build

# Build lambda ReScript code
cd ../lambdas
yarn res:build

Development #

Frontend Development #

The frontend is built with Next.js and can be run in development mode:

cd frontend

# Watch ReScript files for changes (run in separate terminal)
yarn res:dev

# Start Next.js development server
yarn dev

The application will be available at http://localhost:3000.

Lambda Development #

For local lambda development and testing:

cd lambdas

# Watch ReScript files for changes
yarn res:dev

# Run tests
yarn test

# Run tests in watch mode
yarn test:watch

Internationalization #

To extract translation strings:

cd frontend
yarn intl

This extracts all messages defined with @intl.description annotations into locale files.

Deployment #

Backend (Lambdas) #

The backend uses Serverless Framework for deployment to AWS:

cd lambdas

# Deploy to development stage
yarn deploy:dev

# Deploy to production stage
yarn deploy:prod

This will:

  • Deploy Lambda functions for project and session management
  • Create DynamoDB tables for projects and history
  • Configure API Gateway with AWS Cognito authorization
  • Set up CORS for allowed origins

Frontend #

The frontend deployment process includes building and uploading to AWS:

cd frontend

# Complete deployment to development
yarn deploy:complete:dev

# Complete deployment to production
yarn deploy:complete:prod

This runs the full pipeline:

  1. Compile ReScript code
  2. Extract internationalization messages
  3. Prepare environment-specific configuration
  4. Build Next.js application
  5. Deploy to AWS (S3 + CloudFront)

Architecture #

Technology Stack #

Frontend:

Backend:

Development:

Project Structure #

practice-tool-rescript/
├── frontend/                 # Next.js frontend application
│   ├── app/                 # Next.js App Router pages
│   ├── src/                 # ReScript source code
│   │   ├── common/          # Shared utilities and types
│   │   ├── exercise/        # Exercise management
│   │   ├── history/         # Practice history
│   │   ├── home/            # Home page
│   │   ├── i18n/            # Internationalization
│   │   ├── menu/            # Navigation components
│   │   ├── project/         # Project management
│   │   ├── session/         # Practice session logic
│   │   └── store/           # Application state
│   ├── public/              # Static assets
│   └── script/              # Build and deployment scripts
├── lambdas/                 # AWS Lambda functions
│   ├── src/                 # ReScript source code
│   │   ├── bindings/        # AWS SDK bindings
│   │   ├── common/          # Shared utilities
│   │   ├── exercise/        # Exercise types and utilities
│   │   ├── history/         # History Lambda handlers
│   │   ├── project/         # Project Lambda handlers
│   │   └── session/         # Session Lambda handlers
│   ├── test/                # Jest tests
│   └── serverless.yml       # Serverless Framework configuration
└── README.md

Data Model #

Projects:

  • Store exercises with configurable tempo settings
  • Each exercise has slow/fast tempo values and priority flags
  • Track last practiced date and tempo for each exercise

Sessions:

  • Generate practice sessions from one or multiple projects
  • Algorithm prioritizes exercises based on recency and tempo
  • Support for top-priority exercises

History:

  • Record all completed practice sessions
  • Store exercise-level details including tempo practiced
  • Query by user and date range

Resources #

Troubleshooting #

ReScript Compilation Errors #

If you encounter ReScript compilation errors:

# Clean and rebuild
yarn res:build

# Or for watch mode
yarn res:dev

Lambda Deployment Issues #

If Serverless deployment fails:

  1. Verify AWS credentials are configured: aws configure
  2. Check the serverless.yml configuration matches your AWS account
  3. Ensure DynamoDB table names don't conflict with existing tables

Frontend Build Issues #

If the Next.js build fails:

  1. Ensure all ReScript code is compiled: yarn res:build
  2. Clear Next.js cache: rm -rf .next
  3. Verify environment variables are set correctly

Authentication Issues #

If authentication fails:

  1. Verify Cognito configuration in serverless.yml
  2. Check redirect URLs match in both Cognito and environment variables
  3. Ensure the API Gateway authorizer is correctly configured