AstraERP — Modular ERP Backend
AstraERP is a production-ready, modular backend for enterprise resource planning (ERP) systems. Built with Go, Gin and GORM, AstraERP is designed around clean architecture, testability and operational readiness — Postgres/PostGIS compatible.
Version: v1 — polished, comprehensive README with folder structure, environment guidelines, Docker & deployment notes, and best practices.
Table of Contents
Overview
AstraERP implements a clean, modular architecture where each domain (authentication, users, geofencing, etc.) follows the same pattern:
DTO → Repository (DAO) → Service → HTTP Handler
This separation of concerns improves maintainability, testability and enables independent module evolution.
Key Features
- Modular domain-based architecture
- DAO / Repository pattern for testable data access
- JWT-based authentication and permission middleware
- Geofencing & GIS-ready data models (PostGIS-ready)
- Auto-generated Swagger documentation (swaggo)
- Consistent API envelope (shared utils.APIResponse)
- Docker-ready and designed for production deployments
Project Structure (short)
A concise, opinionated tree to show where responsibilities live:
ERP-SYSTEM/
├── cmd/ # Application entry point(s)
│ └── main.go
├── config/ # Configuration loader & DB migrations
│ └── migrations/
├── internal/
│ ├── dto/ # Request & response DTOs (per module)
│ ├── http/
│ │ ├── handlers/ # HTTP handlers / controllers
│ │ ├── middlewares/ # JWT, permissions, logging, CORS
│ │ ├── routes/ # Route registration (versioned)
│ │ └── docs/ # Swagger/docs (generated)
│ ├── models/ # GORM models (Postgres/PostGIS-ready)
│ ├── repository/ # DAO interfaces + implementations
│ ├── services/ # Business logic
│ └── utils/ # Shared helpers (responses, logger, id parser)
├── pkg/ # Reusable exported packages (optional)
├── scripts/ # Dev / migration / seed scripts
├── deployments/ # Docker / k8s manifests & examples
├── tmp/ # Temporary files
├── .env # Local env (DO NOT commit secrets)
├── .gitignore
├── Makefile
├── go.mod
└── go.sum
Quick Start
- Clone
git clone https://github.com/engrsakib/astraERP-GO-Backend.git
cd astraERP-GO-Backend
- Install dependencies
go mod tidy
- Environment
- Copy
.env.exampleto.envand fill values or inject secrets from your secret store.
cp .env.example .env
- Generate Swagger (developer machine)
go install github.com/swaggo/swag/cmd/swag@latest
swag init -g cmd/main.go -o internal/http/docs
- Run (development)
# run directly
go run cmd/main.go
# or use live-reload (Air)
air
Open: http://localhost:8080 — Swagger: http://localhost:8080/swagger/index.html
Environment & Secrets Management
- Use
.env.exampleas template; never commit secrets. Add.envto.gitignore. - For production, prefer a secrets manager (AWS Secrets Manager, HashiCorp Vault, GCP Secret Manager, or Kubernetes Secrets).
- Generate strong secrets for
JWT_SECRET(e.g.,openssl rand -hex 32). - Recommended env variables (examples are provided in
.env.example,.env.local,.env.productionin the repo).
Database & GIS
- Primary DB: PostgreSQL. Models and queries are written with Postgres compatibility in mind.
- Geospatial: PostGIS-ready models (geometry fields) are included for geofencing features.
- Migrations: store SQL/migration files in
config/migrations/and use a migration tool (e.g., golang-migrate). - Ensure PostGIS extension is enabled on DB when using geometry columns:
CREATE EXTENSION IF NOT EXISTS postgis;
API Documentation (Swagger)
- Routes are documented with swag annotations.
- Generate docs:
swag init -g cmd/main.go -o internal/http/docs
- The Swagger UI is available at
/swagger/index.htmlonce the server runs.
Authentication & Security
- Authentication: JWT access tokens (configurable expirations).
- Authorization: permission-based middleware for endpoint-level access.
- Best practices:
- Use HTTPS in production.
- Set
COOKIE_SECURE=truefor secure cookies. - Rotate secrets and use short-lived tokens where appropriate.
Docker & Deployment
deployments/docker/contains sample Dockerfile and docker-compose.yml. Replace placeholders and avoid embedding secrets in images.- Build a static binary for small container images:
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app ./cmd
docker build -t astraerp:latest .
- Use multi-stage builds and minimal base images.
- For production, use orchestrators (Kubernetes) and inject secrets from the cluster secret store.
Testing & CI/CD
- Unit-test business logic (services). Mock repository interfaces for isolated tests.
- Integration tests: use a test database (or testcontainers) for repository tests.
- Recommended CI tasks:
go test ./...golangci-lint run- Build artifacts / container images
- Deploy to staging via pipeline (GitHub Actions, GitLab CI, etc.)
Developer Tools & Best Practices
- Live reload: Air
- Linter: golangci-lint
- Use Docker Compose for local Postgres/Redis during development
- Use
openssl rand -hex 32to generate secrets - Keep repository lean: do not commit
.envor other secrets
Changelog (v9)
- README content refined and reorganized for clarity and operational guidance.
- Added explicit Project Structure section.
- Included environment templates and security guidance.
- Added Docker tips, Swagger instructions, and testing/CI notes.
Author & Contact
Md. Nazmus Sakib — Backend Engineer
Repository: https://github.com/engrsakib/astraERP-GO-Backend
Documentation: https://astraerp-go-backend.onrender.com/swagger/index.html
Website / Portfolio: https://engrsakib.com
Contact: [email protected]
License
Proprietary — maintained by Md. Nazmus Sakib. For licensing or commercial use, please contact the author.
