# Adopt-a-Street A community street adoption platform where users can adopt streets, complete maintenance tasks, participate in events, and earn rewards through a gamification system. ## ๐Ÿ—๏ธ Architecture - **Frontend**: React 19 with React Router v6, Leaflet mapping, Socket.IO client - **Backend**: Node.js/Express with CouchDB database - **Deployment**: Kubernetes on Raspberry Pi cluster - **Real-time**: Socket.IO for live updates ## ๐Ÿš€ Quick Start ### Prerequisites - Node.js 18+ and Bun runtime - CouchDB 3.3+ (or Docker) - Git ### Local Development 1. **Clone the repository** ```bash git clone cd adopt-a-street ``` 2. **Install dependencies** ```bash # Backend cd backend bun install # Frontend cd ../frontend bun install ``` 3. **Set up CouchDB** **Option A: Docker (Recommended)** ```bash # From project root docker-compose up -d couchdb # Wait for CouchDB to start sleep 10 # Setup database and indexes cd backend bun run setup:couchdb ``` **Option B: Manual Installation** ```bash # Install CouchDB locally # Follow instructions at: https://docs.couchdb.org/en/stable/install/index.html # Setup database and indexes cd backend COUCHDB_URL=http://localhost:5984 \ COUCHDB_USER=admin \ COUCHDB_PASSWORD=admin \ bun run setup:couchdb ``` 4. **Configure environment** ```bash # Backend cd backend cp .env.example .env # Edit .env with your CouchDB credentials and other settings # Frontend cd ../frontend cp .env.example .env # Edit .env with your API URL ``` 5. **Seed initial data** ```bash cd backend bun run seed:badges ``` 6. **Start the applications** ```bash # Backend (in one terminal) cd backend bun run dev # Frontend (in another terminal) cd frontend bun start ``` 7. **Access the application** - Frontend: http://localhost:3000 - Backend API: http://localhost:5000 - CouchDB Admin: http://localhost:5984/_utils ### Docker Development Use Docker Compose for the complete stack: ```bash # Start all services docker-compose up -d # View logs docker-compose logs -f # Stop services docker-compose down ``` ## ๐Ÿ“ฆ Database Migration If you're migrating from MongoDB to CouchDB: ```bash # Run migration script node scripts/migrate-to-couchdb.js # For production migration node scripts/migrate-production.js ``` See [COUCHDB_SETUP.md](COUCHDB_SETUP.md) for detailed migration instructions. ## ๐Ÿงช Testing ### Backend Tests ```bash cd backend bun test # Run all tests bun run test:coverage # Run with coverage bun run test:watch # Run in watch mode ``` ### Frontend Tests ```bash cd frontend bun test # Run in watch mode bun run test:coverage # Run with coverage ``` ## ๐Ÿšข Deployment ### Kubernetes (Production) The application is designed for deployment on a Kubernetes cluster, specifically optimized for Raspberry Pi hardware. 1. **Build multi-arch Docker images** ```bash docker buildx create --use --name multiarch-builder docker buildx build --platform linux/arm64,linux/arm/v7 \ -t your-registry/adopt-a-street-backend:latest \ --push ./backend docker buildx build --platform linux/arm64,linux/arm/v7 \ -t your-registry/adopt-a-street-frontend:latest \ --push ./frontend ``` 2. **Deploy to Kubernetes** ```bash # Configure secrets cp deploy/k8s/secrets.yaml.example deploy/k8s/secrets.yaml # Edit secrets with your values # Deploy all services cd deploy/k8s kubectl apply -f namespace.yaml kubectl apply -f secrets.yaml kubectl apply -f couchdb-configmap.yaml kubectl apply -f couchdb-statefulset.yaml kubectl apply -f configmap.yaml kubectl apply -f backend-deployment.yaml kubectl apply -f frontend-deployment.yaml kubectl apply -f ingress.yaml ``` See [deploy/README.md](deploy/README.md) for detailed deployment instructions. ## ๐Ÿ“ Project Structure ``` adopt-a-street/ โ”œโ”€โ”€ backend/ # Node.js/Express API โ”‚ โ”œโ”€โ”€ models/ # Data models (CouchDB service) โ”‚ โ”œโ”€โ”€ routes/ # API routes โ”‚ โ”œโ”€โ”€ middleware/ # Express middleware โ”‚ โ”œโ”€โ”€ services/ # Business logic โ”‚ โ”œโ”€โ”€ scripts/ # Utility scripts โ”‚ โ””โ”€โ”€ __tests__/ # Backend tests โ”œโ”€โ”€ frontend/ # React application โ”‚ โ”œโ”€โ”€ src/ โ”‚ โ”‚ โ”œโ”€โ”€ components/ # React components โ”‚ โ”‚ โ”œโ”€โ”€ context/ # React Context โ”‚ โ”‚ โ””โ”€โ”€ __tests__/ # Frontend tests โ”‚ โ””โ”€โ”€ public/ # Static assets โ”œโ”€โ”€ deploy/ # Kubernetes manifests โ”‚ โ””โ”€โ”€ k8s/ # Deployment configurations โ”œโ”€โ”€ scripts/ # Migration and setup scripts โ”œโ”€โ”€ couchdb/ # CouchDB configuration โ””โ”€โ”€ docs/ # Documentation ``` ## ๐Ÿ”ง Configuration ### Environment Variables #### Backend (.env) ```bash # CouchDB Configuration COUCHDB_URL=http://localhost:5984 COUCHDB_DB_NAME=adopt-a-street COUCHDB_USER=admin COUCHDB_PASSWORD=admin # JWT Authentication JWT_SECRET=your-super-secret-jwt-key # Server Configuration PORT=5000 NODE_ENV=development FRONTEND_URL=http://localhost:3000 # Cloudinary (for image uploads) CLOUDINARY_CLOUD_NAME=your_cloud_name CLOUDINARY_API_KEY=your_api_key CLOUDINARY_API_SECRET=your_api_secret # Stripe (for payments) STRIPE_SECRET_KEY=your_stripe_secret STRIPE_PUBLISHABLE_KEY=your_stripe_publishable # OpenAI (for AI features) OPENAI_API_KEY=your_openai_key ``` #### Frontend (.env) ```bash REACT_APP_API_URL=http://localhost:5000 ``` ## ๐Ÿ›๏ธ API Endpoints - `/api/auth` - User authentication - `/api/users` - User management - `/api/streets` - Street adoption - `/api/tasks` - Maintenance tasks - `/api/posts` - Social feed - `/api/events` - Community events - `/api/rewards` - Points and badges - `/api/reports` - Issue reporting - `/api/ai` - AI-powered features - `/api/payments` - Premium subscriptions ## ๐ŸŽฎ Features - **Street Adoption**: Adopt and maintain local streets - **Task Management**: Create and complete maintenance tasks - **Social Feed**: Share updates and interact with community - **Events**: Organize and participate in community events - **Gamification**: Earn points, badges, and rewards - **Real-time Updates**: Live notifications via Socket.IO - **Interactive Maps**: Visualize adopted streets with Leaflet - **Mobile Responsive**: Works on all device sizes ## ๐Ÿ”’ Security - JWT-based authentication - Input validation and sanitization - Rate limiting - CORS configuration - Helmet.js security headers - Environment-based configuration ## ๐Ÿ“Š Monitoring - CouchDB metrics exporter (Prometheus compatible) - Health check endpoints - Application logging - Error tracking with ErrorBoundary ## ๐Ÿค Contributing 1. Fork the repository 2. Create a feature branch 3. Make your changes 4. Add tests for new functionality 5. Run the test suite 6. Commit your changes with conventional commit messages 7. Push to your fork 8. Create a pull request ## ๐Ÿ“ License This project is licensed under the ISC License. ## ๐Ÿ†˜ Support For issues and questions: 1. Check the [documentation](docs/) 2. Search existing [issues](../../issues) 3. Create a new issue with detailed information 4. Join our community discussions ## ๐Ÿ—บ๏ธ Roadmap - [ ] Mobile app development - [ ] Advanced analytics dashboard - [ ] Integration with city services - [ ] Machine learning for task prioritization - [ ] Multi-language support - [ ] Enhanced offline capabilities --- **Built with โค๏ธ for community engagement and street maintenance**