# rainycitycoder/sby-backend architecture

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

- Interactive diagram: https://gitdiagram.com/rainycitycoder/sby-backend
- Repository: https://github.com/rainycitycoder/sby-backend

## Overview

##### Project type and purpose
- This is a full-stack web application (“Scientist Birthdays”) with a React.js front-end (deployed to AWS S3) and a Django REST back-end (deployed on AWS EC2). The front-end reads two API endpoints (`/bio/` and `/compsci/`) and displays data from a local SQLite3 database.

##### File structure
- Top-level directories and files:
- pythonbackend/ – Django project (settings.py, asgi.py, wsgi.py, urls.py)
- api/ – Django “app” housing models, serializers, views, URLs, tests, and migrations
- gunicorn/ – Service unit file for Gunicorn on the EC2 host
- nginx/ – nginx.conf for reverse-proxy configuration
- scripts/ – provisioning & startup scripts (install dependencies, configure nginx, start Gunicorn, after_install)
- manage.py, requirements.txt, db.sqlite3 – Django entry point, Python dependencies, database
- These indicate a classic monolithic Django API behind Gunicorn + Nginx, plus automated deployment scripts.

##### README for additional insights
- Confirms React front-end (hosted separately), minimal routing, automatic API calls
- Django REST endpoints for two resource paths
- SQLite3 used for persistence
- Deployment to AWS S3 (front end) and AWS EC2 (back end)

##### Main components
a. Front-End Layer
- AWS S3 Bucket (Static Website Hosting)
- Browser (React SPA)
b. Network/Edge Layer (optional)
- Amazon Route 53 / DNS
- (Optionally) Amazon CloudFront CDN in front of the S3 bucket
c. Back-End Layer on AWS EC2
- Nginx (reverse proxy, static file serving if any)
- Gunicorn (WSGI server managing Django processes)
- Django REST Framework application (“pythonbackend” + “api” modules)
- SQLite3 Database (db.sqlite3 file)
d. DevOps/Automation
- Provisioning & startup scripts (in “scripts/”)
- Systemd service for Gunicorn (“gunicorn/gunicorn.service”)
- nginx.conf (in “nginx/”)

##### Relationships and interactions
- Browser loads static assets from S3 (HTTP GET).
- React components in the browser issue fetch() calls to API endpoints (e.g., `https://api.example.com/bio/`).
- Requests route via DNS → EC2 public IP → Nginx listens on port 80/443 → proxies to Gunicorn on a local port.
- Gunicorn forwards requests to Django’s ASGI/WSGI endpoint.
- Django ORM reads/writes to the local SQLite3 file.
- Responses flow back up from Django → Gunicorn → Nginx → Browser.

##### Architectural patterns & design principles
- Separation of concerns: Static SPA vs. dynamic API
- Reverse-proxy pattern: Nginx decoupling TLS, caching, static vs dynamic routing
- Process manager: Gunicorn for concurrency/worker management
- Infrastructure as code: Shell scripts for repeatable deployments
- Single instance monolith: all Django code and SQLite in one EC2 instance

