API for air quality monitoring, navigation, and hazard reporting built with NestJS, PostgreSQL, and Redis.
-
Air Quality Monitoring
- Real-time air quality data from multiple sources
- Historical data analysis
- Pollution forecasting
- Customizable alerts
-
Navigation System
- Smart routing with air quality consideration
- Hazard avoidance
- Custom route preferences
-
User Management
- Authentication and authorization
- User preferences
- Subscription management
-
Reporting System
- Hazard reporting
- Community-driven updates
- Report moderation
-
Notifications
- Real-time alerts
- Custom notification preferences
- Multiple delivery channels
- Backend Framework: NestJS
- Database: PostgreSQL
- Caching: Redis
- Authentication: JWT
- Documentation: Swagger/OpenAPI
- Testing: Jest
- Air Quality Data Sources: OpenWeatherMap, WAQI
- Docker and Docker Compose
- Node.js (v18 or higher)
- npm or yarn
-
Clone the repository
git clone https://github.com/yourusername/air-quality-api.git cd air-quality-api
-
Set up environment variables
cp .env.example .env
Edit
.env
file with your configuration:- Add your OpenWeatherMap API key
- Configure JWT secret
- Adjust database credentials if needed
-
Start the application with Docker
docker-compose up -d
This command starts:
- NestJS API (http://localhost:3000)
- PostgreSQL (localhost:5432)
- Redis (localhost:6379)
-
View logs
docker-compose logs -f
-
Stop the application
docker-compose down
- Created a seed service for adding admin and moderator users.
- Added a seed script to run the seeding process.
- Integrated the seed module into the main application.
To seed the database with initial roles:
npm run seed
This will create:
-
Admin User:
Email:admin@example.com
Password:admin123
-
Moderator User:
Email:moderator@example.com
Password:moderator123
- Implemented a scheduled job using
@nestjs/schedule
. - The job runs every hour to fetch air quality data.
- Added error handling and logging for the fetch process.
Details:
- The job fetches data for predefined cities.
- The data is stored in the database.
- Logs are generated for monitoring the process.
These features ensure:
- Role-based authentication is initialized with admin and moderator accounts.
- Automated air quality data collection is fully operational.
-
Install dependencies
npm install
-
Run in development mode
npm run start:dev
-
Run tests
# Unit tests npm run test # e2e tests npm run test:e2e # Test coverage npm run test:cov
Access the Swagger documentation at: http://localhost:3000/api
-
Presentation Layer (Controllers)
- HTTP request handling
- Input validation
- Response formatting
-
Application Layer (Services)
- Business logic
- Use case implementation
- Service orchestration
-
Domain Layer (Entities)
- Business entities
- Domain logic
- Value objects
-
Infrastructure Layer
- Database access
- External services
- Caching
- Message queues
src/
├── modules/ # Feature modules
│ ├── air-quality/ # Air quality monitoring
│ ├── auth/ # Authentication
│ ├── navigation/ # Route planning
│ ├── notification/ # Alert system
│ ├── report/ # Hazard reporting
│ └── user/ # User management
├── shared/ # Shared utilities
│ ├── decorators/ # Custom decorators
│ ├── filters/ # Exception filters
│ ├── guards/ # Auth guards
│ ├── interfaces/ # Common interfaces
│ └── utils/ # Utility functions
└── config/ # Configuration
- Client makes HTTP request.
- Request passes through middleware (authentication, validation).
- Controller receives the request.
- Service processes business logic.
- Repository handles data access.
- Response flows back through layers.
- Client receives a formatted response.
- REST APIs for synchronous communication.
- Redis pub/sub for real-time updates.
- PostgreSQL for persistent storage.
- Redis for caching and session management.
- Fork the repository.
- Create your feature branch.
- Commit your changes.
- Push to the branch.
- Create a new Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.