# ayusjayaswal/tangerines architecture

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

- Interactive diagram: https://gitdiagram.com/ayusjayaswal/tangerines
- Repository: https://github.com/ayusjayaswal/tangerines

## Overview

##### Project type and purpose
- This is a three-layer CRUD template (“FakeOverflow’s Fourth Rewrite”) with a Next.js frontend, FastAPI backend, PostgreSQL + Redis database/cache layer, and optional Adminer service.
- Its goal is modularity and reuse: client UI → server API → persistent store (PostgreSQL) + cache (Redis).

##### File structure
- Top-level:
- app/ (server-side)
- client/ (Next.js client)
- docker‐compose.yml, Dockerfiles, init SQL scripts, README, requirements.txt
- app/ contains:
- api/ (FastAPI routers: auth, comments, discussions, search, users)
- core/ (config, DB connection, security)
- crud/ (DB operations)
- models/ (ORM models)
- schemas/ (Pydantic schemas)
- utils/ (cache helper)
- client/ contains:
- pages/ (Next.js pages)
- components/, hooks/, utils/, styles/
- lib/api.js abstracts HTTP calls to FastAPI
- Deployment files orchestrate Docker containers for four services: client, server, PostgreSQL, Redis (plus Adminer).

##### Main components and their interactions
a. Frontend (Next.js)
- Runs in a Node.js container
- Components call REST endpoints via lib/api.js to the FastAPI server
b. Backend (FastAPI)
- Exposes /api/v1/* routers
- Uses core/config for env vars, core/database to talk to PostgreSQL, utils/cache for Redis caching
- CRUD modules implement business logic and DB operations
c. Database layer
- PostgreSQL container persists data (discussions, comments, users)
- Redis container caches frequent queries/responses
d. Adminer
- Database management interface connected to PostgreSQL
e. External clients
- Browser or mobile app → Next.js → FastAPI → Postgres/Redis

##### Architectural patterns and design principles
- Three-layer architecture (Client / Server / Data)
- Asynchronous I/O in FastAPI for high throughput
- Separation of concerns: routers → services/crud → models/schemas
- Docker-based isolation and orchestration (docker-compose)
- Pydantic for type-safe schemas

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        Next["Next.js App<br/>(3000)"]:::service
    end

    %% Server Layer
    subgraph "Server Layer"
        FastAPI["FastAPI Server<br/>(8000)"]:::service
        subgraph "Routers (app/api/v1)"
            Routers["API v1 Routers"]:::component
        end
        subgraph "Core"
            Config["Core Config"]:::component
        end
        subgraph "CRUD"
            CRUD["CRUD Operations"]:::component
        end
        subgraph "Models"
            Models["ORM Models"]:::component
        end
        subgraph "Schemas"
            Schemas["Pydantic Schemas"]:::component
        end
        subgraph "Utils (Cache)"
            Cache["Redis Cache Helper"]:::component
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        PostgreSQL[(PostgreSQL<br/>5432)]:::db
        Redis[(Redis<br/>6379)]:::db
        Adminer((Adminer<br/>8080)):::admin
    end

    %% Connections
    Next -->|"REST API calls (/api/v1/*)"| FastAPI
    FastAPI -->|"SQL"| PostgreSQL
    FastAPI -->|"GET/SET"| Redis
    Adminer -->|"DB Admin"| PostgreSQL

    %% Click Events
    click Next "https://github.com/ayusjayaswal/tangerines/tree/main/client/"
    click FastAPI "https://github.com/ayusjayaswal/tangerines/blob/main/app/main.py"
    click Routers "https://github.com/ayusjayaswal/tangerines/tree/main/app/api/v1/"
    click Config "https://github.com/ayusjayaswal/tangerines/blob/main/app/core/config.py"
    click CRUD "https://github.com/ayusjayaswal/tangerines/tree/main/app/crud/"
    click Models "https://github.com/ayusjayaswal/tangerines/tree/main/app/models/"
    click Schemas "https://github.com/ayusjayaswal/tangerines/tree/main/app/schemas/"
    click Cache "https://github.com/ayusjayaswal/tangerines/blob/main/app/utils/cache.py"

    %% Styles
    classDef service fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef component fill:#E8F4FF,stroke:#0366d6,color:#0366d6;
    classDef db fill:#DFFFE0,stroke:#22863a,color:#22863a;
    classDef admin fill:#FFF0D0,stroke:#d29922,color:#d29922;
```
