# manuelnavarro7/country-app architecture

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

- Interactive diagram: https://gitdiagram.com/manuelnavarro7/country-app
- Repository: https://github.com/manuelnavarro7/country-app

## Overview

##### Project Type and Purpose
- This is a full-stack web application (“Country Info App”) whose goal is to display country data (population trends, border countries, flags) to end users.
- Frontend: Next.js (React) single-page app with server- and client-components (app directory) and Tailwind CSS for styling.
- Backend: Express.js REST API server responsible for fetching data from two public external services (Nager.Date API, CountriesNow API) and exposing it to the frontend.

##### File-Structure Analysis
Top-level:
- backend/
– app.js (Express server setup, CORS configuration)
– src/controllers (countryController.js handles API logic)
– src/routes (countryRoutes.js defines endpoints)
– .env for PORT
– package.json/npm scripts
- frontend/
– src/app/… (Next.js app folder using new app router)
· country-list/[code]/page.js, layout.js (dynamic route for country detail)
· page.js (home listing)
· globals.css, Tailwind config, postcss.config.mjs
– next.config.mjs, jsconfig.json, .eslintrc.json
– package.json/npm scripts

##### README Insights
- Backend exposes two GET endpoints: /api/countries/available and /api/countries/info/:countryCode
- Frontend uses NEXT_PUBLIC_BACKEND_URL to call backend on port 5001 from port 3000
- Chart.js is used for rendering historical population data
- No internal database; all country data comes from external REST APIs
- CORS is enabled in Express for localhost:3000

a. Main Components
- Browser/Client (User’s web browser)
- Next.js Frontend (app server + client runtime)
- Express.js Backend (REST API server)
- External APIs – Nager.Date API, CountriesNow API

b. Relationships/Interactions
1. User requests frontend (port 3000) → Next.js server
2. Frontend calls Express backend via REST (NEXT_PUBLIC_BACKEND_URL/api/…)
3. Express controllers route request → fetch data from external APIs
4. External APIs return JSON → Express aggregates and returns to frontend
5. Frontend renders data (country list, detail page, Chart.js chart)

c. Architectural Patterns
- Separation of concerns: distinct frontend and backend tiers
- MVC-style on backend (routes → controllers)
- Next.js app router with server vs. client components
- Environment-based configuration (PORT, NEXT_PUBLIC_BACKEND_URL)
- CORS for cross-origin communication

d. Key Technologies/Libraries
- Frontend: Next.js 13 (app router), React, Tailwind CSS, Chart.js
- Backend: Node.js, Express.js, cors, dotenv
- External dependencies: Nager.Date API, CountriesNow API

## Diagram (Mermaid)

```mermaid
graph TD
    %% UI Layer
    subgraph "UI Layer"
        Browser["Browser"]:::ui
    end

    %% Frontend Layer
    subgraph "Next.js Frontend (port 3000)"
        direction TB
        Layout["layout.js"]:::frontend
        GlobalCSS["globals.css"]:::frontend
        HomePage["page.js (Country List)"]:::frontend
        DynamicLayout["[code]/layout.js"]:::frontend
        DynamicPage["[code]/page.js (Chart.js)"]:::frontend

        subgraph "Config Files"
            direction TB
            NextConfig["next.config.mjs"]:::frontend
            TailwindConfig["tailwind.config.js"]:::frontend
            PostCSSConfig["postcss.config.mjs"]:::frontend
            JSConfig["jsconfig.json"]:::frontend
            ESLint[".eslintrc.json"]:::frontend
            FEPackage["package.json"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Express API (port 5001)"
        direction TB
        AppJS["app.js"]:::backend
        Env[".env"]:::backend
        Routes["countryRoutes.js"]:::backend
        Controller["countryController.js"]:::backend
        BEPackage["package.json"]:::backend
    end

    %% External Services
    subgraph "External Services"
        direction TB
        NagerDate["Nager.Date API"]:::external
        CountriesNow["CountriesNow API"]:::external
    end

    %% Connections
    Browser -->|"HTTP GET /"| Layout
    Browser --> Layout
    Layout --> HomePage
    HomePage -->|"Client Render"| DynamicLayout
    DynamicLayout --> DynamicPage

    Layout -->|"NEXT_PUBLIC_BACKEND_URL/api/countries/available"| AppJS
    DynamicPage -->|"NEXT_PUBLIC_BACKEND_URL/api/countries/info/:countryCode"| AppJS

    AppJS --> Routes
    Routes --> Controller

    AppJS -->|"GET /available"| NagerDate
    AppJS -->|"GET /info/:countryCode"| CountriesNow

    NagerDate -->|"JSON Data"| Controller
    CountriesNow -->|"JSON Data"| Controller
    Controller -->|"Aggregated JSON"| AppJS
    AppJS -->|"Response JSON"| DynamicPage

    %% Click Events
    click AppJS "https://github.com/manuelnavarro7/country-app/blob/main/backend/app.js"
    click Env "https://github.com/manuelnavarro7/country-app/blob/main/backend/.env"
    click Controller "https://github.com/manuelnavarro7/country-app/blob/main/backend/src/controllers/countryController.js"
    click Routes "https://github.com/manuelnavarro7/country-app/blob/main/backend/src/routes/countryRoutes.js"
    click BEPackage "https://github.com/manuelnavarro7/country-app/blob/main/backend/package.json"
    click Layout "https://github.com/manuelnavarro7/country-app/blob/main/frontend/src/app/layout.js"
    click GlobalCSS "https://github.com/manuelnavarro7/country-app/blob/main/frontend/src/app/globals.css"
    click HomePage "https://github.com/manuelnavarro7/country-app/blob/main/frontend/src/app/page.js"
    click DynamicLayout "https://github.com/manuelnavarro7/country-app/blob/main/frontend/src/app/country-list/[code]/layout.js"
    click DynamicPage "https://github.com/manuelnavarro7/country-app/blob/main/frontend/src/app/country-list/[code]/page.js"
    click NextConfig "https://github.com/manuelnavarro7/country-app/blob/main/frontend/next.config.mjs"
    click TailwindConfig "https://github.com/manuelnavarro7/country-app/blob/main/frontend/tailwind.config.js"
    click PostCSSConfig "https://github.com/manuelnavarro7/country-app/blob/main/frontend/postcss.config.mjs"
    click JSConfig "https://github.com/manuelnavarro7/country-app/blob/main/frontend/jsconfig.json"
    click ESLint "https://github.com/manuelnavarro7/country-app/blob/main/frontend/.eslintrc.json"
    click FEPackage "https://github.com/manuelnavarro7/country-app/blob/main/frontend/package.json"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef frontend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef backend fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
```
