# felikarina/bambin architecture

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

- Interactive diagram: https://gitdiagram.com/felikarina/bambin
- Repository: https://github.com/felikarina/bambin
- Video tour (about a minute): https://gitdiagram.com/felikarina/bambin/video

## Overview

##### Project Type and Purpose
- This is a full‐stack web application (“Bambin”) consisting of:
- A Vue.js SPA (frontend) served via Vercel’s CDN.
- A set of serverless API endpoints (the “api” folder) for business logic and data access.
- A relational database layer (PostgreSQL via Supabase and Drizzle ORM) for persistence.
- Supabase Storage for multimedia (photos).
- Purpose: Secure photo gallery, activity journal, messaging and account management for crèche staff and parents.

##### Architectural Overview
- Client Layer (Browser + SPA)
- Components: Vue views/components, router, state & utils (API client, Supabase auth)
- Served as static assets by Vercel.
- API Layer (Serverless Functions)
- Each file in /api (e.g., login.ts, pictures.ts) is a Vercel Serverless Function.
- They import the Drizzle ORM from backend/db to run SQL queries against PostgreSQL.
- Auth middleware (utils/auth.ts) verifies Supabase JWTs.
- Data Layer
- PostgreSQL (hosted by Supabase) for users, children, sections, activities, tags.
- Drizzle schema and migrations live in backend/db and backend/drizzle/meta.
- Supabase Storage buckets handle picture file uploads.
- CI/CD & Infrastructure
- GitHub Workflows trigger Vercel deployment on dev/main branches.
- Docker‐compose used for local integration testing with a test database.
- Vitest & Playwright for unit and end‐to‐end tests.

##### Relationships & Data Flows
- SPA → (HTTPS) → Serverless API
- All CRUD operations for users, children, sections, activities, pictures.
- API → (ORM) → PostgreSQL
- API → (Storage SDK) → Supabase Storage (for file upload/download)
- SPA ↔ (Auth SDK) ↔ Supabase Auth (JWT issuance & validation)
- GitHub Actions → Vercel Deployment → CDN / Serverless Updates

