The backend service for the Motzklist project β a school equipment shopping platform built with Go. This API gateway manages schools, grades, equipment catalogs, user authentication, shopping carts, and payment processing through Stripe integration.
Stack: Go 1.25.4 | PostgreSQL | Stripe API | Docker
- Overview
- Features
- Project Structure
- Getting Started
- API Documentation
- Database Schema
- Configuration
- Testing
- Deployment
- Contributing
Motzklist Backend is a RESTful API service that powers the Motzklist web platform. It provides endpoints for:
- School & Grade Management: Retrieve and manage educational institutions and grade levels
- Equipment Catalogs: Browse required equipment for different schools and grades
- User Authentication: Session-based authentication with secure login/logout
- Shopping Cart: Save and manage shopping lists
- Payment Processing: Stripe integration for secure checkout and order management
- Admin Panel: Manage schools, grades, equipment, and view payment history
All responses support multi-language localization (English & Hebrew) via the lang query parameter.
- β RESTful API with JSON request/response format
- β Multi-language Support β Localized content for English and Hebrew
- β User Authentication β Session-based authentication with secure cookies
- β Shopping Cart Management β Persistent cart storage per user
- β Stripe Integration β Secure payment processing and refund management
- β Admin Endpoints β Full CRUD operations for schools, grades, and equipment
- β CORS Support β Configurable cross-origin requests
- β Docker Containerization β Easy deployment with Docker & Docker Compose
- β PostgreSQL Database β Relational database with multi-language support
- β Unit Tests β Comprehensive test coverage for core functionality
.
βββ main.go # Application entry point, HTTP routing
βββ main_test.go # Unit tests for all handlers
βββ db_api.go # Database operations (schools, grades, equipment)
βββ user_handlers.go # Authentication endpoints (login, logout, auth status)
βββ class_handlers.go # School/Grade/Equipment endpoints
βββ cart_handlers.go # Shopping cart endpoints
βββ payment_handlers.go # Stripe checkout session creation
βββ stripe_handlers.go # Stripe webhook handling and admin payment endpoints
βββ admin_handlers.go # Admin CRUD operations for schools, grades, equipment
βββ mock_db.go # Mock data for development/testing
βββ go.mod # Go module dependencies
βββ go.sum # Go module checksums
βββ Makefile # Build and test commands
βββ Dockerfile # Docker image configuration
βββ docker-compose.yml # PostgreSQL + Backend orchestration
βββ SCHEMA.md # Complete API schema documentation
βββ LICENSE # License file
- Go 1.25.4+ β Download
- PostgreSQL 13+ β For database
- Stripe Account β For payment processing (optional for development)
-
Clone the repository:
git clone https://github.com/Motzklist/Back-End.git cd Back-End -
Download dependencies:
make deps
-
Set up environment variables: Create a
.envfile in the project root (or export these variables):# Database DATABASE_URL=postgres://user:password@localhost:5432/motzklist # Frontend CLIENT_ORIGIN=http://localhost:3000 # Stripe (optional) STRIPE_SECRET_KEY=sk_test_... STRIPE_WEBHOOK_SECRET=whsec_... FRONTEND_URL=http://localhost:3000
-
Set up the PostgreSQL database:
CREATE DATABASE motzklist; -- Run schema migrations (see SCHEMA.md for table definitions)
-
Run the server:
make run
The API will be available at
http://localhost:8080
-
Start services with Docker Compose:
docker-compose up --build
This starts:
- PostgreSQL database (port 5432)
- Go backend service (port 8080)
-
Verify the service:
curl http://localhost:8080/api/schools
See SCHEMA.md for the complete API specification.
Get Schools:
GET /api/schools?lang=enGet Grades for a School:
GET /api/grades?school_id=1&lang=enGet Equipment List:
GET /api/equipment?school_id=1&grade_id=9&lang=enUser Login:
POST /api/login
Content-Type: application/json
{
"username": "avner",
"password": "2004"
}Get Shopping Cart:
GET /api/cart?userid=1&lang=enCreate Stripe Checkout Session:
POST /api/checkout
Content-Type: application/json
{
"userId": "1",
"gradeId": "9",
"items": [
{
"equipmentId": "101",
"name": "Notebook",
"quantity": 5,
"amount": 250
}
]
}Admin: List Schools (requires authentication):
GET /api/admin/schools
Cookie: sessionid=...The database includes the following tables:
- school β Educational institutions with multi-language names
- grade β Grade levels (9-12) with multi-language names
- equipment β Product catalog with pricing and descriptions
- requirement β Links equipment to specific grade/school combinations
- users β User credentials (username, password, user ID)
- cart β Persistent shopping carts per user
- orders β Purchase history with order details
- order_item β Line items within orders (from Stripe webhooks)
See SCHEMA.md for detailed table definitions and relationships.
| Variable | Required | Description |
|---|---|---|
DATABASE_URL |
β | PostgreSQL connection string |
CLIENT_ORIGIN |
β | Frontend origin for CORS (e.g., http://localhost:3000) |
STRIPE_SECRET_KEY |
β | Stripe API secret key |
STRIPE_WEBHOOK_SECRET |
β | Stripe webhook signing secret |
FRONTEND_URL |
β | Frontend URL for Stripe success/cancel redirects |
Update DATABASE_URL in your .env:
DATABASE_URL=postgres://username:password@localhost:5432/motzklist
The CLIENT_ORIGIN environment variable accepts comma-separated origins:
CLIENT_ORIGIN=http://localhost:3000,https://motzklist.com
Run the test suite:
make testTo run tests with verbose output:
go test -v ./...Test Coverage:
- Authentication (login, logout, session management)
- Shopping cart operations (GET, POST, validation)
- Equipment and grade retrieval
- Error handling and input validation
Some tests require a seeded test database and are marked with t.Skip(). To enable them, set up a test database and remove the skip statements.
Build the image:
docker build -t motzklist-backend:latest .Run the container:
docker run -p 8080:8080 \
-e DATABASE_URL="postgres://..." \
-e CLIENT_ORIGIN="https://motzklist.com" \
-e STRIPE_SECRET_KEY="sk_..." \
motzklist-backend:latestDeploy the full stack:
docker-compose up -dView logs:
docker-compose logs -f backend| Command | Description |
|---|---|
make run |
Start the development server |
make build |
Compile the binary to ./build/motzklist-backend |
make clean |
Remove the build directory |
make deps |
Download Go dependencies |
make test |
Run the test suite |
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature) - Make changes and add tests
- Run tests (
make test) to ensure everything passes - Commit with clear messages (
git commit -am 'Add feature') - Push to your fork and create a Pull Request
- Follow Go naming conventions and idioms
- Add tests for new functionality
- Update SCHEMA.md if API changes are made
- Ensure CORS and multi-language support for new endpoints
This project is licensed under the LICENSE file in this repository.
For issues, questions, or suggestions:
Happy coding! π