# tlokeshgit/greencart-microservices architecture

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

- Interactive diagram: https://gitdiagram.com/tlokeshgit/greencart-microservices
- Repository: https://github.com/tlokeshgit/greencart-microservices

## Overview

##### Project type and purpose
- This is a single‐service backend application (GreenCart Backend) built with Django and Django REST Framework.
- It provides RESTful APIs for an e-commerce platform: user/auth management, product/category management, shopping cart, orders, payments (Stripe), coupons, ratings, etc.

##### File structure analysis
- Top‐level:
- build.sh, render.yaml (deployment)
- django_backend/ (Python package)
- .env, .gitignore, README.md
- Inside django_backend:
- manage.py, asgi.py, wsgi.py, settings.py, requirements.txt
- shop/ Django app: models.py, serializers.py, views.py, urls.py, admin.py, tests.py
- templates/ (HTML for homepage, Swagger UI, password-reset flows)
- static/ (CSS/JS for admin and frontend)
- insert_dummy_data.sql
- root urls.py ties shop.urls and swagger/redoc routes

##### README insights
- Confirms Django + DRF stack
- Describes features, deployment on Render.com (Python service + PostgreSQL managed DB)
- Build & start commands (build.sh, gunicorn django_backend.wsgi)
- API docs served via Swagger and ReDoc endpoints

a. Main components
- Clients (Web browser, Mobile app)
- Render.com load balancer / HTTPS endpoint
- Gunicorn (WSGI) / ASGI server
- Django application (django_backend package)
– Core modules: Authentication, Shop app (products, orders, coupons, ratings)
– REST Framework layer (serializers, viewsets, routers)
– Static & template engine (serving admin UI, Swagger UI)
- PostgreSQL database (Render managed)
- External services: Stripe (payment processing)
- Optional: Redis or cache layer (if added later), email SMTP service for password reset
b. Relationships & data flow
1. Client → HTTPS → Render load balancer → Gunicorn/ASGI → Django URL router
2. Django routes to corresponding viewsets in shop app
3. Business logic executes: models read/write to PostgreSQL via Django ORM
4. Payment endpoints invoke Stripe API over HTTPS
5. Responses return back through the same path to client
6. Static assets and Swagger UI served either by Django staticfiles or CDN if configured
c. Architectural patterns & design principles
- Modular “apps” per domain (Django’s app structure)
- Layered architecture:
- Presentation (templates, Swagger UI)
- API layer (DRF viewsets/serializers)
- Business logic (models, services)
- Data layer (ORM → PostgreSQL)
- 12-factor app principles (env variables, build script, stateless server)
- Externalizing config (DJANGO_SETTINGS_MODULE, DATABASE_URL)
d. Key technologies
- Python 3.x, Django, Django REST Framework
- Gunicorn (WSGI), ASGI for async
- PostgreSQL
- Stripe SDK
- Render.com deployment (render.yaml)
- Swagger / ReDoc for API docs

