# cyfer-ap/n-sih-1 architecture

> Architecture diagram of the GitHub repository cyfer-ap/n-sih-1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cyfer-ap/n-sih-1
- Repository: https://github.com/cyfer-ap/n-sih-1

## Overview

##### Project type and purpose
- This is a monolithic full-stack Django web application (“N-SIH: NASA–ISRO Satellite Explorer”) that serves dynamic HTML/CSS/JS pages, pulls data from external APIs (NASA & N2YO), and uses static JSON for some ISRO mission data.
- It exposes multiple user-facing modules (APOD, Mars gallery, Earth imagery, satellite trackers, space weather, ISRO missions) via two Django apps: `nasa_app` and `isro`.

##### File structure
- Top-level:
- `manage.py`, `requirements.txt`, `render.yaml`, `.gitignore`
- `nasa_project/` – Django project settings, ASGI/WSGI entrypoints
- `nasa_app/` – Core NASA-related features (views, templates, static assets)
- `isro/` – ISRO-related features (static JSON, views, templates)
- `db.sqlite3` – local development database
- Each app follows Django conventions:
- `models.py`, `views.py`, `urls.py`, `templates/<app>/`, `static/<app>/`
- `migrations/` for schema changes
- Configuration / deployment:
- `python-dotenv` for `.env` (API keys)
- `gunicorn`, `whitenoise` for production
- `render.yaml` for Render.com deployment

##### Key insights from the README
- Real-time API integrations: NASA APOD, Mars Rover, Media Library, Earth Imagery, N2YO satellite tracker
- Static mission data in JSON for ISRO module
- Vanilla frontend (HTML, CSS, JS) served by Django templates and static files
- SQLite for local dev but interchangeable with any relational DB

##### Main components & interactions
a. Users & Clients
- Web browser or mobile browser (HTML/CSS/JS)
b. Frontend Layer (served by Django)
- Templates (`*.html`), CSS (`*.css`), JS (`*.js`), JSON static files
- Whitenoise middleware serves static assets in production
c. Django Application Layer
- `nasa_project` (project settings & URL router)
- Two Django apps:
– `nasa_app.views` → pulls from NASA APIs, renders templates
– `isro.views` → reads static JSON, calls N2YO for live ISRO tracking
- Models: minimal or none (data mostly transient or static JSON)
d. Database
- SQLite (via Django ORM) – used for any persisted data (e.g., user settings if extended)
e. External Services
- NASA APIs (APOD, Rover, Media, Earth Imagery)
- N2YO Satellite Tracking API
f. Deployment & Infrastructure
- Gunicorn (WSGI server) behind a load balancer
- Environment variables (`.env`) for secrets
- Optional CDN for static content

