# 404dontsleep/simplebase architecture

> Architecture diagram of the GitHub repository 404dontsleep/simplebase, 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/404dontsleep/simplebase
- Repository: https://github.com/404dontsleep/simplebase

## Overview

Based on our analysis of the provided file tree and README, the project is a full-stack web application with a clear separation between a backend service (built in TypeScript, likely utilizing technologies such as Express or a similar Node.js framework) and a frontend client (built with React via Vite). The application is structured to serve administrative functions at an “admin.domain.com” endpoint, where it allows configuration of pages and centralized management of permissions and user accounts.

##### Main Components
- Backend Service:
- Contains configuration, routers for authentication and administration, middleware for authentication, permissions, and verification.
- Manages data operations using MongoDB (as indicated by the "connectMongo.ts" file) and utility functions such as cryptography, email sending, and token management.
- Organized in a modular way with separate directories for models, routers, middlewares, and utilities. This separation indicates an MVC or similar pattern.
- Frontend Application:
- Built with React (using TypeScript and Vite) and organized into pages, components (for layouts, providers, configuration, and elements), and stores that handle state management.
- Contains specific pages for admin configurations, authentication, and general navigation, reflecting the multi-page structure tailored to both admin and user workflows.
- Database:
- The backend connects to a MongoDB database to store user, permission, and router data. Represent this as a separate data storage component.
- External Services:
- Email service used for functionalities like password reset and verification (as referenced in "sendMail.ts").
- Docker is also used (note the Dockerfile and docker-compose.yml) to containerize and deploy the application.

##### Relationships and Interactions
- Data Flow:
- The Backend processes the request, interacts with the MongoDB database, and sometimes communicates with external services (e.g., email server).
- Authentication and Authorization:
- How the Frontend handles login, registration, and configuration requests, while the Backend uses middleware (auth.middleware.ts, permission.middleware.ts, verify.middleware.ts) to secure endpoints.
- Administrative Configuration:

##### Architectural Patterns and Design Principles
- Separation of Concerns: The clear division between frontend and backend simplifies development and maintenance.
- Modular Pattern: Both repositories (Frontend and Backend) use a modular directory structure to separate concerns (routers, models, middlewares, utilities, components, pages, stores).
- Containerization: The Dockerfile and docker-compose ensure that the system is deployable in containerized environments.
- API-Driven Design: The backend exposes a set of HTTP APIs (including a dedicated set for admin and authentication), and the frontend consumes these APIs.
- State Management: Use of stores on the frontend (for auth, permission, theme, and user) that indicate a centralized state management design (perhaps inspired by contexts or libraries like Redux).

##### Technologies and Frameworks
- Backend: TypeScript, Node.js, Express-like routing (or a custom router solution), MongoDB (for database connectivity), and Docker.
- Frontend: React (with TypeScript), Vite as the build tool, and libraries for managing state (such as custom stores or context providers).
- Communication: REST APIs for the interaction between the front and backend components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FEApp["React Client"]:::frontend
        FEPages["Pages"]:::frontend
        FEComponents["Components"]:::frontend
        FEStores["Stores"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BECore["Core Application Logic"]:::backend
        BEAuth["Authentication Routers"]:::backend
        BEAdmin["Administrative Routers (admin.domain.com)"]:::backend
        BEMW["Middlewares"]:::backend
        BEUtils["Utility Modules"]:::backend
        BEDB["MongoDB Connector"]:::backend
    end

    %% External Components
    DB["MongoDB Database"]:::database
    EmailService["Email Service"]:::external

    %% Containerization / Deployment
    Docker["Containerization (Docker)"]:::container

    %% Connections between Frontend and Backend
    FEApp -->|"HTTP_API"| BECore
    FEPages -->|"HTTP_API"| BECore
    FEComponents -->|"UI Interaction"| FEApp
    FEStores -->|"State Management"| FEApp

    %% Internal Backend Composition
    BECore --> BEAuth
    BECore --> BEAdmin
    BECore --> BEMW
    BECore --> BEUtils
    BECore --> BEDB

    BEAuth -->|"secured_by"| BEMW
    BEAdmin -->|"secured_by"| BEMW

    %% Backend to Database and External Services
    BEDB -->|"queries"| DB
    BEUtils -->|"send_email"| EmailService

    %% Containerization Deployment
    Docker -->|"deploys"| FEApp
    Docker -->|"deploys"| BECore

    %% Click Events for Frontend Components
    click FEApp "https://github.com/404dontsleep/simplebase/tree/main/FrontEnd/src"
    click FEPages "https://github.com/404dontsleep/simplebase/tree/main/FrontEnd/src/pages"
    click FEComponents "https://github.com/404dontsleep/simplebase/tree/main/FrontEnd/src/components"
    click FEStores "https://github.com/404dontsleep/simplebase/tree/main/FrontEnd/src/stores"

    %% Click Events for Backend Components
    click BECore "https://github.com/404dontsleep/simplebase/tree/main/Backend/src/me"
    click BEAuth "https://github.com/404dontsleep/simplebase/tree/main/Backend/src/me/routers/auth"
    click BEAdmin "https://github.com/404dontsleep/simplebase/tree/main/Backend/src/me/routers/admin"
    click BEMW "https://github.com/404dontsleep/simplebase/tree/main/Backend/src/me/middlewares"
    click BEDB "https://github.com/404dontsleep/simplebase/blob/main/Backend/src/database/connectMongo.ts"
    click BEUtils "https://github.com/404dontsleep/simplebase/tree/main/Backend/src/me/utils"

    %% Click Event for Email Service
    click EmailService "https://github.com/404dontsleep/simplebase/blob/main/Backend/src/me/utils/sendMail.ts"

    %% Click Event for Containerization
    click Docker "https://github.com/404dontsleep/simplebase/blob/main/Backend/Dockerfile and docker-compose.yml"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef database fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef container fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