##### Essential architectural elements
- Don’t omit the reverse-proxy layer (Nginx) nor the WSGI server (Gunicorn).
- Automation and config artifacts (scripts, systemd unit, nginx.conf) to reflect deploy operations.
- Separation of static vs dynamic content, showing AWS S3 as a separate component.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client/Edge
    subgraph "Client / Edge"
        Browser["Browser (React SPA)"]:::app
        Route53["Amazon Route53 DNS"]:::service
        CloudFront["Amazon CloudFront CDN"]:::service
        S3["AWS S3 (Static Website Hosting)"]:::service
    end

    %% Server
    subgraph "Server (AWS EC2)" 
        direction TB

        subgraph "Compute Stack"
            direction TB
            Nginx["Nginx<br>(nginx/nginx.conf)"]:::compute
            Gunicorn["Gunicorn<br>(gunicorn/gunicorn.service)"]:::compute
            subgraph "Django REST API"
                direction TB
                PythonBackend["pythonbackend/"]:::app
                Settings["settings.py"]:::config
                ASGI["asgi.py"]:::config
                WSGI["wsgi.py"]:::config
                URLs["urls.py"]:::config

                subgraph "api App"
                    direction TB
                    APIApp["api/"]:::app
                    Models["models.py"]:::config
                    Serializers["serializers.py"]:::config
                    Views["views.py"]:::config
                    APIURLs["urls.py"]:::config
                    Tests["tests.py"]:::config
                    Migrations["migrations/"]:::config
                end
            end
            SQLite["SQLite3 Database<br>(db.sqlite3)"]:::db
        end

        subgraph "DevOps & Config"
            direction TB
            Scripts["scripts/"]:::config
            OSDeps["instance_os_dependencies.sh"]:::config
            PyDeps["python_dependencies.sh"]:::config
            NginxSetup["nginx.sh"]:::config
            GunicornScript["gunicorn.sh"]:::config
            StartApp["start_app.sh"]:::config
            AfterInstall["after_install.sh"]:::config
            Systemd["gunicorn.service"]:::config
            NginxConf["nginx.conf"]:::config
            UserData["UserData.sh"]:::config
            ManagePy["manage.py"]:::config
            Requirements["requirements.txt"]:::config
            README["README.md"]:::config
            License["LICENSE"]:::config
        end
    end

    %% Connections
    Browser -->|"GET static assets"| S3
    Route53 -->|DNS lookup| S3
    Route53 -->|DNS lookup| Nginx
    Browser -->|"REST API calls"| Nginx
    S3 -->|serves assets| Browser

    Nginx -->|"proxy to"| Gunicorn
    Gunicorn -->|"WSGI to"| PythonBackend
    PythonBackend -->|"calls api app"| APIApp
    APIApp -->|"ORM reads/writes"| SQLite
    SQLite -->|data storage| APIApp
    APIApp -->|responses| Gunicorn
    Gunicorn -->|responses| Nginx
    Nginx -->|responses| Browser

    Scripts -->|provisions EC2| Nginx
    UserData -->|bootstraps EC2| Scripts

    %% Click Events
    click PythonBackend "https://github.com/rainycitycoder/sby-backend/tree/main/pythonbackend/"
    click Settings "https://github.com/rainycitycoder/sby-backend/blob/main/pythonbackend/settings.py"
    click ASGI "https://github.com/rainycitycoder/sby-backend/blob/main/pythonbackend/asgi.py"
    click WSGI "https://github.com/rainycitycoder/sby-backend/blob/main/pythonbackend/wsgi.py"
    click URLs "https://github.com/rainycitycoder/sby-backend/blob/main/pythonbackend/urls.py"
    click APIApp "https://github.com/rainycitycoder/sby-backend/tree/main/api/"
    click Models "https://github.com/rainycitycoder/sby-backend/blob/main/api/models.py"
    click Serializers "https://github.com/rainycitycoder/sby-backend/blob/main/api/serializers.py"
    click Views "https://github.com/rainycitycoder/sby-backend/blob/main/api/views.py"
    click APIURLs "https://github.com/rainycitycoder/sby-backend/blob/main/api/urls.py"
    click Tests "https://github.com/rainycitycoder/sby-backend/blob/main/api/tests.py"
    click Migrations "https://github.com/rainycitycoder/sby-backend/tree/main/api/migrations/"
    click SQLite "https://github.com/rainycitycoder/sby-backend/blob/main/db.sqlite3"
    click Systemd "https://github.com/rainycitycoder/sby-backend/blob/main/gunicorn/gunicorn.service"
    click NginxConf "https://github.com/rainycitycoder/sby-backend/blob/main/nginx/nginx.conf"
    click Scripts "https://github.com/rainycitycoder/sby-backend/tree/main/scripts/"
    click OSDeps "https://github.com/rainycitycoder/sby-backend/blob/main/scripts/instance_os_dependencies.sh"
    click PyDeps "https://github.com/rainycitycoder/sby-backend/blob/main/scripts/python_dependencies.sh"
    click NginxSetup "https://github.com/rainycitycoder/sby-backend/blob/main/scripts/nginx.sh"
    click GunicornScript "https://github.com/rainycitycoder/sby-backend/blob/main/scripts/gunicorn.sh"
    click StartApp "https://github.com/rainycitycoder/sby-backend/blob/main/scripts/start_app.sh"
    click AfterInstall "https://github.com/rainycitycoder/sby-backend/blob/main/scripts/after_install.sh"
    click UserData "https://github.com/rainycitycoder/sby-backend/blob/main/UserData.sh"
    click ManagePy "https://github.com/rainycitycoder/sby-backend/blob/main/manage.py"
    click Requirements "https://github.com/rainycitycoder/sby-backend/blob/main/requirements.txt"
    click README "https://github.com/rainycitycoder/sby-backend/blob/main/README.md"
    click License "https://github.com/rainycitycoder/sby-backend/tree/main/LICENSE"

    %% Styles
    classDef service fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef compute fill:#98FB98,stroke:#000,stroke-width:1px
    classDef app fill:#FFFACD,stroke:#000,stroke-width:1px
    classDef db fill:#FFD700,stroke:#000,stroke-width:1px
    classDef config fill:#F0E68C,stroke:#000,stroke-width:1px
```