##### Architectural patterns & design principles
- Monolithic MVC:
- Views handle HTTP, orchestrate data fetch (API/DB/static), choose template
- Templates handle view logic → static assets
- Models minimal; mostly for Django defaults
- Separation of concerns:
- Two apps (NASA vs ISRO) for modularity
- Static JSON vs live API calls clearly distinguished
- External integration layer:
- Abstract each external API call in its own view or utility function
- Caching or rate-limit safeguards (future improvement)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Browser["Web Browser\n(Client)"]:::frontend

    %% Infrastructure Layer
    LB["Load Balancer\n(Render Router/nginx)"]:::backend
    Gunicorn["Gunicorn\n(WSGI Server)"]:::backend

    %% Django Monolith
    subgraph "Django Monolith" 
        direction TB
        Settings["settings.py"]:::backend
        Urls["urls.py"]:::backend
        ASGI["asgi.py"]:::backend
        WSGI["wsgi.py"]:::backend

        URLRouter["URL Dispatcher"]:::backend

        subgraph "nasa_app"
            direction TB
            AppConfig_NASA["apps.py"]:::backend
            Urls_NASA["urls.py"]:::backend
            Views_NASA["views.py"]:::backend
            Models_NASA["models.py"]:::backend
            Templates_NASA["HTML Templates"]:::frontend
            StaticCSS_NASA["CSS Files"]:::frontend
            StaticJS_NASA["JS Files"]:::frontend
        end

        subgraph "isro"
            direction TB
            AppConfig_ISRO["apps.py"]:::backend
            Urls_ISRO["urls.py"]:::backend
            Views_ISRO["views.py"]:::backend
            Models_ISRO["models.py"]:::backend
            Templates_ISRO["HTML Templates"]:::frontend
            StaticCSS_ISRO["CSS Files"]:::frontend
            StaticJS_ISRO["JS Files"]:::frontend
            JSONStatic["isro_missions.json"]:::data
        end

        URLRouter --> AppConfig_NASA
        URLRouter --> AppConfig_ISRO
    end

    %% Static/File Server
    StaticServer["Static/File Server\n(Whitenoise/CDN)"]:::frontend

    %% Data Store
    DB["SQLite Database\n(db.sqlite3)"]:::data

    %% External Services
    subgraph "External APIs"
        direction TB
        NASA_APOD["NASA APOD API"]:::external
        NASA_Rover["NASA Rover API"]:::external
        NASA_Media["NASA Media API"]:::external
        NASA_Earth["NASA Earth Imagery API"]:::external
        N2YO["N2YO Satellite API"]:::external
    end

    %% Env & Deployment
    Env[".env (API Keys)"]:::backend
    Requirements["requirements.txt"]:::backend
    RenderConfig["render.yaml"]:::backend

    %% Connections
    Browser -->|"HTTP GET"| LB
    LB --> Gunicorn
    Gunicorn -->|WSGI Call| Settings
    Settings --> Urls
    Urls --> URLRouter

    URLRouter --> Views_NASA
    URLRouter --> Views_ISRO

    Views_NASA -->|ORM Queries| DB
    Views_NASA -->|HTTP Requests| NASA_APOD
    Views_NASA -->|HTTP Requests| NASA_Rover
    Views_NASA -->|HTTP Requests| NASA_Media
    Views_NASA -->|HTTP Requests| NASA_Earth

    Views_ISRO -->|Read Static JSON| JSONStatic
    Views_ISRO -->|HTTP Requests| N2YO
    Views_ISRO -->|ORM Queries| DB

    Views_NASA -->|Render| Templates_NASA
    Views_ISRO -->|Render| Templates_ISRO

    Templates_NASA -->|Served| StaticServer
    Templates_ISRO -->|Served| StaticServer
    Browser -->|Fetch CSS/JS| StaticServer

    Gunicorn -->|Serves Static| StaticServer

    Settings -->|Middleware| StaticServer
    Settings -->|Middleware| Env

    Settings -->|Configured by| Requirements
    Settings -->|Deployment| RenderConfig

    %% Click Events
    click Settings "https://github.com/cyfer-ap/n-sih-1/blob/main/nasa_project/settings.py"
    click Urls "https://github.com/cyfer-ap/n-sih-1/blob/main/nasa_project/urls.py"
    click ASGI "https://github.com/cyfer-ap/n-sih-1/blob/main/nasa_project/asgi.py"
    click WSGI "https://github.com/cyfer-ap/n-sih-1/blob/main/nasa_project/wsgi.py"

    click AppConfig_NASA "https://github.com/cyfer-ap/n-sih-1/blob/main/nasa_app/apps.py"
    click Urls_NASA "https://github.com/cyfer-ap/n-sih-1/blob/main/nasa_app/urls.py"
    click Views_NASA "https://github.com/cyfer-ap/n-sih-1/blob/main/nasa_app/views.py"
    click Models_NASA "https://github.com/cyfer-ap/n-sih-1/blob/main/nasa_app/models.py"
    click Templates_NASA "https://github.com/cyfer-ap/n-sih-1/tree/main/nasa_app/templates/nasa_app"
    click StaticCSS_NASA "https://github.com/cyfer-ap/n-sih-1/tree/main/nasa_app/static/css"
    click StaticJS_NASA "https://github.com/cyfer-ap/n-sih-1/tree/main/nasa_app/static/js"

    click AppConfig_ISRO "https://github.com/cyfer-ap/n-sih-1/blob/main/isro/apps.py"
    click Urls_ISRO "https://github.com/cyfer-ap/n-sih-1/blob/main/isro/urls.py"
    click Views_ISRO "https://github.com/cyfer-ap/n-sih-1/blob/main/isro/views.py"
    click Models_ISRO "https://github.com/cyfer-ap/n-sih-1/blob/main/isro/models.py"
    click Templates_ISRO "https://github.com/cyfer-ap/n-sih-1/tree/main/isro/templates/isro"
    click StaticCSS_ISRO "https://github.com/cyfer-ap/n-sih-1/tree/main/isro/static/isro/css"
    click StaticJS_ISRO "https://github.com/cyfer-ap/n-sih-1/tree/main/isro/static/isro/js"
    click JSONStatic "https://github.com/cyfer-ap/n-sih-1/blob/main/isro/static/isro/data/isro_missions.json"

    click DB "https://github.com/cyfer-ap/n-sih-1/blob/main/db.sqlite3"
    click Requirements "https://github.com/cyfer-ap/n-sih-1/blob/main/requirements.txt"
    click RenderConfig "https://github.com/cyfer-ap/n-sih-1/blob/main/render.yaml"

    %% Styles
    classDef frontend fill:#ccffcc,stroke:#33aa33,stroke-width:1px
    classDef backend fill:#cce0ff,stroke:#3366cc,stroke-width:1px
    classDef external fill:#ffe0b3,stroke:#ff9933,stroke-width:1px
    classDef data fill:#e0e0e0,stroke:#888888,stroke-width:1px
```
