# hazed2004/secret-locker architecture

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

- Interactive diagram: https://gitdiagram.com/hazed2004/secret-locker
- Repository: https://github.com/hazed2004/secret-locker

## Overview

##### Backend Components
- FastAPI Server: Represented by backend/main.py, this is the entry point for the server.
- Authentication Module: Under backend/auth, this includes functionality for JWT authentication, login and registration, user schema definitions, and stored constants/secret management.
- Database Module: In backend/database, which manages the database connection, models, and any related constants.
- Middleware: Found in backend/middleware, which likely handles configuration, request/response processing (such as authentication hooks, logging, etc.).
- Configuration: backend/config.py serves as the configuration file which likely defines environment-specific settings, including database connections and other service parameters.

##### Frontend Components
- Static HTML/CSS/JS: The frontend directory contains general pages (index.html, home, auth pages for login and register) paired with JavaScript scripts that handle client-side logic.
- Assets: The images directory holds screenshots or UI assets.

##### External Dependencies
- PostgreSQL Database: This is external but central to the persistence layer. The backend’s database module interacts with it for CRUD operations.
- Swagger UI: Available through /docs, showing the API documentation provided by FastAPI.
- Webserver for the Frontend: Although the frontend is a static site, it is served via a different webserver (examples include Apache2 or Python HTTP server).

##### Relationships and Data Flow
- The Frontend sends HTTP requests (possibly via AJAX/fetch) to the FastAPI backend endpoints for various operations (e.g., authentication, CRUD actions).
- The Backend processes these requests, using middleware (for additional control such as authentication checks and logging) and then routes to the authentication or database modules as needed.
- The Authentication Module verifies user credentials and issues/validates JWT tokens.
- The Database Module interacts with the PostgreSQL database for persistent data storage using the provided models and connection utilities.
- Configuration is shared between server startup and connectivity to external services (e.g., database host, port configurations).

##### Architectural Patterns/Design Principles
- Separation of Concerns: Clear separation between authentication, database, middleware, and configuration.
- Modular Design: Each directory (auth, database, middleware) encapsulates a specific aspect of the backend.
- API-First: The RESTful API endpoints provided by FastAPI allow clients (the frontend) to interact with the backend, with JWT for security.
- Stateless Backend: JWT based authentication encourages statelessness between requests.

- How the frontend separates from the backend. Show clearly that the frontend is served by a static file server and interacts through HTTP APIs.
- Role of JWT authentication in the auth module, ensuring the secure flow between login/register functionalities and the protected endpoints.
- To show data flow from client-side requests (via AJAX or form submit) to the FastAPI endpoints, and then onward to and from the PostgreSQL database.
- Configuration and middleware as integral parts of the API handling process.

## Diagram (Mermaid)

```mermaid
flowchart TD 
    subgraph "Frontend"
        FS["Static Pages"]:::frontend
        FScr["Frontend Scripts"]:::frontend
        FA["Assets (Images)"]:::frontend
    end

    subgraph "Backend"
        fastapi["FastAPI Server"]:::backend
        auth["Authentication Service (JWT,Login,Register)"]:::backend
        db_module["Database Module"]:::backend
        middleware["Middleware"]:::backend
        config["Configuration"]:::backend
        swagger["Swagger UI (/docs)"]:::backend
    end

    postgres["PostgreSQL Database"]:::external

    %% Data Flow
    FS -->|"HTTP_Request"| fastapi
    fastapi -->|"JWT_Check"| auth
    fastapi -->|"Process_Request"| middleware
    fastapi -->|"DB_Query"| db_module
    fastapi -->|"API_Docs"| swagger
    fastapi -->|"Config_Setting"| config
    db_module -->|"CRUD"| postgres

    %% Frontend Internal Flow
    FS -->|"loads_script"| FScr
    FS -->|"renders_assets"| FA

    %% Click Events
    click fastapi "https://github.com/hazed2004/secret-locker/blob/main/backend/main.py"
    click auth "https://github.com/hazed2004/secret-locker/tree/main/backend/auth"
    click db_module "https://github.com/hazed2004/secret-locker/tree/main/backend/database"
    click middleware "https://github.com/hazed2004/secret-locker/tree/main/backend/middleware"
    click config "https://github.com/hazed2004/secret-locker/blob/main/backend/config.py"
    click FS "https://github.com/hazed2004/secret-locker/tree/main/frontend"
    click FScr "https://github.com/hazed2004/secret-locker/tree/main/frontend/scripts"
    click FA "https://github.com/hazed2004/secret-locker/tree/main/images"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#333,stroke-width:2px;
```
