# nahiyanasir/spot_sync architecture

> Architecture diagram of the GitHub repository nahiyanasir/spot_sync, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nahiyanasir/spot_sync
- Repository: https://github.com/nahiyanasir/spot_sync

## Overview

Spot-sync is a Go REST backend for user authentication, parking-zone availability, and parking/EV-charging reservations. The main workflow is a client request entering the Echo server, passing route middleware where protected, and reaching a domain handler, service, and PostgreSQL-backed repository. Reservation creation checks capacity under a row lock and transaction; zone listings calculate availability from active reservations. The graph follows documented layering and sampled handlers/services/repositories; server wiring and reservation-service internals were not sampled, so uncertain links are omitted.

Main entry points: [`internal/server.go`](https://github.com/nahiyanasir/spot_sync/tree/main/internal/server.go) (HTTP server), [`internal/middlewares/auth.go`](https://github.com/nahiyanasir/spot_sync/blob/main/internal/middlewares/auth.go) (Auth middleware), [`internal/user/registerRoutes.go`](https://github.com/nahiyanasir/spot_sync/blob/main/internal/user/registerRoutes.go) (User routes), [`internal/user/service.go`](https://github.com/nahiyanasir/spot_sync/blob/main/internal/user/service.go) (User service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_platform["API platform"]
  node_entry["Application entry<br/>[main.go]"]
  node_config["Config and DB setup"]
  node_server["HTTP server<br/>[server.go]"]
  node_middleware["Auth middleware<br/>[auth.go]"]
end

subgraph group_identity["Identity"]
  node_jwt["JWT service<br/>[jwt.go]"]
  node_user_routes["User routes<br/>[registerRoutes.go]"]
  node_user_handler["User handler<br/>[handler.go]"]
  node_user_service["User service<br/>[service.go]"]
  node_user_repo["User repository<br/>[repository.go]"]
end

subgraph group_zones["Parking zones"]
  node_zone_routes["Zone routes<br/>[registerRoutes.go]"]
  node_zone_handler["Zone handler<br/>[handler.go]"]
  node_zone_service["Zone service<br/>[service.go]"]
  node_zone_repo["Zone repository<br/>[repository.go]"]
end

subgraph group_reservations["Reservations"]
  node_reservation_routes["Reservation routes<br/>[registerRoutes.go]"]
  node_reservation_handler["Reservation handler<br/>[handler.go]"]
  node_reservation_service["Reservation service<br/>[service.go]"]
  node_reservation_repo["Reservation repository<br/>[repository.go]"]
end

node_client(("API client"))
node_postgres[("PostgreSQL")]

node_client -->|"sends requests"| node_server
node_entry -->|"loads settings"| node_config
node_entry -->|"starts server"| node_server
node_config -->|"connects"| node_postgres
node_server -->|"registers routes"| node_user_routes
node_server -->|"registers routes"| node_zone_routes
node_server -->|"registers routes"| node_reservation_routes
node_user_routes -->|"dispatches"| node_user_handler
node_zone_routes -->|"dispatches"| node_zone_handler
node_reservation_routes -->|"dispatches"| node_reservation_handler
node_user_routes -->|"protects routes"| node_middleware
node_zone_routes -->|"protects routes"| node_middleware
node_reservation_routes -->|"protects routes"| node_middleware
node_middleware -->|"validates tokens"| node_jwt
node_user_handler -->|"calls"| node_user_service
node_user_service -->|"queries"| node_user_repo
node_user_service -->|"generates tokens"| node_jwt
node_user_repo -->|"reads and writes"| node_postgres
node_zone_handler -->|"calls"| node_zone_service
node_zone_service -->|"queries"| node_zone_repo
node_zone_service -->|"counts active bookings"| node_postgres
node_zone_repo -->|"reads and writes"| node_postgres
node_reservation_handler -->|"calls"| node_reservation_service
node_reservation_repo -->|"locks and updates"| node_postgres
node_reservation_service -->|"uses repository"| node_reservation_repo

click node_entry "https://github.com/nahiyanasir/spot_sync/blob/main/cmd/main.go"
click node_config "https://github.com/nahiyanasir/spot_sync/tree/main/internal/config"
click node_server "https://github.com/nahiyanasir/spot_sync/tree/main/internal/server.go"
click node_middleware "https://github.com/nahiyanasir/spot_sync/blob/main/internal/middlewares/auth.go"
click node_jwt "https://github.com/nahiyanasir/spot_sync/blob/main/internal/auth/jwt.go"
click node_user_routes "https://github.com/nahiyanasir/spot_sync/blob/main/internal/user/registerRoutes.go"
click node_user_handler "https://github.com/nahiyanasir/spot_sync/blob/main/internal/user/handler.go"
click node_user_service "https://github.com/nahiyanasir/spot_sync/blob/main/internal/user/service.go"
click node_user_repo "https://github.com/nahiyanasir/spot_sync/blob/main/internal/user/repository.go"
click node_zone_routes "https://github.com/nahiyanasir/spot_sync/blob/main/internal/parkingzone/registerRoutes.go"
click node_zone_handler "https://github.com/nahiyanasir/spot_sync/blob/main/internal/parkingzone/handler.go"
click node_zone_service "https://github.com/nahiyanasir/spot_sync/blob/main/internal/parkingzone/service.go"
click node_zone_repo "https://github.com/nahiyanasir/spot_sync/blob/main/internal/parkingzone/repository.go"
click node_reservation_routes "https://github.com/nahiyanasir/spot_sync/blob/main/internal/reservations/registerRoutes.go"
click node_reservation_handler "https://github.com/nahiyanasir/spot_sync/blob/main/internal/reservations/handler.go"
click node_reservation_service "https://github.com/nahiyanasir/spot_sync/blob/main/internal/reservations/service.go"
click node_reservation_repo "https://github.com/nahiyanasir/spot_sync/blob/main/internal/reservations/repository.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_config,node_server,node_middleware,node_client toneBlue
class node_jwt,node_user_routes,node_user_handler,node_user_service,node_user_repo,node_postgres toneAmber
class node_zone_routes,node_zone_handler,node_zone_service,node_zone_repo toneMint
class node_reservation_routes,node_reservation_handler,node_reservation_service,node_reservation_repo toneRose
```

## Components

### API platform

- [Application entry](https://github.com/nahiyanasir/spot_sync/blob/main/cmd/main.go): `cmd/main.go`
- [Config and DB setup](https://github.com/nahiyanasir/spot_sync/tree/main/internal/config): `internal/config`
- [HTTP server](https://github.com/nahiyanasir/spot_sync/tree/main/internal/server.go): `internal/server.go`
- [Auth middleware](https://github.com/nahiyanasir/spot_sync/blob/main/internal/middlewares/auth.go): `internal/middlewares/auth.go`

### Identity

- [JWT service](https://github.com/nahiyanasir/spot_sync/blob/main/internal/auth/jwt.go): `internal/auth/jwt.go`
- [User routes](https://github.com/nahiyanasir/spot_sync/blob/main/internal/user/registerRoutes.go): `internal/user/registerRoutes.go`
- [User handler](https://github.com/nahiyanasir/spot_sync/blob/main/internal/user/handler.go): `internal/user/handler.go`
- [User service](https://github.com/nahiyanasir/spot_sync/blob/main/internal/user/service.go): `internal/user/service.go`
- [User repository](https://github.com/nahiyanasir/spot_sync/blob/main/internal/user/repository.go): `internal/user/repository.go`

### Parking zones

- [Zone routes](https://github.com/nahiyanasir/spot_sync/blob/main/internal/parkingzone/registerRoutes.go): `internal/parkingzone/registerRoutes.go`
- [Zone handler](https://github.com/nahiyanasir/spot_sync/blob/main/internal/parkingzone/handler.go): `internal/parkingzone/handler.go`
- [Zone service](https://github.com/nahiyanasir/spot_sync/blob/main/internal/parkingzone/service.go): `internal/parkingzone/service.go`
- [Zone repository](https://github.com/nahiyanasir/spot_sync/blob/main/internal/parkingzone/repository.go): `internal/parkingzone/repository.go`

### Reservations

- [Reservation routes](https://github.com/nahiyanasir/spot_sync/blob/main/internal/reservations/registerRoutes.go): `internal/reservations/registerRoutes.go`
- [Reservation handler](https://github.com/nahiyanasir/spot_sync/blob/main/internal/reservations/handler.go): `internal/reservations/handler.go`
- [Reservation service](https://github.com/nahiyanasir/spot_sync/blob/main/internal/reservations/service.go): `internal/reservations/service.go`
- [Reservation repository](https://github.com/nahiyanasir/spot_sync/blob/main/internal/reservations/repository.go): `internal/reservations/repository.go`

### Other components

- **API client**
- **PostgreSQL**

## Connections

- API client → HTTP server: sends requests
- Application entry → Config and DB setup: loads settings
- Application entry → HTTP server: starts server
- Config and DB setup → PostgreSQL: connects
- HTTP server → User routes: registers routes
- HTTP server → Zone routes: registers routes
- HTTP server → Reservation routes: registers routes
- User routes → User handler: dispatches
- Zone routes → Zone handler: dispatches
- Reservation routes → Reservation handler: dispatches
- User routes → Auth middleware: protects routes
- Zone routes → Auth middleware: protects routes
- Reservation routes → Auth middleware: protects routes
- Auth middleware → JWT service: validates tokens
- User handler → User service: calls
- User service → User repository: queries
- User service → JWT service: generates tokens
- User repository → PostgreSQL: reads and writes
- Zone handler → Zone service: calls
- Zone service → Zone repository: queries
- Zone service → PostgreSQL: counts active bookings
- Zone repository → PostgreSQL: reads and writes
- Reservation handler → Reservation service: calls
- Reservation repository → PostgreSQL: locks and updates
- Reservation service → Reservation repository: uses repository
