A real-time GitHub stars counter built with Motia - showcasing how incredibly simple it is to build production-ready, real-time applications with just a few lines of code.
🎯 Live in Action: This exact counter powers the live star count on the Motia website - updating in real-time as developers star the repository!
This entire real-time application was built using just 2 simple steps:
01-github-webhook.step.ts
- Secure webhook endpoint that receives GitHub star events00-repository-stars.stream.ts
- Real-time data stream for live updates
That's it! No complex infrastructure, no boilerplate, no headaches. Just pure business logic.
- Stars update instantly across all connected clients
- Built-in streaming with automatic state management
- No WebSocket complexity or manual connection handling
- Automatic GitHub webhook signature verification
- Request validation with TypeScript + Zod schemas
- Error handling and logging
- Full TypeScript support with auto-generated types
- API schema validation for requests and responses
- Zero runtime surprises
- Deploy instantly to Motia Cloud
- Built-in monitoring, scaling, and observability
- No DevOps configuration required
// 1. Define your data structure
const RepositoryStarsSchema = z.object({
stars: z.number(),
name: z.string(),
fullName: z.string(),
organization: z.string(),
lastUpdated: z.string(),
})
// 2. Create a real-time stream
export const config: StreamConfig = {
name: 'stars',
schema: RepositoryStarsSchema,
baseConfig: { storageType: 'default' },
}
// 3. Handle webhook events
export const handler: Handlers['GitHubStarWebhook'] = async (req, { streams }) => {
await streams.stars.set(organization, repository, starData)
// Real-time updates sent automatically! 🎉
}
-
Clone and Install
git clone https://github.com/MotiaDev/github-stars-counter.git cd github-stars-counter npm install
-
Configure GitHub Webhook (Optional)
# Set up your webhook secret for security export GITHUB_WEBHOOK_SECRET=your-secret-here
-
Start Development
npm run dev
-
Deploy to Production
Option 1: CLI Deployment
# Deploy with version and API key motia cloud deploy --api-key your-api-key --version-name 1.0.0 # Deploy with environment variables motia cloud deploy --api-key your-api-key \ --version-name 1.0.0 \ --env-file .env.production \ --environment-id your-env-id
Option 2: One-Click Web Deployment
- Ensure your local project is running (
npm run dev
) - Go to Motia Cloud -> Import from Workbench
- Select your local project port
- Choose project and environment name
- Upload environment variables (optional)
- Click Deploy and watch the magic happen! ✨
- Ensure your local project is running (
This counter is actively running on the Motia website, demonstrating real-world production usage. Every star on the Motia repository triggers this webhook and updates the live counter instantly.
See it in action on: Motia website
This project demonstrates core Motia concepts:
- API Steps: HTTP endpoints with automatic validation
- Streams: Real-time data synchronization
- State Management: Persistent, scalable storage
- Security: Production-ready webhook verification
- Type Safety: End-to-end TypeScript integration
Built with ❤️ by the Motia Open Source community to showcase the power of unified backend development.