# jossuejativa/proyectocapstone architecture

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

- Interactive diagram: https://gitdiagram.com/jossuejativa/proyectocapstone
- Repository: https://github.com/jossuejativa/proyectocapstone

## Overview

##### Project Type and Purpose
- This project is a full-stack web application designed to manage users, dishes, tables, allergens, ingredients, and orders.
- The backend is built with Django and Django REST Framework, exposing a RESTful API, while the frontend (in the “frontend” folder) is a client-side app built with TypeScript and Vite that communicates with the backend.
- A dedicated WebSocket service exists (in the “websocket” directory) that uses socket.io for real-time communication.
- Docker and Docker Compose are used to manage the database (PostgreSQL) and other services.

##### File Structure
- The “admincontroller” directory contains the Django project and applications (e.g., authAPI, dishesAPI). It includes typical Django project files such as settings, urls, and WSGI/ASGI, as well as migrations, tests, and static files.
- The “frontend” directory holds the client application code, assets, components, and pages. It is set up with TypeScript and Vite, and it uses modern React patterns (or similar).
- The “websocket” directory includes server-side WebSocket implementation with a clear structure – configurations, database initialization, models, and socket logic implemented in TypeScript.
- Configuration files such as Dockerfiles (for admincontroller and websocket) and docker-compose.yml show how various services are containerized.

a. Main Components to Include:
- Client (Frontend): Displays pages, handles client-side routing and interacts with the backend API. Differentiate between admin routes and web routes.
- Backend API (Admin Controller): A Django app exposing RESTful endpoints to manage users, dishes, tables, allergens, ingredients, and orders.
- Breakdown the Django portion into its core apps (authAPI, dishesAPI, etc.) if needed.
- WebSocket Service: A separate service running on Node/TypeScript with socket.io to handle real-time communication (order updates, notifications, etc.).
- Database: The PostgreSQL instance running via Docker Compose.
- Docker & Deployment Components: Containerization setup that integrates the backend, WebSocket service, and database.

b. Relationships and Interactions:
- The Frontend interacts with the Backend API via HTTP requests (secure endpoints using JWT tokens) and with the WebSocket server for live updates (using socket.io-client).
- The Backend communicates with the PostgreSQL database for persistent storage.
- The WebSocket service may also interact with the database if needed or with the backend service indirectly for order events.
- Docker Compose orchestrates the interconnections between containers (database, backend, WebSocket, potentially frontend for local development).

c. Architectural Patterns and Design Principles:
- Separation of Concerns: Clearly separate the frontend, backend API, and WebSocket service. Use RESTful API design principles on the backend.
- Microservices/Modularization: Even though the backend is monolithic (Django project), the segmentation into separate apps (authAPI, dishesAPI, etc.) helps modularize the business logic.
- Containerization: Emphasize use of Docker for replication and isolated environments.
- Client-Server Communication: Illustrate both stateless HTTP requests and stateful WebSocket communication.

d. Relevant Technologies:
- Django, Django REST Framework, and Python on the backend.
- PostgreSQL as the relational database.
- Docker and Docker Compose for orchestration.
- TypeScript, Vite, and React (or similar framework from the “frontend” folder) for the client.
- Socket.io for WebSockets in the “websocket” service.

##### Instructing the Principal Software Engineer
- Backend with the Database, and outline relationships (e.g., “saves user data”, “fetches orders”).
- Optionally, subdivide the backend into its constituent apps (authAPI, dishesAPI) to indicate modular boundaries.
- Ports and host details (e.g., API on localhost:8000, WebSocket on localhost:3000, PostgreSQL on localhost:5432), as provided in the README.
- Use of JWT for authentication in the REST API calls and the support for token refresh workflows.

##### Final Recommendations
- Detail the major components and how they interact; don’t leave out deployment aspects like Docker and the orchestration provided by docker-compose.
- Be as detailed as needed, breaking down services into as many components as makes sense for clear comprehension.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        FE["Frontend (React, Vite, TypeScript)"]:::frontend
    end

    subgraph "API Layer"
        BE["Backend API (Django)"]:::backend
        subgraph "Django Apps"
            AUTH["Auth API"]:::backend
            DISHES["Dishes API"]:::backend
        end
        BE -->|"contains"| AUTH
        BE -->|"contains"| DISHES
    end

    subgraph "Real-Time Service"
        WS["WebSocket Service (socket.io, TypeScript)"]:::websocket
    end

    subgraph "Database Layer"
        DB(("PostgreSQL")):::database
    end

    subgraph "Containerization"
        DC["Docker Compose"]:::docker
        DD["Django Dockerfile"]:::docker
        WD["WebSocket Docker Config"]:::docker
    end

    FE -->|"HTTP(JWT)"| BE
    FE -->|"socket.io"| WS
    BE -->|"CRUD"| DB
    WS -->|"optional_DB"| DB

    DC --> BE
    DC --> WS
    DC --> DB

    click BE "https://github.com/jossuejativa/proyectocapstone/tree/main/admincontroller/admincontroller/"
    click AUTH "https://github.com/jossuejativa/proyectocapstone/tree/main/admincontroller/authAPI/"
    click DISHES "https://github.com/jossuejativa/proyectocapstone/tree/main/admincontroller/dishesAPI/"
    click FE "https://github.com/jossuejativa/proyectocapstone/tree/main/frontend/"
    click WS "https://github.com/jossuejativa/proyectocapstone/tree/main/websocket/"
    click DC "https://github.com/jossuejativa/proyectocapstone/blob/main/docker-compose.yml"
    click DD "https://github.com/jossuejativa/proyectocapstone/tree/main/admincontroller/Dockerfile"
    click WD "https://github.com/jossuejativa/proyectocapstone/blob/main/websocket/.dockerignore"

    classDef frontend fill:#e0f7fa,stroke:#006064,stroke-width:2px;
    classDef backend fill:#ffe0b2,stroke:#e65100,stroke-width:2px;
    classDef websocket fill:#dcedc8,stroke:#33691e,stroke-width:2px;
    classDef database fill:#fff9c4,stroke:#f9a825,stroke-width:2px;
    classDef docker fill:#f8bbd0,stroke:#880e4f,stroke-width:2px;
```
