Skip to content

codeforgood-org/community-issue-mapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—ΊοΈ Community Issue Mapper

A production-ready crowdsourced issue reporting platform built with Leaflet.js and Go. Report and track community issues like potholes, accessibility problems, broken streetlights, and more.

License Go Version Docker

✨ Features

Core Functionality

  • πŸ—ΊοΈ Interactive Map: Click-to-report issues with Leaflet.js integration
  • πŸ“Έ Image Upload: Attach photos to issue reports (max 10MB)
  • 🏷️ Categorization: Multiple issue categories (pothole, accessibility, streetlight, graffiti, trash, other)
  • πŸ“Š Real-time Statistics: Track total, new, and resolved issues
  • πŸ‘ Community Voting: Upvote important issues to increase visibility
  • πŸ” Advanced Filtering: Filter by category, status, and location
  • πŸ“ Geolocation: Automatic user location detection
  • πŸ“± Responsive Design: Works seamlessly on desktop and mobile

Technical Features

  • ⚑ RESTful API: Clean, well-documented API endpoints
  • 🐘 PostgreSQL Database: Robust data persistence with proper indexing
  • 🐳 Docker Ready: Full containerization with docker-compose
  • πŸ”’ Production Security: CORS, rate limiting, input validation
  • πŸ“ˆ Scalable Architecture: Clean architecture pattern with repository layer
  • πŸš€ CI/CD Pipeline: Automated testing and deployment with GitHub Actions
  • πŸ“ Comprehensive Logging: Request/response logging for debugging
  • πŸ₯ Health Checks: Built-in health and readiness endpoints

πŸ—οΈ Architecture

community-issue-mapper/
β”œβ”€β”€ backend/                    # Go backend application
β”‚   β”œβ”€β”€ cmd/
β”‚   β”‚   └── server/            # Application entry point
β”‚   β”œβ”€β”€ internal/
β”‚   β”‚   β”œβ”€β”€ api/               # API layer
β”‚   β”‚   β”‚   β”œβ”€β”€ handlers/      # HTTP handlers
β”‚   β”‚   β”‚   β”œβ”€β”€ middleware/    # Middleware (CORS, logging, rate limiting)
β”‚   β”‚   β”‚   └── router.go      # Route definitions
β”‚   β”‚   β”œβ”€β”€ config/            # Configuration management
β”‚   β”‚   β”œβ”€β”€ database/          # Database connection
β”‚   β”‚   β”œβ”€β”€ models/            # Data models
β”‚   β”‚   β”œβ”€β”€ repository/        # Data access layer
β”‚   β”‚   └── service/           # Business logic layer
β”‚   β”œβ”€β”€ migrations/            # Database migrations
β”‚   └── go.mod                 # Go dependencies
β”œβ”€β”€ frontend/                  # Frontend application
β”‚   β”œβ”€β”€ css/                   # Stylesheets
β”‚   β”œβ”€β”€ js/                    # JavaScript modules
β”‚   β”‚   β”œβ”€β”€ api.js            # API client
β”‚   β”‚   β”œβ”€β”€ map.js            # Map management
β”‚   β”‚   └── app.js            # Main application logic
β”‚   └── index.html            # Main HTML file
β”œβ”€β”€ uploads/                   # Uploaded images storage
β”œβ”€β”€ .github/workflows/         # GitHub Actions CI/CD
β”œβ”€β”€ docker-compose.yml         # Docker composition
β”œβ”€β”€ Dockerfile                 # Docker image definition
└── README.md                 # This file

πŸš€ Quick Start

Prerequisites

  • Docker and Docker Compose (recommended)
  • OR Go 1.21+ and PostgreSQL 14+

Option 1: Docker (Recommended)

  1. Clone the repository

    git clone https://github.com/codeforgood-org/community-issue-mapper.git
    cd community-issue-mapper
  2. Create environment file

    cp .env.example .env
    # Edit .env with your preferred settings
  3. Start the application

    docker-compose up -d
  4. Run migrations

    docker-compose run migrate
  5. Access the application

Option 2: Local Development

  1. Install dependencies

    cd backend
    go mod download
  2. Set up PostgreSQL

    createdb community_issues
  3. Run migrations

    # Install migrate tool first
    brew install golang-migrate  # macOS
    # or download from https://github.com/golang-migrate/migrate
    
    make migrate-up
  4. Start the server

    make run
    # or with auto-reload (requires air)
    make dev

πŸ“š API Documentation

Base URL

http://localhost:8080/api/v1

Endpoints

Issues

List Issues
GET /api/v1/issues

Query Parameters:

  • category (optional): Filter by category (pothole, accessibility, streetlight, graffiti, trash, other)
  • status (optional): Filter by status (new, in_progress, resolved, closed)
  • min_lat, max_lat, min_lng, max_lng (optional): Bounding box filter
  • limit (optional): Maximum number of results (default: 100, max: 1000)
  • offset (optional): Pagination offset

Response:

[
  {
    "id": 1,
    "title": "Large pothole on Main Street",
    "description": "Dangerous pothole near the intersection",
    "category": "pothole",
    "status": "new",
    "latitude": 37.7749,
    "longitude": -122.4194,
    "address": "123 Main St",
    "image_url": "/uploads/1.jpg",
    "reporter_name": "John Doe",
    "reporter_email": "john@example.com",
    "votes": 5,
    "created_at": "2025-01-01T10:00:00Z",
    "updated_at": "2025-01-01T10:00:00Z"
  }
]
Create Issue
POST /api/v1/issues
Content-Type: application/json

