PHPackages                             marcuwynu23/narciso - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. marcuwynu23/narciso

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

marcuwynu23/narciso
===================

'Narciso' is a web library built on top of native PHP, designed to provide developers with a set of tools and functionalities to simplify and enhance web development tasks. It aims to streamline common web development processes such as handling HTTP requests, managing sessions, accessing databases, and generating dynamic content.

v1.0.2(1mo ago)113Apache-2.0PHPCI passing

Since Mar 5Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/marcuwynu23/narciso)[ Packagist](https://packagist.org/packages/marcuwynu23/narciso)[ RSS](/packages/marcuwynu23-narciso/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependencies (3)Versions (8)Used By (0)

[![](./docs/logo.svg)](./docs/logo.svg)[![Packagist](https://camo.githubusercontent.com/cc0c332b732936c27dade311a29acbc66a1472b67bfbe1b76ea2506e7d679e69/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6172637577796e7532332f6e61726369736f)](https://packagist.org/packages/marcuwynu23/narciso)[![License](https://camo.githubusercontent.com/92e9b49cd5c1be3a4355c0bcfb62d4a87e6e0a605e6c9d2ceae5170143b33f7a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6172637577796e7532332f6e61726369736f)](LICENSE)[![CI](https://github.com/marcuwynu23/narciso/actions/workflows/ci.yml/badge.svg)](https://github.com/marcuwynu23/narciso/actions/workflows/ci.yml)[![Stars](https://camo.githubusercontent.com/f49cbf8d45cc51f760cbc129be4642133d969dd2232155a1627075f9459f8727/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6d6172637577796e7532332f6e61726369736f)](https://github.com/marcuwynu23/narciso/stargazers)[![PHP version](https://camo.githubusercontent.com/5c460db2e6cfcfd75ae5a6aaa5a98a7ac37c3e5c1a71254f6b8d919d77a70b74/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d76657273696f6e2f6d6172637577796e7532332f6e61726369736f)](https://camo.githubusercontent.com/5c460db2e6cfcfd75ae5a6aaa5a98a7ac37c3e5c1a71254f6b8d919d77a70b74/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d76657273696f6e2f6d6172637577796e7532332f6e61726369736f)

**Lightweight PHP web library.** Routing, middleware, CORS, rate limiting, security headers, and database — no framework required.

➡️ **[Read the full user guide →](USER-GUIDE.md)**

---

Table of Contents
-----------------

[](#table-of-contents)

- [What Is Narciso?](#what-is-narciso)
- [Use Cases](#use-cases)
- [Benefits](#benefits-for-developers)
- [Advantages Over Other Tools](#advantages-over-other-tools)
- [User Guide](USER-GUIDE.md)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [API Reference](#api-reference)
- [Configuration](#configuration)
- [Example Output](#example-output)
- [CI/CD Integration](#cicd-integration)
- [Development](#development)
- [Architecture](#architecture)
- [Contributing](CONTRIBUTING.md)
- [License](#license)

---

What Is Narciso?
----------------

[](#what-is-narciso)

**Narciso** is a lightweight PHP web library built on top of native PHP, inspired by **FastAPI** and **Flask**. It gives you a simple, expressive API for routing, middlewares, CORS, rate limiting, security headers, and database access — so you can build APIs and web apps quickly without a heavy framework.

### What It Does

[](#what-it-does)

- **Route** — Map HTTP methods and URL patterns (including path parameters like `/users/:id`) to handler callbacks
- **Protect** — Add security headers, CORS, and rate limiting with one-line method calls
- **Connect** — Configure MySQL or SQLite in a single config array; `$app->db` is ready in every route
- **Respond** — Return JSON, XML (auto-detected from query/header), or render PHP views
- **Obfuscate** — Hide or fake the `X-Powered-By` header to keep the server technology private
- **Extend** — Add custom middleware via a callable or the `MiddlewareInterface`
- **Session** — Start PHP sessions with `handleSession()`

### Why Use It?

[](#why-use-it)

ProblemHow Narciso Solves ItHeavy frameworks require boilerplateNarciso is ~500 lines of PHP; drop it in and start codingCORS and security headers are tediousOne call: `$app->useCors([...])`, `$app->useSecurityHeaders()`Rate limiting needs middleware setup`$app->useRateLimit(100, 60)` — 1 line, in-memory, per-IPDatabase config varies between MySQL/SQLiteSingle `handleDatabase([...])` with `type: mysql` or `type: sqlite`API format negotiation is boilerplate`$app->sendAPI($data)` auto-detects JSON vs XML from `Accept` header or `?format=`Server signature leaks tech stack`$app->setPoweredBy(false)` removes `X-Powered-By` entirely### The Philosophy

[](#the-philosophy)

1. **Minimal setup, maximum value.** A working API server in 10 lines of code.
2. **Your process stays yours.** No forced directory structure, no service container, no DI. Just PHP.
3. **Native-first.** Built on `mysqli`, `SQLite3`, and native PHP sessions — no runtime dependencies.

---

Use Cases
---------

[](#use-cases)

ScenarioHow Narciso Helps**JSON API backend**Define routes with `$app->route()`, return JSON with `$app->json()` or `$app->sendAPI()`. CORS and rate limiting built in.**Rapid prototype**Install via Composer, write a single PHP file, run with `php -S`. Zero config.**Microservice**Lightweight enough to deploy as a standalone service. Add security headers and rate limiting in two lines.**Simple web app with database**Connect MySQL or SQLite with `handleDatabase()`, render views with `render()`.**API gateway / proxy**Use the middleware pipeline to add logging, auth, and rate limiting before proxying requests.**Learning tool**Read the ~500-line source to understand how routing, middleware, and request handling work in PHP.---

Benefits for Developers
-----------------------

[](#benefits-for-developers)

- **~10 second setup** — `composer require marcuwynu23/narciso`
- **No runtime dependencies** — Zero Composer dependencies at runtime
- **Familiar API** — Inspired by Flask and FastAPI; route handlers receive `($app, $params)`
- **Path parameters** — `/users/:id` syntax like Express.js
- **Middleware onion** — Add as many middlewares as needed; they wrap in order
- **JSON/XML auto-detection** — `sendAPI()` reads `Accept` header or `?format=` query param
- **Built-in security** — Security headers, CORS, rate limiting ship with the library
- **Technology obfuscation** — Remove or fake `X-Powered-By` with `setPoweredBy()`
- **PHP 7.4+ compatible** — Works on legacy and modern PHP
- **Fully tested** — PHPUnit suite with 36+ tests covering routing, middleware, database, and API

---

Advantages Over Other Tools
---------------------------

[](#advantages-over-other-tools)

AspectNarcisoLaravelSlimSymfonyHandwritten**Setup time**~10 secondsMinutes~30 secondsMinutesOngoing effort**Runtime dependencies**050+580+0**Learning curve**LowHighMediumHighN/A**File size (source)**~500 lines10,000s~2,000100,000sVaries**Database abstraction**mysqli / SQLite3EloquentPDODoctrineCustom**CORS middleware**Built-inPackagePackageBundleCustom**Rate limiting**Built-inPackagePackageBundleCustom**Security headers**Built-inMiddlewarePackageBundleCustom**JSON/XML auto-detect**Built-inManualManualManualCustom**Path parameters**`:param`Route params`{param}``{param}`Custom**Middleware interface**YesYesYesYesCustom**Template engine**PHP includesBladeTwig/PlatesTwigCustom**CLI tooling**NoArtisanNoMakerN/A**ORM**NoEloquentOptionalDoctrineCustom**License**Apache 2.0MITMITMITYour choice---

Installation
------------

[](#installation)

```
composer require marcuwynu23/narciso
```

Requires PHP 7.4+ and the `json` extension. For MySQL use, install `php-mysql`. For SQLite, install `php-sqlite3`.

**Verify:**

```
php -r "require 'vendor/autoload.php'; echo class_exists(Marcuwynu23\\\Narciso\\\Application::class) ? 'OK' : 'FAIL';"
```

---

Quick Start
-----------

[](#quick-start)

Create `index.php`:

```
