https://github.com/nobokumar/spotsync-server
https://github.com/nobokumar/spotsync-server
Last synced: 25 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/nobokumar/spotsync-server
- Owner: noboKumar
- Created: 2026-06-25T20:08:37.000Z (30 days ago)
- Default Branch: main
- Last Pushed: 2026-06-25T21:09:11.000Z (29 days ago)
- Last Synced: 2026-06-25T22:12:41.631Z (29 days ago)
- Size: 4.88 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ SpotSync API
Smart Parking & EV Charging Reservation System built with Go, Echo, GORM, PostgreSQL, and JWT authentication.
## ๐ Live Demo
* **Backend API:** https://spotsync-server-285t.onrender.com
---
## ๐ Project Overview
SpotSync is a centralized parking management platform designed for busy airports and malls. The system supports regular parking and EV charging reservations while ensuring that parking zones never exceed their capacity, even under concurrent booking requests.
The project implements Clean Architecture principles and uses database transactions with row-level locking (`FOR UPDATE`) to prevent race conditions during reservations.
---
## โจ Features
### ๐ Authentication
* User registration
* User login
* JWT authentication
* Password hashing with bcrypt
* Role-based authorization
### ๐ Parking Zones
* Create parking zones (Admin)
* View all parking zones
* View single parking zone
* Dynamic available spot calculation
### ๐
Reservations
* Reserve parking spots
* View personal reservations
* Cancel reservations
* View all reservations (Admin)
* Concurrency-safe booking system using transactions and row locking
---
## ๐ Tech Stack
| Technology | Usage |
| ---------- | ------------------ |
| Go 1.24+ | Backend language |
| Echo | HTTP framework |
| GORM | ORM |
| PostgreSQL | Database |
| JWT | Authentication |
| bcrypt | Password hashing |
| Validator | Request validation |
---
## ๐ Domain Driven Design
The project follows Domain Driven Design principles:
```text
SpotSync-server/
โ
โโโ cmd/
โ โโโ main.go
โ
โโโ auth/
โ โโโ jwt.go
โ
โโโ config/
โ โโโ config.go
โ
โโโ database/
โ โโโ postgres.go
โ
โโโ domain/
โ โ
โ โโโ users/
โ โ โโโ dto/
โ โ โ โโโ request.go
โ โ โ โโโ response.go
โ โ โโโ entity.go # User model
โ โ โโโ repository.go
โ โ โโโ service.go
โ โ โโโ handler.go
โ โ โโโ routes.go
โ โ
โ โโโ parking_zones/
โ โ โโโ dto/
โ โ โ โโโ request.go
โ โ โ โโโ response.go
โ โ โโโ entity.go # ParkingZone model
โ โ โโโ repository.go
โ โ โโโ service.go
โ โ โโโ handler.go
โ โ โโโ routes.go
โ โ
โ โโโ reservations/
โ โโโ dto/
โ โ โโโ request.go
โ โ โโโ response.go
โ โโโ entity.go # Reservation model
โ โโโ repository.go
โ โโโ service.go
โ โโโ handler.go
โ โโโ routes.go
โ
โโโ middleware/
โ โโโ auth.go
โ โโโ admin.go
โ
โโโ server/
โ โโโ http.go
โ
โโโ utils/
โ โโโ error.go
โ โโโ parse.go
โ
โโโ .env
โโโ .gitignore
โโโ go.mod
โโโ go.sum
โโโ README.md
```
### Layer Responsibilities
| Layer | Responsibility |
| ---------- | ------------------------------- |
| DTO | Request and response structures |
| Handler | HTTP request handling |
| Service | Business logic |
| Repository | Database operations |
| Models | Database entities |
Dependencies flow in one direction:
```text
Handler
โ
Service
โ
Repository
โ
Database
```
---
## ๐ Concurrency Handling
The reservation system prevents overbooking by using:
* Database Transactions
* Row-Level Locking (`FOR UPDATE`)
* Atomic reservation creation
This guarantees that two users cannot reserve the last available spot simultaneously.
Example:
```go
tx.Clauses(
clause.Locking{
Strength: "UPDATE",
},
).First(&zone, zoneID)
```
---
## โ๏ธ Environment Variables
Create a `.env` file:
```env
DSN=dataBase_connection
PORT=8080
JWT_SECRET=your-super-secret-key
```
---
## ๐ Running Locally
### 1. Clone the Repository
```bash
git clone https://github.com/noboKumar/SpotSync-server.git
cd SpotSync-server
```
### 2. Install Dependencies
```bash
go mod tidy
```
### 3. Create Environment Variables
```bash
cp .env
```
Update the values inside `.env`.
### 5. Run the Application
```bash
go run cmd/main.go
```
or
```bash
go run main.go
```
depending on your project structure.
The server will start at:
```text
http://localhost:8080
```
---
## ๐ฅ Development Mode (Hot Reload)
Install Air:
```bash
go install github.com/air-verse/air@latest
```
Run:
```bash
air
```
---
## ๐ API Endpoints
### Authentication
| Method | Endpoint | Access |
| ------ | ----------------------- | ------ |
| POST | `/api/v1/auth/register` | Public |
| POST | `/api/v1/auth/login` | Public |
---
### Parking Zones
| Method | Endpoint | Access |
| ------ | ------------------- | ------ |
| POST | `/api/v1/zones` | Admin |
| GET | `/api/v1/zones` | Public |
| GET | `/api/v1/zones/:id` | Public |
---
### Reservations
| Method | Endpoint | Access |
| ------ | -------------------------------------- | ------------- |
| POST | `/api/v1/reservations` | Authenticated |
| GET | `/api/v1/reservations/my-reservations` | Authenticated |
| DELETE | `/api/v1/reservations/:id` | Authenticated |
| GET | `/api/v1/reservations` | Admin |
---
## ๐งช Testing API
You can test the API using:
* Postman
* Thunder Client
* Insomnia
* cURL
Example:
```bash
curl http://localhost:8080/api/v1/zones
```
---
## ๐ License
This project was developed as part of an academic assignment and is intended for educational purposes.