Smart Parking & EV Charging Reservation — A centralized platform for airports and malls to manage parking zones and handle high-demand EV charging spot reservations.
Live URL: https://spotsync-production.up.railway.app
Health Check: https://spotsync-production.up.railway.app/ping
API Zones: https://spotsync-production.up.railway.app/api/v1/zones
- User registration and login with JWT authentication
- Role-based access control (
driver/admin) - Parking zone management (create, update, delete) — admin only
- Real-time available spot calculation per zone
- Concurrency-safe reservation system using database transactions and row-level locking
- Reservation cancellation with ownership enforcement
| Technology | Version |
|---|---|
| Go | 1.22+ |
| Echo | v4 |
| GORM | v1 |
| PostgreSQL | (NeonDB) |
| go-playground/validator | v10 |
| golang-jwt/jwt | v5 |
| bcrypt | golang.org/x/crypto |
This project follows Clean Architecture with strict layer separation:
main.go → Wires all layers via Dependency Injection
├── models/ → GORM structs (database table definitions)
├── dto/ → Request and response data transfer objects
├── repository/ → All database operations (GORM queries, transactions)
├── service/ → Business logic (hashing, JWT generation, capacity rules)
├── handler/ → HTTP layer (bind, validate, call service, return JSON)
├── middlewares/ → JWT authentication and role enforcement
└── config/ → Database connection setup
Dependency flow: Handler → Service → Repository → Database
Handlers never touch the database directly. Raw GORM errors never reach the client.
When two drivers attempt to reserve the last available spot simultaneously, a naive implementation would allow both to succeed, exceeding zone capacity.
Solution: The CreateReservationTx repository method wraps the entire check-and-create flow inside a single GORM transaction with a FOR UPDATE row-level lock on the parking zone record. This serializes concurrent requests at the database level, guaranteeing that only one reservation is created when a zone is at full capacity.
- Go 1.22+
- PostgreSQL database (local or NeonDB)
- Air for hot-reload (optional)
-
Clone the repository
git clone https://github.com/usernayeem/spotsync.git cd spotsync -
Install dependencies
go mod tidy
-
Configure environment variables
cp .env.example .env # Edit .env with your database credentials and JWT secret -
Run the server
# With hot-reload (recommended for development) air # Without hot-reload go run main.go
The server starts on the port defined in your .env file (default: 8080).
| Variable | Description |
|---|---|
PORT |
Server port (e.g. 8080) |
DATABASE_URL |
Full PostgreSQL connection string |
JWT_SECRET |
Secret key for signing JWT tokens |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /api/v1/auth/register |
Public | Register a new user |
| POST | /api/v1/auth/login |
Public | Login and receive JWT token |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| GET | /api/v1/zones |
Public | Get all zones with available spots |
| GET | /api/v1/zones/:id |
Public | Get a single zone by ID |
| POST | /api/v1/zones |
Admin | Create a new parking zone |
| PATCH | /api/v1/zones/:id |
Admin | Update an existing zone |
| DELETE | /api/v1/zones/:id |
Admin | Delete a zone |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /api/v1/reservations |
Authenticated | Reserve a parking spot |
| GET | /api/v1/reservations/my-reservations |
Authenticated | Get your own reservations |
| DELETE | /api/v1/reservations/:id |
Authenticated | Cancel your reservation |
| GET | /api/v1/reservations |
Admin | Get all reservations in the system |
| Code | Usage |
|---|---|
200 |
Successful GET, PATCH, DELETE |
201 |
Successful POST (resource created) |
400 |
Validation errors or invalid input |
401 |
Missing or invalid JWT token |
403 |
Valid token but insufficient permissions |
404 |
Resource not found |
409 |
Business logic conflict (e.g. zone is full) |
500 |
Unexpected server error |