Request Body:

{
  "title": "Broken streetlight",
  "description": "Streetlight not working for 2 weeks",
  "category": "streetlight",
  "latitude": 37.7749,
  "longitude": -122.4194,
  "address": "456 Oak Ave",
  "reporter_name": "Jane Smith",
  "reporter_email": "jane@example.com"
}
Get Issue
GET /api/v1/issues/{id}
Update Issue
PATCH /api/v1/issues/{id}
Content-Type: application/json

Request Body (all fields optional):

{
  "title": "Updated title",
  "description": "Updated description",
  "status": "in_progress",
  "category": "pothole"
}
Delete Issue
DELETE /api/v1/issues/{id}
Upload Image
POST /api/v1/issues/{id}/upload
Content-Type: multipart/form-data

Form Data:

  • image: Image file (max 10MB)
Vote for Issue
POST /api/v1/issues/{id}/vote

Statistics

Get Statistics
GET /api/v1/stats

Response:

{
  "total_issues": 150,
  "issues_by_status": {
    "new": 45,
    "in_progress": 30,
    "resolved": 60,
    "closed": 15
  },
  "issues_by_category": {
    "pothole": 40,
    "accessibility": 25,
    "streetlight": 20,
    "graffiti": 15,
    "trash": 30,
    "other": 20
  }
}

Health Checks

Health Check
GET /health
Readiness Check
GET /ready

πŸ› οΈ Development

Available Make Commands

make help              # Show all available commands
make build             # Build the application
make run               # Run the application
make test              # Run tests
make test-coverage     # Run tests with coverage report
make clean             # Clean build artifacts
make docker-build      # Build Docker image
make docker-up         # Start Docker containers
make docker-down       # Stop Docker containers
make docker-logs       # View Docker logs
make migrate-up        # Run database migrations up
make migrate-down      # Run database migrations down
make migrate-create    # Create a new migration
make deps              # Download dependencies
make lint              # Run linter
make dev               # Run with auto-reload

Running Tests

cd backend
go test -v ./...

# With coverage
go test -v -race -coverprofile=coverage.out ./...
go tool cover -html=coverage.out

Creating Database Migrations

make migrate-create name=add_new_field

This creates two files in backend/migrations/:

  • {timestamp}_add_new_field.up.sql
  • {timestamp}_add_new_field.down.sql

🌍 Environment Variables

Variable Description Default
PORT Server port 8080
ENV Environment (development/production) development
DB_HOST Database host localhost
DB_PORT Database port 5432
DB_USER Database user issueapp
DB_PASSWORD Database password issueapp_password
DB_NAME Database name community_issues
DB_SSL_MODE Database SSL mode disable
CORS_ALLOWED_ORIGINS Allowed CORS origins *
MAX_UPLOAD_SIZE Max upload size in bytes 10485760 (10MB)
UPLOAD_DIR Upload directory ./uploads
RATE_LIMIT_REQUESTS Rate limit requests 100
RATE_LIMIT_DURATION Rate limit duration 1m

πŸ“¦ Deployment

Docker Deployment

  1. Build and push Docker image

    docker build -t your-registry/community-issue-mapper:latest .
    docker push your-registry/community-issue-mapper:latest
  2. Deploy with docker-compose

    docker-compose up -d

Cloud Deployment

The application can be easily deployed to:

  • AWS ECS/Fargate: Use the included Dockerfile
  • Google Cloud Run: Supports container deployment
  • Azure Container Instances: Direct Docker deployment
  • Heroku: Use container registry
  • DigitalOcean App Platform: Docker-based deployment

Environment-specific configurations

  • Set ENV=production for production
  • Use proper database credentials
  • Configure CORS origins appropriately
  • Set up SSL/TLS termination at load balancer
  • Use managed PostgreSQL service for production

πŸ”’ Security

  • βœ… CORS protection with configurable origins
  • βœ… Rate limiting to prevent abuse
  • βœ… Input validation and sanitization
  • βœ… SQL injection prevention (parameterized queries)
  • βœ… File upload validation
  • βœ… Secure headers
  • ⚠️ TODO: Add authentication/authorization
  • ⚠️ TODO: Add HTTPS enforcement
  • ⚠️ TODO: Add API key management

πŸ§ͺ Testing

The project includes:

  • Unit tests for repository layer
  • Integration tests for API endpoints
  • GitHub Actions CI/CD pipeline
  • Code coverage reporting

πŸ“Š Monitoring

Health Checks

  • /health: Database connectivity check
  • /ready: Application readiness check

Logging

All requests are logged with:

  • HTTP method
  • Request URI
  • Response status
  • Response size
  • Request duration

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“§ Support

For support, please open an issue on GitHub or contact the maintainers.

πŸ—ΊοΈ Roadmap

  • User authentication and authorization
  • Email notifications for issue updates
  • Admin dashboard for issue management
  • Mobile applications (iOS/Android)
  • SMS notifications
  • Integration with city management systems
  • Analytics and reporting dashboard
  • Multi-language support
  • Dark mode
  • Offline support with PWA

Built with ❀️ for communities everywhere

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •