Skip to content

Go-based backend application for a delivery service company

Notifications You must be signed in to change notification settings

Mehran-tr/delivery-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Delivery Service Application

This is a Go-based backend application for a delivery service company. The app enables parcel creation, delivery tracking, motorbike parcel pickup, and management functionalities with proper authentication and security.

Project Structure

go-delivery-app/
|-- cmd/
|   |-- server/           # Entry point for the application
|       |-- main.go       # Main server start file
|-- internal/
|   |-- auth/             # Authentication logic (JWT)
|       |-- jwt.go
|   |-- handlers/         # API request handlers (Controllers)
|       |-- parcel.go
|       |-- motorbike.go
|       |-- admin.go
|   |-- models/           # Data models (DB Schema)
|       |-- models.go
|   |-- services/         # Business logic services
|   |-- db/               # Database connection and migrations
|       |-- database.go
|   |-- middleware/       # Logging, security, and other middleware
|       |-- logging.go
|-- config/               # Configuration files (optional)
|-- migrations/           # Database migration files (optional)
|-- test/                 # Test files
|-- logs/                 # Logs folder
|-- go.mod                # Go modules file
|-- go.sum                # Go modules file

Features

  • Parcel Management: Users (senders) can create and track parcels, and motorbikes can pick up and deliver parcels.
  • User Roles:
    • Sender: Create parcels, track parcel status.
    • Motorbike: View available parcels, pick up and deliver parcels.
    • Admin: View all parcels, users, and parcel statuses.
  • Authentication: JWT-based authentication and role-based authorization.
  • Database: PostgreSQL is used for storing parcels, users, and related data.
  • Logging: All actions are logged, and middleware is used to log requests.
  • Security: Secure coding practices, JWT, HTTPS (recommended), and input sanitization.
  • Concurrency: Safe concurrent access to database and parcel statuses.

Installation

Prerequisites

Setup Instructions

  1. Clone the repository:
git clone https://github.com/yourusername/go-delivery-app.git
cd go-delivery-app
  1. Set up the PostgreSQL database:
CREATE DATABASE delivery;
  1. Update the connection details in internal/db/database.go:
dsn := "host=localhost user=postgres password=yourpassword dbname=delivery port=5432 sslmode=disable"
  1. Install dependencies:
go mod tidy
  1. Run the migrations (if using migrations):
go run cmd/migrations.go
  1. Start the server:
go run cmd/server/main.go

Server will run at localhost:8080.

API Endpoints

Sender

  • Create Parcel: POST /sender/parcel
  • Get Parcel Status: GET /sender/parcel/{id}

Motorbike

  • List Available Parcels: GET /motorbike/parcels
  • Pick Parcel: POST /motorbike/parcel/{id}/pickup

Admin

  • View All Parcels: GET /admin/parcels
  • View All Users: GET /admin/users

Authentication

The app uses JWT for secure authentication. Each request should include the Authorization: Bearer <token> header.

Testing

To run tests:

go test ./...

Logging

Logs are stored in the logs/ directory. Make sure to configure proper logging for production use.

Security Considerations

  • Use HTTPS for production.
  • Implement proper rate limiting to prevent abuse.
  • Regularly rotate JWT secret keys and other sensitive credentials.
  • Securely hash and store passwords using bcrypt or similar libraries.

Contributions

Feel free to submit pull requests or report issues on the GitHub repository.

License

MIT License. See LICENSE for details.

About

Go-based backend application for a delivery service company

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages