A full-stack CRUD application demonstrating modern web development with Ballerina, React, and Supabase.
👋 First time here? Follow our simplified quick-start guide for Windows users!
→ Click here to go to the New User Guide
The new user guide provides a streamlined setup process specifically designed for Windows users with PowerShell commands and step-by-step instructions.
React Frontend (Port 3000)
↓ HTTP/HTTPS
Ballerina API Server (Port 8080)
↓ PostgreSQL Protocol
Supabase PostgreSQL Database
Before you begin, ensure you have the following installed:
- Ballerina (Version 2201.12.7 or later)
- Node.js (Version 16 or later)
- npm (comes with Node.js)
- Git (for cloning the repository)
- Download the MSI installer from ballerina.io
- Run the installer and follow the setup wizard
- Verify installation:
bal version
# Using Homebrew
brew install ballerina
# Or download from ballerina.io# Download and install the DEB/RPM package from ballerina.io
# Or use the installation script:
curl -sSL https://dist.ballerina.io/bvm/get-ballerina.sh | bash- Download from nodejs.org
- Run the installer
- Verify installation:
node --version npm --version
# Using Node Version Manager (recommended)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm install node
nvm use nodegit clone <your-repository-url>
cd ballerina_backend_test-
Create Supabase Account:
- Go to supabase.com
- Sign up for a free account
- Create a new project
-
Get Database Credentials:
- Go to Settings → Database
- Copy your connection details:
- Host:
db.xxxxxxxxxxxxx.supabase.co - Database name:
postgres - Username:
postgres - Password: (your project password)
- Port:
5432
- Host:
-
Run Database Setup:
- Go to SQL Editor in Supabase
- Copy and paste the contents of
crud-app/database_setup.sql - Click "Run" to create the users table
-
Navigate to the project directory:
cd crud-app -
Create Configuration File: Create a file named
Config.tomlin thecrud-appdirectory:# Database Configuration for Supabase DB_HOST = "db.xxxxxxxxxxxxx.supabase.co" DB_NAME = "postgres" DB_USERNAME = "postgres" DB_PASSWORD = "your-actual-password" DB_PORT = 5432
⚠️ Important: Replace the values with your actual Supabase credentials. -
Install Ballerina Dependencies:
bal build
-
Navigate to React frontend:
cd react-frontend -
Install Dependencies:
npm install
# Navigate to crud-app directory
cd crud-app
# Run the Ballerina server
bal runThe backend will start on http://localhost:8080
# Navigate to react-frontend directory
cd crud-app/react-frontend
# Start the development server
npm run devThe frontend will start on http://localhost:3000
Open your browser and navigate to: http://localhost:3000
You should see a CRUD interface where you can:
- ✅ View all users
- ✅ Add new users
- ✅ Edit existing users
- ✅ Delete users
ballerina_backend_test/
├── crud-app/
│ ├── main.bal # Ballerina API server
│ ├── Ballerina.toml # Ballerina project configuration
│ ├── Dependencies.toml # Auto-generated dependencies
│ ├── Config.toml # Database credentials (create this)
│ ├── database_setup.sql # Database schema and sample data
│ ├── postgresql-42.7.2.jar # PostgreSQL JDBC driver
│ ├── README.md # Detailed project documentation
│ └── react-frontend/ # React frontend application
│ ├── src/
│ │ ├── App.jsx # Main React component
│ │ ├── App.css # Application styles
│ │ └── main.jsx # React entry point
│ ├── index.html # HTML template
│ ├── package.json # Node.js dependencies
│ └── vite.config.js # Vite build configuration
└── README.md # This file
The Ballerina backend provides the following REST API endpoints:
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/users |
Get all users |
| GET | /api/users/{id} |
Get user by ID |
| POST | /api/users |
Create new user |
| PUT | /api/users/{id} |
Update user |
| DELETE | /api/users/{id} |
Delete user |
| OPTIONS | /api/users |
CORS preflight |
curl http://localhost:8080/api/userscurl -X POST http://localhost:8080/api/users \
-H "Content-Type: application/json" \
-d '{"name": "John Doe", "email": "john@example.com"}'curl -X PUT http://localhost:8080/api/users/1 \
-H "Content-Type: application/json" \
-d '{"name": "John Smith", "email": "john.smith@example.com"}'curl -X DELETE http://localhost:8080/api/users/1# Build Ballerina project
cd crud-app
bal build
# Build React frontend for production
cd react-frontend
npm run buildYou can test the API using:
- curl (command line)
- Postman (GUI)
- Insomnia (GUI)
- VS Code REST Client extension
ERROR: Connection refused or timeout
Solution:
- Verify Supabase credentials in
Config.toml - Check if your Supabase project is active
- Ensure you're using the correct host URL
Access to XMLHttpRequest has been blocked by CORS policy
Solution:
- The backend includes CORS headers
- Ensure both frontend and backend are running
- Check that you're accessing the frontend via
http://localhost:3000
ERROR: Port 8080 is already in use
Solution:
# Windows
netstat -ano | findstr :8080
taskkill /PID <PID> /F
# macOS/Linux
lsof -ti:8080 | xargs kill -9ERROR: Cannot resolve dependencies
Solution:
# Clean and rebuild
bal clean
bal buildnpm ERR! Cannot resolve dependency tree
Solution:
# Clear npm cache and reinstall
npm cache clean --force
rm -rf node_modules package-lock.json
npm installIf you prefer using environment variables instead of Config.toml:
# Set environment variables (Windows PowerShell)
$env:DB_HOST="db.xxxxxxxxxxxxx.supabase.co"
$env:DB_NAME="postgres"
$env:DB_USERNAME="postgres"
$env:DB_PASSWORD="your-password"
$env:DB_PORT="5432"
# Then run
bal run- Never commit
Config.tomlwith real credentials to version control - Use environment variables for production deployments
- Enable SSL/TLS for production databases
- Implement authentication for production APIs
- Validate and sanitize all user inputs
- Use HTTPS in production
# Sensitive configuration
Config.toml
.env
*.env
# Dependencies
node_modules/
target/
# Build outputs
dist/
build/-
Docker:
FROM ballerina/ballerina:2201.12.7 COPY . /app WORKDIR /app EXPOSE 8080 CMD ["bal", "run", "main.bal"]
-
Cloud Platforms:
- Heroku
- DigitalOcean App Platform
- AWS Elastic Beanstalk
- Google Cloud Platform
- Netlify (recommended for static sites)
- Vercel
- GitHub Pages
- AWS S3 + CloudFront
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit your changes:
git commit -am 'Add feature' - Push to the branch:
git push origin feature-name - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues:
- Check the troubleshooting section above
- Review the Ballerina and React documentation
- Create an issue in the repository
- Check Supabase status page for database issues
Happy Coding! 🎉
Built with ❤️ using Ballerina, React, and Supabase.