A production-grade backend API for multi-user project collaboration, featuring authentication, authorization, rate limiting, auditing, and workflow management.
- ๐ JWT-based Authentication - Secure token-based auth with refresh tokens
- ๐ฅ Multi-tenant Organizations - Support for multiple organizations per user
- ๐ฏ Role-Based Access Control - Granular permissions at org and project levels
- ๐ Project & Task Management - Full workflow support with status transitions
- ๐ Activity Audit Trail - Immutable logs of all system actions
- โก Rate Limiting - Token bucket strategy for API protection
- ๐ Prometheus Metrics - Built-in monitoring and observability
- ๐ Structured Logging - JSON logging with correlation IDs
- โ Input Validation - Schema-based validation for all requests
- ๐ณ Docker Support - PostgreSQL container for easy setup
- Language: Go 1.25
- Framework: Chi router
- Database: PostgreSQL 15
- Auth: JWT with golang-jwt/jwt
- Validation: go-playground/validator
- Logging: zerolog
- Metrics: Prometheus
- Containerization: Docker & Docker Compose
- Go 1.25+
- Docker & Docker Compose
- Make (optional)
-
Clone the repository
git clone <repository-url> cd api-architecture
-
Create environment file
cp .env.example .env # Edit .env with your configuration -
Start PostgreSQL
docker-compose up -d
-
Install dependencies
go mod download
-
Run the application
go run cmd/server/main.go
Or using Make:
make run
The API will be available at http://localhost:8080
- OpenAPI Spec: See api/openapi.yaml
- Health Check:
GET /health - Readiness Check:
GET /ready - Metrics:
GET /metrics
.
โโโ api/ # OpenAPI specification
โโโ cmd/
โ โโโ server/ # Application entry point
โโโ internal/ # Private application code
โ โโโ api/v1/ # API routes and handlers
โ โ โโโ handler/ # HTTP request handlers
โ โ โโโ middleware/ # HTTP middleware
โ โ โโโ routes.go # Route definitions
โ โโโ auth/ # Authentication logic
โ โโโ config/ # Configuration management
โ โโโ logger/ # Logging utilities
โ โโโ model/ # Domain models
โ โโโ utils/ # Helper functions
โ โโโ repository.go # Data access layer
โ โโโ service.go # Business logic layer
โ โโโ validator.go # Request validation
โ โโโ response.go # Response helpers
โโโ migrations/ # Database migrations
โโโ tests/ # Test files
โโโ docker-compose.yml # Docker services
โโโ Makefile # Build automation
โโโ README.md # This file
POST /api/v1/auth/register- Register new userPOST /api/v1/auth/login- Login userPOST /api/v1/auth/refresh- Refresh access tokenPOST /api/v1/auth/logout- Logout user
GET /api/v1/users/me- Get current user profilePATCH /api/v1/users/me- Update profileDELETE /api/v1/users/me- Delete account
POST /api/v1/organizations- Create organizationGET /api/v1/organizations- List organizationsGET /api/v1/organizations/{id}- Get organizationPATCH /api/v1/organizations/{id}- Update organizationDELETE /api/v1/organizations/{id}- Delete organization
POST /api/v1/organizations/{id}/members- Add memberGET /api/v1/organizations/{id}/members- List membersPATCH /api/v1/organizations/{id}/members/{user_id}- Update member roleDELETE /api/v1/organizations/{id}/members/{user_id}- Remove member
POST /api/v1/organizations/{id}/projects- Create projectGET /api/v1/organizations/{id}/projects- List projectsGET /api/v1/projects/{id}- Get projectPATCH /api/v1/projects/{id}- Update projectDELETE /api/v1/projects/{id}- Delete project
POST /api/v1/projects/{id}/tasks- Create taskGET /api/v1/projects/{id}/tasks- List tasksGET /api/v1/tasks/{id}- Get taskPATCH /api/v1/tasks/{id}- Update taskDELETE /api/v1/tasks/{id}- Delete task
POST /api/v1/tasks/{id}/assignees- Assign userDELETE /api/v1/tasks/{id}/assignees/{user_id}- Unassign userPOST /api/v1/tasks/{id}/comments- Add commentGET /api/v1/tasks/{id}/comments- List commentsDELETE /api/v1/comments/{id}- Delete comment
GET /api/v1/projects/{id}/activities- Get project activitiesGET /api/v1/tasks/{id}/activities- Get task activities
Run tests:
go test -v ./...Run tests with coverage:
make test-coverageConfiguration is loaded from environment variables. See .env.example for all available options.
Key configuration:
JWT_SECRET- Secret key for JWT signing (change in production!)DB_*- Database connection parametersRATE_LIMIT_*- Rate limiting thresholdsLOG_LEVEL- Logging level (debug, info, warn, error)
The database schema is automatically applied on first startup via Docker. See migrations/001_init_schema.sql for the complete schema.
Key tables:
users- User accountsorganizations- Top-level tenantsorg_memberships- User-organization relationshipsprojects- Projects within organizationsproject_memberships- User-project relationshipstasks- Work itemstask_assignments- Task assigneestask_comments- Task discussionsactivities- Audit logrefresh_tokens- Session management
Rate limits are enforced per IP address:
- General endpoints: 100 requests/min
- Auth endpoints: 10 requests/min
- Write operations: 60 requests/min
- Bulk operations: 20 requests/min
- Passwords hashed with bcrypt (cost 12)
- JWT tokens with short expiration (15 min)
- Refresh token rotation on use
- SQL injection prevention via parameterized queries
- Input validation on all endpoints
- CORS configuration
- Request ID tracking
Prometheus metrics are exposed at /metrics:
- HTTP request counts by method, path, and status
- Request duration histograms
- Database connection pool stats
make buildmake runmake docker-up # Start services
make docker-down # Stop services
make docker-clean # Stop and remove volumes