# srijan-petwal/mission-control architecture

> Architecture diagram of the GitHub repository srijan-petwal/mission-control, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/srijan-petwal/mission-control
- Repository: https://github.com/srijan-petwal/mission-control

## Overview

##### Project type and purpose
- This is a full-stack web application (“NASA Mission Control”) for scheduling and tracking mock space launches.
- Frontend: React SPA (create-react-app) served in development via `npm start` and in production as static assets.
- Backend: Node.js + Express REST API, persisting data in MongoDB Atlas via Mongoose, with PM2 clustering for performance.

##### File structure
- Top-level splits into `client/` (React) and `server/` (Express+MongoDB).
- `client/src/` contains React components, pages, and custom hooks.
- `server/src/` follows an MVC-style layout:
- `models/` (Mongoose schemas + in-memory fallback)
- `routes/` (Routers + Controllers for `/planets` and `/launches`)
- `app.js` bootstraps middleware, JSON parsing, CORS, static file serving
- `server.js` launches the Express app (and in production serves React’s build).
- Data ingestion: `server/data/kepler-data.csv` is loaded on startup to populate planets collection.
- PM2 cluster configuration (not in files but described in README) forks multiple Node instances.

##### Key insights from the README
- RESTful endpoints for CRUD on launches and GET on planets.
- MongoDB Atlas persistence via Mongoose models.
- PM2 cluster mode for multi-core scaling.
- React Router handles `/launch`, `/upcoming`, `/history`.

##### Main components and interactions
a. Frontend (React SPA)
- Deployed as static files under `client/public` or served by Express in production.
- Consumes backend REST API over HTTPS (GET/POST/DELETE).
- Uses custom hooks (`usePlanets`, `useLaunches`) to fetch data.
b. Backend (Node.js + Express)
- Exposes `/planets` and `/launches` endpoints via controllers & routers.
- Uses Mongoose models (`planets.mongo.js`, `launches.mongo.js`) to interact with MongoDB Atlas.
- On startup, reads `kepler-data.csv` to seed the planets collection.
- PM2 spawns multiple Node instances to handle concurrent requests.
c. Database (MongoDB Atlas)
- Two main collections: `planets` and `launches`.
- Connection via MONGO_URL (in `.env`).
d. External services
- NASA Kepler Exoplanet Archive (source of CSV data).

