nitrokite/backend/README.md
Farid Siddiqi a1360919f0
Some checks failed
Build and Deploy API Server & Frontend / deploy (push) Blocked by required conditions
Build and Deploy API Server & Frontend / build-backend (push) Has been cancelled
Build and Deploy API Server & Frontend / build-frontend (push) Has been cancelled
Add frontend React dashboard with CI/CD deployment pipeline
2025-12-25 22:08:03 -08:00

109 lines
2.4 KiB
Markdown

# Nitrokite API Server
Go/Gin REST API server for Nitrokite's digital marketing platform.
## Project Structure
```
backend/
├── main.go # Main application entry point
├── go.mod # Go module dependencies
├── go.sum # Dependency checksums
├── .air.toml # Air live reload configuration
└── migrations/ # Database migration files
├── *.up.sql # Migration up scripts
└── *.down.sql # Migration down scripts
```
## Development
### Prerequisites
- Go 1.24.1 or higher
- PostgreSQL 14+
- Air (for live reload) - `go install github.com/air-verse/air@latest`
### Setup
1. Install dependencies:
```bash
go mod download
```
2. Set up environment variables:
```bash
export DATABASE_URL="host=localhost port=5432 user=apiserver password=apiserver dbname=apiserver sslmode=disable"
export PORT=8080
```
3. Run with live reload:
```bash
air
```
4. Or build and run:
```bash
go build -o api-server .
./api-server
```
## Database Migrations
Migrations are automatically run on application startup. They are located in the `migrations/` directory.
To create a new migration:
```bash
# Create migration files manually with naming convention:
# 000002_description.up.sql
# 000002_description.down.sql
```
## API Endpoints
### Health Check
```
GET /health
```
Returns server health status and version information.
### Users
```
GET /api/v1/users # List all users
GET /api/v1/users/:id # Get user by ID
POST /api/v1/users # Create new user
PUT /api/v1/users/:id # Update user
DELETE /api/v1/users/:id # Delete user
```
## Building for Production
```bash
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-s -w -X main.Version=$(git rev-parse --short HEAD) -X main.BuildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
-o api-server \
.
```
## Deployment
The API server is deployed via CI/CD pipeline using blue-green deployment strategy.
See [deployment documentation](../deployment/README.md) for details.
## Environment Variables
- `DATABASE_URL` - PostgreSQL connection string (required)
- `PORT` - Server port (default: 8080)
- `AUTO_MIGRATE` - Run migrations on startup (default: true)
- `GIN_MODE` - Gin mode: debug, release (default: debug)
## Testing
```bash
go test -v ./...
```
## License
Copyright © 2025 Nitrokite. All rights reserved.