# ghostblaster08/smile_horizon architecture

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

- Interactive diagram: https://gitdiagram.com/ghostblaster08/smile_horizon
- Repository: https://github.com/ghostblaster08/smile_horizon

## Overview

##### Main System Components
a. Backend (Django):
- The core of the application is built using Django 4.2+.
- It includes several Django apps (modules) such as:
- Appointment: Manages appointments and treatment records.
- Patient: Handles patient registration, medical history, and document management.
- Prescription: Manages medicines and prescription details.
- User: Manages user profiles (extending Django’s AbstractUser for roles like doctors and staff).
- Core: Provides shared functionality such as the dashboard and common utilities.
- The project’s main directory (Smile_Horizon/Smile_Horizon) holds the global settings, main URL router, and server configuration.
- Use of Django’s MTV architecture (Models, Templates, and Views) is evident, with models defining the data, views containing the business logic, and templates handling presentation in the backend.
- Built-in authentication system as part of the backend.

b. Frontend:
- Two frontend approaches are in the repository:
- Traditional Django Templates: Found under the “templates” directory, using HTML, CSS, JavaScript, and Bootstrap 5.
- React-based Frontend: Located in the “react_smilehorizon” directory. This part contains a complete React project (with its own package.json, Tailwind CSS configuration, and components) indicating an SPA interface which likely interacts with backend endpoints (via Django REST Framework serializers present in several apps).

c. Database:
- The application uses SQLite by default (as seen in the db.sqlite3 file), with a note in the README that it’s configurable for PostgreSQL, MySQL, or other production-grade databases.

d. Additional Concerns:
- Static and Media Files: Managed by Django (static assets and uploaded files).
- Migration files in each app ensure that the database schema is synchronized with the defined models.
- Integration Between Frontend and Backend: Likely REST API endpoints exist (evidenced by serializers in Appointment, Patient, and Prescription apps) that are consumed by the React SPA.

##### Relationships & Data Flow
- The client (web browser) interacts with the system using both the traditional Django-rendered pages and the React SPA.
- For the React SPA:
- The frontend (React application) sends HTTP requests (possibly AJAX/Fetch calls) to REST API endpoints served by the Django backend.
- Responses from Django (via views/serializers) are used to update the UI dynamically.
- In the backend:
- Views call business logic, interact with models, and use serializers to produce JSON data for the frontend when needed.
- Django’s URL routing (both in the main project and within individual apps) manages the endpoints.
- The database is accessed via Django’s ORM, storing the core data (patients, appointments, prescriptions, user accounts, etc.)

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clear division between individual Django apps (each handling a specific business domain) and the separation between the presentation layer (templates/React) and the business logic.
- REST API Pattern: Evidenced by serializers in multiple apps, suggesting that the backend is built to serve data to the React frontend.
- MVC/MVT Architecture: The project follows Django’s conventional patterns, with a strict separation between data models, views (business logic), and templates.
- Frontend-Backend Decoupling: With the presence of a dedicated React project, the system design should show loosely-coupled interactions via clearly defined API contracts.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client / Browser"
        CT["Django Templates Frontend"]:::frontend
        CR["React SPA Frontend"]:::frontend
    end

    subgraph "Backend - Django"
        DC["Main Config (settings, urls, etc.)"]:::backend
        AA["Appointment App"]:::backend
        PP["Patient App"]:::backend
        PR["Prescription App"]:::backend
        UA["User App"]:::backend
        CA["Core App (Dashboard & Shared)"]:::backend
        AU["Authentication"]:::backend
    end

    DB["Database (SQLite)"]:::database

    %% Client to Backend
    CT -->|"HTTP_Request"| DC
    CR -->|"API_Request"| DC

    %% Routing within Backend
    DC -->|"Routes"| AA
    DC -->|"Routes"| PP
    DC -->|"Routes"| PR
    DC -->|"Routes"| UA
    DC -->|"Routes"| CA
    DC -->|"Auth"| AU

    %% Backend to Database
    AA -->|"CRUD"| DB
    PP -->|"CRUD"| DB
    PR -->|"CRUD"| DB
    UA -->|"CRUD"| DB
    CA -->|"CRUD"| DB
    AU -->|"Query"| DB

    %% Click Events
    click DC "https://github.com/ghostblaster08/smile_horizon/tree/main/Smile_Horizon/Smile_Horizon"
    click AA "https://github.com/ghostblaster08/smile_horizon/tree/main/Smile_Horizon/Appointment"
    click PP "https://github.com/ghostblaster08/smile_horizon/tree/main/Smile_Horizon/Patient"
    click PR "https://github.com/ghostblaster08/smile_horizon/tree/main/Smile_Horizon/Prescription"
    click UA "https://github.com/ghostblaster08/smile_horizon/tree/main/Smile_Horizon/User"
    click CA "https://github.com/ghostblaster08/smile_horizon/tree/main/Smile_Horizon/core"
    click CT "https://github.com/ghostblaster08/smile_horizon/tree/main/Smile_Horizon/templates"
    click CR "https://github.com/ghostblaster08/smile_horizon/tree/main/react_smilehorizon"
    click DB "https://github.com/ghostblaster08/smile_horizon/blob/main/Smile_Horizon/db.sqlite3"

    %% Styles
    classDef frontend fill:#a2d2ff,stroke:#000,stroke-width:2px;
    classDef backend fill:#ffecd1,stroke:#000,stroke-width:2px;
    classDef database fill:#caffbf,stroke:#000,stroke-width:2px;
```