##### Architectural patterns & design principles
- Separation of concerns: clear split between presentation (React), API (Express), data (MongoDB).
- MVC‐style backend: models, controllers, routers.
- API-first design: documented REST endpoints.
- Scalability via PM2 clustering.
- Data seeding on startup for exoplanet dataset.

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "Client Layer"
    Browser["Browser"]:::frontend
    SPA["React SPA"]:::frontend
    Index["index.js"]:::frontend
    AppComp["App.js"]:::frontend
    Components["components/"]:::frontend
    Pages["pages/"]:::frontend
    Hooks["hooks/"]:::frontend
    Config["public/, package.json"]:::frontend
  end

  subgraph "Server Layer"
    PM2["PM2 Cluster Manager"]:::external
    subgraph "Express Instances"
      App1["Express Instance"]:::backend
      App2["Express Instance"]:::backend
    end
    AppBootstrap["app.js"]:::backend
    ServerEntry["server.js"]:::backend
    subgraph "Routes & Controllers"
      PlanetsRouter["planets.router.js"]:::backend
      PlanetsCtrl["planets.controller.js"]:::backend
      LaunchesRouter["launches.router.js"]:::backend
      LaunchesCtrl["launches.controller.js"]:::backend
    end
    subgraph "Models"
      PlanetsMongo["planets.mongo.js"]:::backend
      PlanetsModel["planets.model.js"]:::backend
      LaunchesMongo["launches.mongo.js"]:::backend
      LaunchesModel["launches.model.js"]:::backend
    end
  end

  subgraph "Database"
    MongoDB["MongoDB Atlas"]:::db
  end

  subgraph "External Data"
    CSV["kepler-data.csv"]:::external
  end

  Browser -->|"Serves SPA"| SPA
  SPA -->|"HTTPS GET/POST/DELETE"| PM2
  PM2 -->|"fork"| App1
  PM2 -->|"fork"| App2
  ServerEntry -->|"bootstraps"| App1
  ServerEntry -->|"bootstraps"| App2
  App1 -->|"uses routes"| PlanetsRouter
  App1 -->|"uses routes"| LaunchesRouter
  PlanetsRouter -->|"calls"| PlanetsCtrl
  LaunchesRouter -->|"calls"| LaunchesCtrl
  PlanetsCtrl -->|"uses"| PlanetsMongo
  PlanetsCtrl -->|"uses"| PlanetsModel
  LaunchesCtrl -->|"uses"| LaunchesMongo
  LaunchesCtrl -->|"uses"| LaunchesModel
  App1 -->|"TCP/IP"| MongoDB
  App1 -->|"File Read on Startup"| CSV

  click Index "https://github.com/srijan-petwal/mission-control/blob/main/client/src/index.js"
  click AppComp "https://github.com/srijan-petwal/mission-control/blob/main/client/src/App.js"
  click Components "https://github.com/srijan-petwal/mission-control/tree/main/client/src/components/"
  click Pages "https://github.com/srijan-petwal/mission-control/blob/main/client/src/pages/AppLayout.js"
  click Pages "https://github.com/srijan-petwal/mission-control/blob/main/client/src/pages/Launch.js"
  click Pages "https://github.com/srijan-petwal/mission-control/blob/main/client/src/pages/Upcoming.js"
  click Pages "https://github.com/srijan-petwal/mission-control/blob/main/client/src/pages/History.js"
  click Hooks "https://github.com/srijan-petwal/mission-control/blob/main/client/src/hooks/usePlanets.js"
  click Hooks "https://github.com/srijan-petwal/mission-control/blob/main/client/src/hooks/useLaunches.js"
  click Hooks "https://github.com/srijan-petwal/mission-control/blob/main/client/src/hooks/requests.js"
  click Config "https://github.com/srijan-petwal/mission-control/blob/main/client/package.json"
  click Config "https://github.com/srijan-petwal/mission-control/blob/main/client/public/index.html"
  click Config "https://github.com/srijan-petwal/mission-control/blob/main/client/public/manifest.json"
  click Config "https://github.com/srijan-petwal/mission-control/blob/main/client/public/robots.txt"
  click Config "https://github.com/srijan-petwal/mission-control/tree/main/client/public/sound/"
  click AppBootstrap "https://github.com/srijan-petwal/mission-control/blob/main/server/src/app.js"
  click ServerEntry "https://github.com/srijan-petwal/mission-control/blob/main/server/src/server.js"
  click PlanetsRouter "https://github.com/srijan-petwal/mission-control/blob/main/server/src/routes/planets/planets.router.js"
  click PlanetsCtrl "https://github.com/srijan-petwal/mission-control/blob/main/server/src/routes/planets/planets.controller.js"
  click LaunchesRouter "https://github.com/srijan-petwal/mission-control/blob/main/server/src/routes/launches/launches.router.js"
  click LaunchesCtrl "https://github.com/srijan-petwal/mission-control/blob/main/server/src/routes/launches/launches.controller.js"
  click PlanetsMongo "https://github.com/srijan-petwal/mission-control/blob/main/server/src/models/planets.mongo.js"
  click PlanetsModel "https://github.com/srijan-petwal/mission-control/blob/main/server/src/models/planets.model.js"
  click LaunchesMongo "https://github.com/srijan-petwal/mission-control/blob/main/server/src/models/launches.mongo.js"
  click LaunchesModel "https://github.com/srijan-petwal/mission-control/blob/main/server/src/models/launches.model.js"
  click CSV "https://github.com/srijan-petwal/mission-control/blob/main/server/data/kepler-data.csv"

  classDef frontend fill:#D0E8FF,stroke:#0366D6,stroke-width:2px
  classDef backend fill:#DFFFE0,stroke:#228B22,stroke-width:2px,stroke-dasharray: 5 5
  classDef db fill:#FFE5B4,stroke:#CC8400,stroke-width:2px
  classDef external fill:#F0F0F0,stroke:#666666,stroke-width:2px,stroke-dasharray: 2 2
```
