8000 GitHub - airqi-com/airqi-backend
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

airqi-com/airqi-backend

Repository files navigation

Air Quality Monitoring and Navigation API

API for air quality monitoring, navigation, and hazard reporting built with NestJS, PostgreSQL, and Redis.

Table of Contents


image

Features

  • 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

Technology Stack

  • Backend Framework: NestJS
  • Database: PostgreSQL
  • Caching: Redis
  • Authentication: JWT
  • Documentation: Swagger/OpenAPI
  • Testing: Jest
  • Air Quality Data Sources: OpenWeatherMap, WAQI

Prerequisites

  • Docker and Docker Compose
  • Node.js (v18 or higher)
  • npm or yarn

Getting Started

  1. Clone the repository

    git clone https://github.com/yourusername/air-quality-api.git
    cd air-quality-api
  2. 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
  3. Start the application with Docker

    docker-compose up -d

    This command starts:

  4. View logs

    docker-compose logs -f
  5. Stop the application

    docker-compose down

Seeding and Fetch Job Features

Role Seeding

  • 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

Air Quality Fetch Job

  • 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.

Development

  1. Install dependencies

    npm install
  2. Run in development mode

    npm run start:dev
  3. Run tests

    # Unit tests
    npm run test
    
    # e2e tests
    npm run test:e2e
    
    # Test coverage
    npm run test:cov

API Documentation

Access the Swagger documentation at: http://localhost:3000/api

Architecture

Layered Architecture

  1. Presentation Layer (Controllers)

    • HTTP request handling
    • Input validation
    • Response formatting
  2. Application Layer (Services)

    • Business logic
    • Use case implementation
    • Service orchestration
  3. Domain Layer (Entities)

    • Business entities
    • Domain logic
    • Value objects
  4. Infrastructure Layer

    • Database access
    • External services
    • Caching
    • Message queues

Module Structure

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

Data Flow

  1. Client makes HTTP request.
  2. Request passes through middleware (authentication, validation).
  3. Controller receives the request.
  4. Service processes business logic.
  5. Repository handles data access.
  6. Response flows back through layers.
  7. Client receives a formatted response.

Microservices Communication

  • REST APIs for synchronous communication.
  • Redis pub/sub for real-time updates.
  • PostgreSQL for persistent storage.
  • Redis for caching and session management.

Contributing

  1. Fork the repository.
  2. Create your feature branch.
  3. Commit your changes.
  4. Push to the branch.
  5. Create a new Pull Request.

License

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0