##### Architectural Patterns & Principles
- Single‐Page Application decoupled from Backend via REST‐style serverless endpoints.
- Database access is centralized behind Drizzle ORM for type safety and migrations.
- Serverless micro‐endpoints organized per resource (user, picture, activity).
- Use of managed services (Supabase) to offload infrastructure concerns.
- Clear separation of concerns: frontend, API logic, persistence, and devops.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Browser["Browser (Vue SPA)"]:::frontend
    end

    %% CDN Layer
    CDN["Vercel CDN / Static Hosting"]:::cdn

    %% API Layer
    subgraph "Serverless API (Vercel Functions)"
        Login["/api/login.ts"]:::api
        Users["/api/users.ts"]:::api
        Children["/api/children.ts"]:::api
        ChildSections["/api/child-sections.ts"]:::api
        Sections["/api/sections.ts"]:::api
        SectionActivities["/api/section-activities.ts"]:::api
        Activities["/api/activities.ts"]:::api
        Pictures["/api/pictures.ts"]:::api
        PictureTags["/api/picture-tags.ts"]:::api
    end

    %% Auth Service
    Auth["Supabase Auth (JWT Service)"]:::auth

    %% Data Layer
    DB["PostgreSQL (Supabase)"]:::db
    Storage["Supabase Storage"]:::storage

    %% CI/CD
    subgraph "CI/CD Pipeline"
        GHActions["GitHub Actions"]:::cicd
        VercelDeploy["Vercel Deployment"]:::cicd
    end

    %% Local Dev/Test
    LocalTest["Local Dev/Test (Docker Compose & Test DB)"]:::test

    %% Data Flows
    Browser -->|"Static Assets"| CDN
    Browser -->|"HTTPS Requests"| Login
    Browser -->|"HTTPS Requests"| Users
    Browser -->|"HTTPS Requests"| Children
    Browser -->|"HTTPS Requests"| ChildSections
    Browser -->|"HTTPS Requests"| Sections
    Browser -->|"HTTPS Requests"| SectionActivities
    Browser -->|"HTTPS Requests"| Activities
    Browser -->|"HTTPS Requests"| Pictures
    Browser -->|"HTTPS Requests"| PictureTags
    Browser <-->|"Auth SDK"| Auth

    Login -->|"Uses Auth Middleware"| Auth
    Users -->|"Validate JWT"| Auth
    Children -->|"Validate JWT"| Auth
    ChildSections -->|"Validate JWT"| Auth
    Sections -->|"Validate JWT"| Auth
    SectionActivities -->|"Validate JWT"| Auth
    Activities -->|"Validate JWT"| Auth
    Pictures -->|"Validate JWT"| Auth
    PictureTags -->|"Validate JWT"| Auth

    Login -->|"ORM Queries"| DB
    Users -->|"ORM Queries"| DB
    Children -->|"ORM Queries"| DB
    ChildSections -->|"ORM Queries"| DB
    Sections -->|"ORM Queries"| DB
    SectionActivities -->|"ORM Queries"| DB
    Activities -->|"ORM Queries"| DB

    Pictures -->|"Storage SDK"| Storage
    PictureTags -->|"ORM Queries"| DB

    GHActions -->|"Trigger Deploy"| VercelDeploy
    VercelDeploy -->|"Update CDN & Functions"| CDN
    VercelDeploy -->|"Update CDN & Functions"| Login

    LocalTest -->|"Local PostgreSQL"| DB
    LocalTest -->|"Integration Tests"| Login

    %% Click Events
    click Browser "https://github.com/felikarina/bambin/blob/main/frontend/src/main.ts"
    click CDN "https://github.com/felikarina/bambin/blob/main/vercel.json"
    click Login "https://github.com/felikarina/bambin/blob/main/api/login.ts"
    click Users "https://github.com/felikarina/bambin/blob/main/api/users.ts"
    click Children "https://github.com/felikarina/bambin/blob/main/api/children.ts"
    click ChildSections "https://github.com/felikarina/bambin/blob/main/api/child-sections.ts"
    click Sections "https://github.com/felikarina/bambin/blob/main/api/sections.ts"
    click SectionActivities "https://github.com/felikarina/bambin/blob/main/api/section-activities.ts"
    click Activities "https://github.com/felikarina/bambin/blob/main/api/activities.ts"
    click Pictures "https://github.com/felikarina/bambin/blob/main/api/pictures.ts"
    click PictureTags "https://github.com/felikarina/bambin/blob/main/api/picture-tags.ts"
    click Auth "https://github.com/felikarina/bambin/blob/main/backend/utils/auth.ts"
    click DB "https://github.com/felikarina/bambin/blob/main/backend/db/index.ts"
    click Storage "https://github.com/felikarina/bambin/blob/main/frontend/src/utils/supabase.ts"
    click GHActions "https://github.com/felikarina/bambin/blob/main/.github/workflows/verce-deploy-dev.yml"
    click VercelDeploy "https://github.com/felikarina/bambin/blob/main/.github/workflows/verce-deploy-main.yml"
    click LocalTest "https://github.com/felikarina/bambin/blob/main/docker-compose.test.yml"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#1E3A8A,color:#1E3A8A;
    classDef cdn fill:#E0F2FE,stroke:#0284C7,color:#0284C7;
    classDef api fill:#D1FAE5,stroke:#065F46,color:#065F46;
    classDef auth fill:#FEF3C7,stroke:#92400E,color:#92400E;
    classDef db fill:#FFEDD5,stroke:#C2410C,color:#C2410C;
    classDef storage fill:#F5D0FE,stroke:#6B21A8,color:#6B21A8;
    classDef cicd fill:#F3F4F6,stroke:#4B5563,color:#4B5563;
    classDef test fill:#F9FAFB,stroke:#6B7280,color:#6B7280;
```
