# ahmad-danaf/spacecodey architecture

> Architecture diagram of the GitHub repository ahmad-danaf/spacecodey, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ahmad-danaf/spacecodey
- Repository: https://github.com/ahmad-danaf/spacecodey

## Overview

##### Project Type and Purpose
- Type: Full-stack monolithic web application built on Django.
- Purpose: Provide astrophotographers and space enthusiasts with user accounts, daily NASA images, ISS tracking, weather comparison, optimal shoot times, tips & articles.

##### Main Components
a. Client / Frontend
– Web browser or mobile client
– Static assets: HTML templates, CSS, JavaScript under `/templates` and `/static`
b. Django Application (Monolith)
– ASGI/WSGI entrypoint (`asgi.py`, `wsgi.py`)
– URL router (`urls.py`)
– View layer (`views.py` in each app + global `views.py`)
– Models (`models.py`) + ORM (SQLite by default)
– Apps (each a logical module):
- user_management
- content
- events
- nasa_info
- weather
– Management commands (background jobs):
- `fetch_events` (pull events from external calendar APIs)
- `delete_old_events`
c. Database
– SQLite (or Postgres/MySQL in production)
– Stores users, articles, events, weather history, etc.
d. External Services / APIs
– NASA APOD API
– ISS Tracking API
– Weather APIs (for real-time comparisons)
e. Deployment / Infrastructure
– Azure Web App (or VM)
– GitHub Actions CI/CD (`.github/workflows/deploy.yml`)
– Environment variables (.env for API keys)

##### Relationships and Data Flows
– User → HTTP(S) → Django ASGI/WSGI → URL router → App View → Model/DB → Render Template → HTTP Response → User
– App View → External API Client (e.g., in `nasa_info/views.py`, `weather/views.py`, `events/utils.py`) → API Response → Transform & Cache if needed → Display to User
– Management Command (cron/worker) → Django ORM → Fetch & Clean Data → Update DB
– Static Assets served via Django `collectstatic` or CDN
– Email Verification Flow:
User → Register View (user_management) → Send Email via SMTP → Verification Link → Confirm View → Activate Account

##### Architectural Patterns & Design Principles
– Monolithic, modular design using Django Apps (separation by feature).
– MVC/MVT pattern: Models, Views (logic), Templates.
– Single database for all apps.
– Reuse of Django’s authentication framework extended in `user_management`.
– Background tasks implemented as Django management commands.
– API wrappers/utilities isolated in `utils` packages.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client / Browser"]:::frontend

    %% Django Monolith
    subgraph "Django Monolith"
        direction TB
        ASGI["ASGI Entrypoint"]:::backend
        WSGI["WSGI Entrypoint"]:::backend
        Router["URL Dispatcher (urls.py)"]:::backend
        subgraph "Django Apps"
            direction TB
            UM["user_management"]:::backend
            Content["content"]:::backend
            Events["events"]:::backend
            Nasa["nasa_info"]:::backend
            Weather["weather"]:::backend
        end
        ORM["ORM & Models"]:::backend
    end

    %% Database
    DB["SQLite Database"]:::database

    %% External APIs
    subgraph "External APIs"
        direction TB
        NASAAPI["NASA APOD API"]:::external
        ISSAPI["ISS Tracking API"]:::external
        WeatherAPI["Weather API"]:::external
    end

    %% Infrastructure
    Scheduler["Scheduler / Cron"]:::infra
    Static["Static File Server / CDN"]:::infra
    CI["CI/CD Pipeline"]:::infra
    Azure["Azure Web App"]:::infra

    %% Data Flows
    Client -->|HTTP GET/POST| ASGI
    Client -->|HTTP GET/POST| WSGI
    ASGI --> Router
    WSGI --> Router
    Router --> UM
    Router --> Content
    Router --> Events
    Router --> Nasa
    Router --> Weather
    UM --> ORM
    Content --> ORM
    Events --> ORM
    Nasa --> ORM
    Weather --> ORM
    ORM -->|SQL SELECT/INSERT| DB
    Router -->|collectstatic| Static
    Static --> Client

    %% External Service Calls
    Nasa -.->|HTTP Request| NASAAPI
    Events -.->|HTTP Request| ISSAPI
    Weather -.->|HTTP Request| WeatherAPI

    %% Background Tasks
    Scheduler -.->|triggers commands| Events

    %% Deployment
    CI -->|deploy| Azure
    Azure -->|hosts| ASGI
    Azure -->|hosts| WSGI

    %% Click Events
    click Static "https://github.com/ahmad-danaf/spacecodey/tree/production/SpaceCodey/static/"
    click ASGI "https://github.com/ahmad-danaf/spacecodey/blob/production/SpaceCodey/SpaceCodey/asgi.py"
    click WSGI "https://github.com/ahmad-danaf/spacecodey/blob/production/SpaceCodey/SpaceCodey/wsgi.py"
    click Router "https://github.com/ahmad-danaf/spacecodey/blob/production/SpaceCodey/SpaceCodey/urls.py"
    click UM "https://github.com/ahmad-danaf/spacecodey/tree/production/SpaceCodey/user_management/"
    click Content "https://github.com/ahmad-danaf/spacecodey/tree/production/SpaceCodey/content/"
    click Events "https://github.com/ahmad-danaf/spacecodey/tree/production/SpaceCodey/events/"
    click Nasa "https://github.com/ahmad-danaf/spacecodey/tree/production/SpaceCodey/nasa_info/"
    click Weather "https://github.com/ahmad-danaf/spacecodey/tree/production/SpaceCodey/weather/"
    click CI "https://github.com/ahmad-danaf/spacecodey/blob/production/.github/workflows/deploy.yml"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#333,stroke-width:1px
    classDef backend fill:#c8e6c9,stroke:#333,stroke-width:1px
    classDef external fill:#ffe0b2,stroke:#333,stroke-width:1px
    classDef database fill:#eeeeee,stroke:#333,stroke-width:1px
    classDef infra fill:#d1c4e9,stroke:#333,stroke-width:1px
```
