# kimjeffsj/syn-backend architecture

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

- Interactive diagram: https://gitdiagram.com/kimjeffsj/syn-backend
- Repository: https://github.com/kimjeffsj/syn-backend

## Overview

##### Project Type & Purpose
- SYN is a full-stack employee scheduling and management system. The backend is built with FastAPI (Python) and the frontend uses React (with Vite, TypeScript, Redux Toolkit, TailwindCSS, and WebSockets).

##### Analyzing the File Structure
- Notice the clear modular design in the backend under the “app” directory:
- "app/core" contains configuration, database setup, events, security – these form the foundation of the backend system.
- "app/features" is divided into feature-specific subdirectories (admin_dashboard, auth, announcements, employee_dashboard, employee_management, leave, notifications, schedule, shift_trade). These indicate that the backend is organized by domain features.
- "app/models" houses ORM models that interact with the PostgreSQL database.
- The presence of “alembic” for database migrations provides an important linkage to the persistent data layer.
- The tests directory also confirms the separation of concerns and the importance of isolated components that you may wish to annotate with testing for reliability.

##### Key Architectural Components and Interactions
a. Client-Side Frontend:
- React-based frontend application as one major component. Indicate that it communicates with the backend via REST API calls and WebSockets (for real-time notifications).
- That the frontend is hosted on Vercel.

b. API Backend:
- Inside, subdivide this component into “Core” (configuration, database, event handling, security) and “Features” (each feature module like admin_dashboard, auth, employee_dashboard, etc.).
- Each feature contains its own routers, schemas, and service logic. Illustrate these as separate modules within the FastAPI backend.

c. Database & Migrations:
- Elements like “Alembic migrations” that indicate how schema evolution is handled.

d. Caching & Real-time Communication:
- A Redis cache component that is used for caching and potentially for handling real-time features.

e. External Services & Authentication:
- Additional external services or libraries in use (e.g., JWT for authentication, security modules) as part of the authentication and security layer.

##### Architectural Patterns & Design Principles
- Modular design: Each feature facet is independently organized. Make sure to visually separate or group these domain components.
- Layered architecture: The separation between controllers (routers), business logic (services), and data models is clear – each should be represented.
- Event-driven style: In features such as “notifications”, include an “Events Bus” component that shows how events are triggered (from various features) and handled by the notifications and websocket modules.

- Each component should have a clear label. For example, “Admin Dashboard Module”, “Authentication Service”, “Employee Management Service”, etc.
- Data flow from the frontend to the backend and vice versa.
- Dependencies such as service calls from the API layer to the database.
- Event propagation from the business logic to the notifications subsystem.
- Rectangles for services or modules,
- That the fundamental architectural layers and all major feature modules are captured as clearly as possible.

## Diagram (Mermaid)

```mermaid
flowchart TD
    FE["React Client (Vercel)"]:::frontend
    BE["FastAPI Application"]:::backend

    %% Core Components subgraph
    subgraph "Core Components"
        C["Core & Infrastructure"]:::core
        E["Event Bus"]:::core
    end

    %% Feature Modules subgraph
    subgraph "Feature Modules"
        F1["Admin Dashboard Module"]:::module
        F2["Authentication Service"]:::module
        F3["Announcements Module"]:::module
        F4["Employee Dashboard Module"]:::module
        F5["Employee Management Service"]:::module
        F6["Leave Request Module"]:::module
        F7["Notifications Module & WebSocket Manager"]:::module
        F8["Schedule Module"]:::module
        F9["Shift Trade Module"]:::module
    end

    DBM["Database Models"]:::db
    DM["Database Migrations"]:::db
    DB["PostgreSQL Database"]:::db
    RC["Redis Cache"]:::external

    %% Connections between layers
    FE -->|"REST_API/WebSocket"| BE
    BE -->|"UsesCache&PubSub"| RC
    BE -->|"ORM_Operations"| DBM
    DBM -->|"Data_Storage"| DB
    C -->|"Handles_Migrations"| DM
    F7 -->|"Notifies"| E
    E -->|"Push_Notifications"| FE

    %% Represent inclusion of core and feature components in the API backend
    BE --> C
    BE --> F1

    %% Click Events
    click BE "https://github.com/kimjeffsj/syn-backend/tree/main/app"
    click C "https://github.com/kimjeffsj/syn-backend/tree/main/app/core"
    click F1 "https://github.com/kimjeffsj/syn-backend/tree/main/app/features/admin_dashboard"
    click F2 "https://github.com/kimjeffsj/syn-backend/tree/main/app/features/auth"
    click F3 "https://github.com/kimjeffsj/syn-backend/tree/main/app/features/announcements"
    click F4 "https://github.com/kimjeffsj/syn-backend/tree/main/app/features/employee_dashboard"
    click F5 "https://github.com/kimjeffsj/syn-backend/tree/main/app/features/employee_management"
    click F6 "https://github.com/kimjeffsj/syn-backend/tree/main/app/features/leave"
    click F7 "https://github.com/kimjeffsj/syn-backend/tree/main/app/features/notifications"
    click F8 "https://github.com/kimjeffsj/syn-backend/tree/main/app/features/schedule"
    click F9 "https://github.com/kimjeffsj/syn-backend/tree/main/app/features/shift_trade"
    click DBM "https://github.com/kimjeffsj/syn-backend/tree/main/app/models"
    click DM "https://github.com/kimjeffsj/syn-backend/tree/main/alembic"
    click E "https://github.com/kimjeffsj/syn-backend/tree/main/app/core/events"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef core fill:#F0E68C,stroke:#000,stroke-width:2px;
    classDef module fill:#FFFFCC,stroke:#000,stroke-width:2px;
    classDef db fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