##### Detailed breakdown
- Layer 1 (Edge): Client devices → HTTPS
- Layer 2 (Ingress): Render.com static route → build & deploy (build.sh, render.yaml)
- Layer 3 (Application):
- Gunicorn/ASGI server
- Django core (settings, URL dispatch)
- shop app modules (models, serializers, views)
- admin & Swagger UI templates/static
- Layer 4 (Persistence & integrations):
- PostgreSQL (data store)
- Stripe API (payment)
- SMTP/email (user notifications)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layer 1: Edge
    Client["Clients (Web Browser, Mobile App)"]:::client
    Client -->|"HTTPS Request"| RenderLB

    %% Layer 2: Ingress & Deployment
    subgraph "Render.com Infrastructure"
        direction TB
        RenderLB["Render.com Load Balancer"]:::cloud
        BuildDeploy["Build & Deploy"]:::deployment
    end
    RenderLB --> BuildDeploy
    BuildDeploy -->|"build.sh & render.yaml"| Migrate
    Migrate["manage.py migrate"]:::script
    Migrate --> Gunicorn

    %% Layer 3: Application Servers
    subgraph "Application Layer"
        direction TB
        Gunicorn["Gunicorn / ASGI Server"]:::server
        Gunicorn --> DjangoCore
        DjangoCore["Django Application\n(settings, URL router)"]:::app
        DjangoCore --> ShopApp
    end

    subgraph "Shop App Modules" 
        direction TB
        Models["Models"]:::logic
        Serializers["Serializers"]:::api
        Views["Views / ViewSets"]:::logic
        URLs["URL Routing"]:::api
        Admin["Admin Customization"]:::ui
        Tests["Tests Suite"]:::test
        Static["Static Assets"]:::static
        Templates["HTML Templates"]:::ui
        Models -->|"ORM"| DB
        Serializers --> Views
        Views -->|"DRF Routers"| URLs
    end
    ShopApp --> Models
    ShopApp --> Serializers
    ShopApp --> Views
    ShopApp --> URLs
    ShopApp --> Admin
    ShopApp --> Tests
    ShopApp --> Static
    ShopApp --> Templates

    %% Layer 4: Persistence & Integrations
    subgraph "Persistence & External Services"
        direction TB
        DB["PostgreSQL Database"]:::db
        Stripe["Stripe Payment API"]:::external
        SMTP["SMTP / Email Service"]:::external
    end
    Views -->|"Write/Read"| DB
    Views -->|"Invoke Payment"| Stripe
    Views -->|"Send Emails"| SMTP

    %% Click Events
    click Client "https://github.com/tlokeshgit/greencart-microservices/blob/main/.env"
    click RenderLB "https://github.com/tlokeshgit/greencart-microservices/blob/main/render.yaml"
    click BuildDeploy "https://github.com/tlokeshgit/greencart-microservices/blob/main/build.sh"
    click Migrate "https://github.com/tlokeshgit/greencart-microservices/blob/main/django_backend/manage.py"
    click Gunicorn "https://github.com/tlokeshgit/greencart-microservices/blob/main/django_backend/asgi.py"
    click Gunicorn "https://github.com/tlokeshgit/greencart-microservices/blob/main/django_backend/wsgi.py"
    click DjangoCore "https://github.com/tlokeshgit/greencart-microservices/blob/main/django_backend/settings.py"
    click DjangoCore "https://github.com/tlokeshgit/greencart-microservices/blob/main/django_backend/requirements.txt"
    click ShopApp "https://github.com/tlokeshgit/greencart-microservices/tree/main/django_backend/shop/"
    click Models "https://github.com/tlokeshgit/greencart-microservices/blob/main/django_backend/shop/models.py"
    click Serializers "https://github.com/tlokeshgit/greencart-microservices/blob/main/django_backend/shop/serializers.py"
    click Views "https://github.com/tlokeshgit/greencart-microservices/blob/main/django_backend/shop/views.py"
    click URLs "https://github.com/tlokeshgit/greencart-microservices/blob/main/django_backend/shop/urls.py"
    click Admin "https://github.com/tlokeshgit/greencart-microservices/blob/main/django_backend/shop/admin.py"
    click Tests "https://github.com/tlokeshgit/greencart-microservices/blob/main/django_backend/shop/tests.py"
    click Static "https://github.com/tlokeshgit/greencart-microservices/tree/main/django_backend/shop/static/"
    click Templates "https://github.com/tlokeshgit/greencart-microservices/tree/main/django_backend/shop/templates/"
    click DB "https://github.com/tlokeshgit/greencart-microservices/blob/main/README.md"
    click Stripe "https://github.com/tlokeshgit/greencart-microservices/blob/main/README.md"
    click SMTP "https://github.com/tlokeshgit/greencart-microservices/blob/main/README.md"
    click ShopApp "https://github.com/tlokeshgit/greencart-microservices/blob/main/django_backend/insert_dummy_data.sql"

    %% Styles
    classDef client fill:#A3C1DA,stroke:#000,stroke-width:1px
    classDef cloud fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef deployment fill:#F9E79F,stroke:#000,stroke-width:1px
    classDef script fill:#F5CBA7,stroke:#000,stroke-width:1px
    classDef server fill:#AED6F1,stroke:#000,stroke-width:1px
    classDef app fill:#AED6F1,stroke:#000,stroke-width:1px
    classDef logic fill:#ABEBC6,stroke:#000,stroke-width:1px
    classDef api fill:#D2B4DE,stroke:#000,stroke-width:1px
    classDef ui fill:#FADBD8,stroke:#000,stroke-width:1px
    classDef test fill:#E8DAEF,stroke:#000,stroke-width:1px
    classDef static fill:#D5F5E3,stroke:#000,stroke-width:1px
    classDef db fill:#F4D03F,stroke:#000,stroke-width:1px
    classDef external fill:#F1948A,stroke:#000,stroke-width:1px
```
